Skip to content

Commit d11140f

Browse files
authored
neovim: add 'autoconfigure' setting (#356271)
certain plugins need a custom configuration (available in passthru.initLua) to work with nix. For instance unicode-vim needs to configure where to find the data: ``` vim.g.Unicode_data_directory="${self.unicode-vim}/autoload/unicode" ``` if true, the wrapper automatically appends those snippets when necessary first appearance of initLua in #352741 This will make testing those plugins easier.
1 parent b675ca7 commit d11140f

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

pkgs/applications/editors/neovim/tests/default.nix

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ let
8080
sha256 = "1ykcvyx82nhdq167kbnpgwkgjib8ii7c92y3427v986n2s5lsskc";
8181
};
8282

83-
# neovim-drv must be a wrapped neovim
83+
/* neovim-drv must be a wrapped neovim
84+
- exposes lua config in $luarcGeneric
85+
- exposes vim config in $vimrcGeneric
86+
87+
*/
88+
8489
runTest = neovim-drv: buildCommand:
8590
runCommandLocal "test-${neovim-drv.name}" ({
8691
nativeBuildInputs = [ ];
@@ -164,6 +169,13 @@ in
164169
${nvim_with_plug}/bin/nvim -V3log.txt -i NONE -c 'color base16-tomorrow-night' +quit! -e
165170
'';
166171

172+
nvim_with_autoconfigure = pkgs.neovim.overrideAttrs(oa: {
173+
plugins = [ vimPlugins.unicode-vim ];
174+
autoconfigure = true;
175+
# legacy wrapper sets it to false
176+
wrapRc = true;
177+
});
178+
167179
nvim_with_ftplugin = let
168180
# this plugin checks that it's ftplugin/vim.tex is loaded before $VIMRUNTIME/ftplugin/vim.tex
169181
# $VIMRUNTIME/ftplugin/vim.tex sources $VIMRUNTIME/ftplugin/initex.vim which sets b:did_ftplugin
@@ -324,6 +336,12 @@ in
324336

325337
inherit nvim-with-luasnip;
326338

339+
autoconfigure = runTest nvim_with_autoconfigure ''
340+
assertFileContains \
341+
"$luarc" \
342+
'${vimPlugins.unicode-vim.passthru.initLua}'
343+
'';
344+
327345
# check that bringing in one plugin with lua deps makes those deps visible from wrapper
328346
# for instance luasnip has a dependency on jsregexp
329347
can_require_transitive_deps =

pkgs/applications/editors/neovim/wrapper.nix

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ let
2020

2121
wrapper = {
2222
extraName ? ""
23+
# certain plugins need a custom configuration (available in passthru.initLua)
24+
# to work with nix.
25+
# if true, the wrapper automatically appends those snippets when necessary
26+
, autoconfigure ? false
2327
# should contain all args but the binary. Can be either a string or list
2428
, wrapperArgs ? []
2529
, withPython2 ? false
@@ -87,11 +91,19 @@ let
8791
packpathDirs.myNeovimPackages = myVimPackage;
8892
finalPackdir = neovimUtils.packDir packpathDirs;
8993

94+
luaPluginRC = let
95+
op = acc: normalizedPlugin:
96+
acc ++ lib.optional (finalAttrs.autoconfigure && normalizedPlugin.plugin.passthru ? initLua) normalizedPlugin.plugin.passthru.initLua;
97+
in
98+
lib.foldl' op [] pluginsNormalized;
99+
90100
rcContent = ''
91101
${luaRcContent}
92102
'' + lib.optionalString (neovimRcContent' != null) ''
93103
vim.cmd.source "${writeText "init.vim" neovimRcContent'}"
94-
'';
104+
'' +
105+
lib.concatStringsSep "\n" luaPluginRC
106+
;
95107

96108
getDeps = attrname: map (plugin: plugin.${attrname} or (_: [ ]));
97109

@@ -155,7 +167,7 @@ let
155167
__structuredAttrs = true;
156168
dontUnpack = true;
157169
inherit viAlias vimAlias withNodeJs withPython3 withPerl withRuby;
158-
inherit wrapRc providerLuaRc packpathDirs;
170+
inherit autoconfigure wrapRc providerLuaRc packpathDirs;
159171
inherit python3Env rubyEnv;
160172
inherit wrapperArgs generatedWrapperArgs;
161173
luaRcContent = rcContent;

0 commit comments

Comments
 (0)