From d11140fa35add4fc798643e9cd44b08bcbe23321 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron <886074+teto@users.noreply.github.com> Date: Sun, 24 Nov 2024 16:29:58 +0100 Subject: [PATCH] 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 https://github.com/NixOS/nixpkgs/issues/352741 This will make testing those plugins easier. --- .../editors/neovim/tests/default.nix | 20 ++++++++++++++++++- pkgs/applications/editors/neovim/wrapper.nix | 16 +++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/pkgs/applications/editors/neovim/tests/default.nix b/pkgs/applications/editors/neovim/tests/default.nix index 1c468282d106..fb89d47aceb0 100644 --- a/pkgs/applications/editors/neovim/tests/default.nix +++ b/pkgs/applications/editors/neovim/tests/default.nix @@ -80,7 +80,12 @@ let sha256 = "1ykcvyx82nhdq167kbnpgwkgjib8ii7c92y3427v986n2s5lsskc"; }; - # neovim-drv must be a wrapped neovim + /* neovim-drv must be a wrapped neovim + - exposes lua config in $luarcGeneric + - exposes vim config in $vimrcGeneric + + */ + runTest = neovim-drv: buildCommand: runCommandLocal "test-${neovim-drv.name}" ({ nativeBuildInputs = [ ]; @@ -164,6 +169,13 @@ in ${nvim_with_plug}/bin/nvim -V3log.txt -i NONE -c 'color base16-tomorrow-night' +quit! -e ''; + nvim_with_autoconfigure = pkgs.neovim.overrideAttrs(oa: { + plugins = [ vimPlugins.unicode-vim ]; + autoconfigure = 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 @@ -324,6 +336,12 @@ in inherit nvim-with-luasnip; + autoconfigure = runTest nvim_with_autoconfigure '' + assertFileContains \ + "$luarc" \ + '${vimPlugins.unicode-vim.passthru.initLua}' + ''; + # 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 = diff --git a/pkgs/applications/editors/neovim/wrapper.nix b/pkgs/applications/editors/neovim/wrapper.nix index 01e49149c6e3..d7b3c322b562 100644 --- a/pkgs/applications/editors/neovim/wrapper.nix +++ b/pkgs/applications/editors/neovim/wrapper.nix @@ -20,6 +20,10 @@ let wrapper = { extraName ? "" + # certain plugins need a custom configuration (available in passthru.initLua) + # to work with nix. + # if true, the wrapper automatically appends those snippets when necessary + , autoconfigure ? false # should contain all args but the binary. Can be either a string or list , wrapperArgs ? [] , withPython2 ? false @@ -87,11 +91,19 @@ let packpathDirs.myNeovimPackages = myVimPackage; finalPackdir = neovimUtils.packDir packpathDirs; + luaPluginRC = let + op = acc: normalizedPlugin: + acc ++ lib.optional (finalAttrs.autoconfigure && normalizedPlugin.plugin.passthru ? initLua) normalizedPlugin.plugin.passthru.initLua; + in + lib.foldl' op [] pluginsNormalized; + rcContent = '' ${luaRcContent} '' + lib.optionalString (neovimRcContent' != null) '' vim.cmd.source "${writeText "init.vim" neovimRcContent'}" - ''; + '' + + lib.concatStringsSep "\n" luaPluginRC + ; getDeps = attrname: map (plugin: plugin.${attrname} or (_: [ ])); @@ -155,7 +167,7 @@ let __structuredAttrs = true; dontUnpack = true; inherit viAlias vimAlias withNodeJs withPython3 withPerl withRuby; - inherit wrapRc providerLuaRc packpathDirs; + inherit autoconfigure wrapRc providerLuaRc packpathDirs; inherit python3Env rubyEnv; inherit wrapperArgs generatedWrapperArgs; luaRcContent = rcContent;