diff --git a/pkgs/applications/editors/neovim/plugin-submodule.nix b/pkgs/applications/editors/neovim/plugin-submodule.nix index 5a9ca56afb56..dce427c49798 100644 --- a/pkgs/applications/editors/neovim/plugin-submodule.nix +++ b/pkgs/applications/editors/neovim/plugin-submodule.nix @@ -11,6 +11,7 @@ let plugin = null; config = null; optional = false; + type = "viml"; }; in map (x: defaultPlugin // (if x ? plugin then x else { plugin = x; })) plugins; @@ -26,6 +27,15 @@ let example = "set title"; }; + type = lib.mkOption { + type = lib.types.either (lib.types.enum [ + "lua" + "viml" + ]) lib.types.str; + description = "Language used in config. Configurations are aggregated per-language."; + default = "viml"; + }; + optional = mkEnableOption "optional" // { description = "Don't load automatically on startup (load with :packadd)"; }; @@ -78,12 +88,20 @@ in userPluginViml = lib.mkOption { readOnly = true; - type = lib.types.listOf lib.types.lines; + type = lib.types.nullOr lib.types.lines; description = '' The viml config set by the user. ''; }; + userPluginConfigs = lib.mkOption { + readOnly = true; + type = lib.types.attrsOf lib.types.lines; + description = '' + The user configurations (viml, lua, ...) set by the user. + ''; + }; + pluginPython3Packages = lib.mkOption { readOnly = true; type = lib.types.listOf (lib.types.functionTo (lib.types.listOf lib.types.package)); @@ -106,6 +124,13 @@ in config = let pluginsNormalized = config.plugins; + + userPluginConfigs = + let + grouped = lib.groupBy (x: x.type) pluginsNormalized; + configsOnly = lib.foldl (acc: p: if p.config != null then acc ++ [ p.config ] else acc) [ ]; + in + lib.mapAttrs (_name: vals: lib.concatStringsSep "\n" (configsOnly vals)) grouped; in { pluginAdvisedLua = @@ -125,9 +150,9 @@ in in lib.foldl' op [ ] pluginsNormalized; - userPluginViml = lib.foldl ( - acc: p: if p.config != null then acc ++ [ p.config ] else acc - ) [ ] pluginsNormalized; + userPluginViml = userPluginConfigs.viml or null; + + inherit userPluginConfigs; pluginPython3Packages = map (plugin: plugin.python3Dependencies or (_: [ ])) pluginsNormalized; diff --git a/pkgs/applications/editors/neovim/tests/default.nix b/pkgs/applications/editors/neovim/tests/default.nix index 0e5bdf7a5d07..5945a5826359 100644 --- a/pkgs/applications/editors/neovim/tests/default.nix +++ b/pkgs/applications/editors/neovim/tests/default.nix @@ -12,7 +12,6 @@ writeText, neovim, vimPlugins, - neovimUtils, wrapNeovimUnstable, neovim-unwrapped, fetchFromGitLab, @@ -21,8 +20,6 @@ pkgs, }: let - inherit (neovimUtils) makeNeovimConfig; - plugins = with vimPlugins; [ { plugin = vim-obsession; @@ -30,6 +27,14 @@ let map $ Obsession ''; } + { + plugin = vim-obsession; + type = "lua"; + config = '' + -- this is a comment + vim.g.nixpkgs_test_value = 42 + ''; + } ]; packagesWithSingleLineConfigs = with vimPlugins; [ @@ -43,20 +48,6 @@ let } ]; - nvimConfSingleLines = { - plugins = packagesWithSingleLineConfigs; - neovimRcContent = '' - " just a comment - ''; - }; - - nvimConfNix = { - inherit plugins; - neovimRcContent = '' - " just a comment - ''; - }; - nvim-with-luasnip = wrapNeovim2 "-with-luasnip" { plugins = [ { @@ -105,6 +96,7 @@ let } ( '' + export PATH="${neovim-drv}/bin:$PATH" source ${nmt}/bash-lib/assertions.sh vimrc="${writeText "test-${neovim-drv.name}-init.vim" neovim-drv.initRc}" luarc="${writeText "test-${neovim-drv.name}-init.lua" neovim-drv.luaRcContent}" @@ -139,8 +131,19 @@ pkgs.lib.recurseIntoAttrs rec { ### neovim tests ################## - nvim_with_plugins = wrapNeovim2 "-with-plugins" nvimConfNix; - nvim_singlelines = wrapNeovim2 "-single-lines" nvimConfSingleLines; + nvim_with_plugins = wrapNeovim2 "-with-plugins" { + inherit plugins; + neovimRcContent = '' + " just a comment + ''; + }; + + nvim_singlelines = wrapNeovim2 "-single-lines" { + plugins = packagesWithSingleLineConfigs; + neovimRcContent = '' + " just a comment + ''; + }; # test that passthru.initRc hasn't changed passthruInitRc = runTest nvim_singlelines '' @@ -413,12 +416,19 @@ pkgs.lib.recurseIntoAttrs rec { # 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 '' - ${nvim-with-luasnip}/bin/nvim -i NONE -c "lua require'jsregexp'" -e +quitall! + nvim --headless -i NONE -c "lua require'jsregexp'" -e +quitall! ''; inherit nvim_with_rocks_nvim; rocks_install_plenary = runTest nvim_with_rocks_nvim '' - ${nvim_with_rocks_nvim}/bin/nvim -V3log.txt -i NONE +'Rocks install plenary.nvim' +quit! -e + nvim -V3rocks-log.txt -i NONE +'Rocks install plenary.nvim' +quit! -e + ''; + + can_load_lua_config = runTest nvim_with_plugins '' + if ! nvim --headless -V3lua-config-log.txt -i NONE -c 'lua if vim.g.nixpkgs_test_value ~= 42 then os.exit(42) end' +quit! -e; then + echo "Failed to find plugin config" + exit 1 + fi ''; inherit (vimPlugins) corePlugins; diff --git a/pkgs/applications/editors/neovim/utils.nix b/pkgs/applications/editors/neovim/utils.nix index af180c869a73..ae3ff9dc1800 100644 --- a/pkgs/applications/editors/neovim/utils.nix +++ b/pkgs/applications/editors/neovim/utils.nix @@ -6,12 +6,8 @@ config, vimUtils, vimPlugins, - nodejs, neovim-unwrapped, - bundlerEnv, - ruby, lua, - python3Packages, wrapNeovimUnstable, }: let @@ -109,11 +105,12 @@ let # viml config set by the user along with the plugin inherit (checked_cfg) - userPluginViml + userPluginViml # redefine via userPluginConfigs runtimeDeps pluginAdvisedLua pluginPython3Packages luaDependencies + userPluginConfigs ; # A Vim "package", see ':h packages' diff --git a/pkgs/applications/editors/neovim/wrapper.nix b/pkgs/applications/editors/neovim/wrapper.nix index 723f608c3f40..f048fac3ac2b 100644 --- a/pkgs/applications/editors/neovim/wrapper.nix +++ b/pkgs/applications/editors/neovim/wrapper.nix @@ -14,7 +14,6 @@ neovimUtils, perl, lndir, - vimUtils, runCommand, }: @@ -100,7 +99,10 @@ let # we call vimrcContent without 'packages' to avoid the init.vim generation neovimRcContent' = lib.concatStringsSep "\n" ( - vimPackageInfo.userPluginViml ++ lib.optional (neovimRcContent != null) neovimRcContent + lib.optional (vimPackageInfo.userPluginConfigs.viml or "" != "") ( + vimPackageInfo.userPluginConfigs.viml + ) + ++ (lib.optional (neovimRcContent != null) neovimRcContent) ); packpathDirs.myNeovimPackages = vimPackageInfo.vimPackage; @@ -126,6 +128,9 @@ let lib.optional (luaDeps != [ ]) luaPathLuaRc ++ [ providerLuaRc ] ++ lib.optional (luaRcContent != "") luaRcContent + ++ lib.optional ( + vimPackageInfo.userPluginConfigs.lua or "" != "" + ) vimPackageInfo.userPluginConfigs.lua ++ lib.optional (neovimRcContent' != "") '' vim.cmd.source "${writeText "init.vim" neovimRcContent'}" ''