neovim: add 'autowrapRuntimeDeps' to append (#358587)

plugin runtime dependencies. A recurrent question is how to make LSP
work on nix, with users wanting to install masons etc. I think it makes
sense for neovim to install neovim plugins in a way that they work out
of the box. That's one of the strengths of nix and a shortcoming of the
neovim infrastructure.
We suffix the PATH instead of prepend such that project versions of the
software takes precedence.
It's opt-in for now to but worth revisiting later for the previous
reasons.
This commit is contained in:
Matthieu Coudron 2024-12-17 00:23:05 +01:00 committed by GitHub
parent d18fae80ef
commit c16f43f97c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 36 additions and 8 deletions

View file

@ -170,12 +170,24 @@ in
'';
nvim_with_autoconfigure = pkgs.neovim.overrideAttrs(oa: {
plugins = [ vimPlugins.unicode-vim ];
plugins = [
vimPlugins.unicode-vim
vimPlugins.fzf-hoogle-vim
];
autoconfigure = true;
# legacy wrapper sets it to false
wrapRc = true;
});
nvim_with_runtimeDeps = pkgs.neovim.overrideAttrs({
plugins = [
pkgs.vimPlugins.hex-nvim
];
autowrapRuntimeDeps = true;
# legacy wrapper sets it to false
wrapRc = true;
});
nvim_with_ftplugin = let
# this plugin checks that it's ftplugin/vim.tex is loaded before $VIMRUNTIME/ftplugin/vim.tex
# $VIMRUNTIME/ftplugin/vim.tex sources $VIMRUNTIME/ftplugin/initex.vim which sets b:did_ftplugin
@ -334,7 +346,6 @@ in
${nvim_with_opt_plugin}/bin/nvim -i NONE +quit! -e
'';
inherit nvim-with-luasnip;
autoconfigure = runTest nvim_with_autoconfigure ''
assertFileContains \
@ -342,11 +353,18 @@ in
'${vimPlugins.unicode-vim.passthru.initLua}'
'';
autowrap_runtime_deps = runTest nvim_with_runtimeDeps ''
assertFileContains \
"${nvim_with_runtimeDeps}/bin/nvim" \
'${pkgs.xxd}/bin'
'';
inherit nvim-with-luasnip;
# check that bringing in one plugin with lua deps makes those deps visible from wrapper
# for instance luasnip has a dependency on jsregexp
can_require_transitive_deps =
runTest nvim-with-luasnip ''
cat ${nvim-with-luasnip}/bin/nvim
cat ${nvim-with-luasnip}/nvim
${nvim-with-luasnip}/bin/nvim -i NONE --cmd "lua require'jsregexp'" -e +quitall!
'';

View file

@ -24,6 +24,10 @@ let
# to work with nix.
# if true, the wrapper automatically appends those snippets when necessary
, autoconfigure ? false
# append to PATH runtime deps of plugins
, autowrapRuntimeDeps ? false
# should contain all args but the binary. Can be either a string or list
, wrapperArgs ? []
, withPython2 ? false
@ -120,7 +124,15 @@ let
wrapperArgsStr = if lib.isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs;
generatedWrapperArgs = let
binPath = lib.makeBinPath (lib.optional finalAttrs.withRuby rubyEnv ++ lib.optional finalAttrs.withNodeJs nodejs);
op = acc: normalizedPlugin: acc ++ normalizedPlugin.plugin.runtimeDeps or [];
runtimeDeps = lib.foldl' op [] pluginsNormalized;
binPath = lib.makeBinPath (
lib.optional finalAttrs.withRuby rubyEnv
++ lib.optional finalAttrs.withNodeJs nodejs
++ lib.optionals finalAttrs.autowrapRuntimeDeps runtimeDeps
);
in
# vim accepts a limited number of commands so we join them all
@ -167,7 +179,7 @@ let
__structuredAttrs = true;
dontUnpack = true;
inherit viAlias vimAlias withNodeJs withPython3 withPerl withRuby;
inherit autoconfigure wrapRc providerLuaRc packpathDirs;
inherit autoconfigure autowrapRuntimeDeps wrapRc providerLuaRc packpathDirs;
inherit python3Env rubyEnv;
inherit wrapperArgs generatedWrapperArgs;
luaRcContent = rcContent;

View file

@ -1285,9 +1285,7 @@ in
};
hex-nvim = super.hex-nvim.overrideAttrs {
postPatch = ''
substituteInPlace lua/hex.lua --replace xxd ${xxd}/bin/xxd
'';
runtimeDeps = [ xxd ];
nvimRequireCheck = "hex";
};