diff --git a/pkgs/applications/editors/neovim/tests/default.nix b/pkgs/applications/editors/neovim/tests/default.nix index 29749c35db1fa..84d4433bc68a3 100644 --- a/pkgs/applications/editors/neovim/tests/default.nix +++ b/pkgs/applications/editors/neovim/tests/default.nix @@ -1,6 +1,12 @@ # run tests by building `neovim.tests` -{ vimUtils, writeText, neovim, vimPlugins -, lib, fetchFromGitHub, neovimUtils, wrapNeovimUnstable +{ vimUtils +, writeText +, neovim +, vimPlugins +, lib +, fetchFromGitHub +, neovimUtils +, wrapNeovimUnstable , neovim-unwrapped , fetchFromGitLab , runCommandLocal @@ -9,8 +15,6 @@ let inherit (neovimUtils) makeNeovimConfig; - packages.myVimPackage.start = with vimPlugins; [ vim-nix ]; - plugins = with vimPlugins; [ { plugin = vim-obsession; @@ -47,11 +51,8 @@ let nvimAutoDisableWrap = makeNeovimConfig { }; - nvimConfDontWrap = makeNeovimConfig { - inherit plugins; - customRC = '' - " just a comment - ''; + neovimWithCyan = neovim.override { + configure.packages.all.start = [ vimPlugins.nvim-teal-maker ]; }; wrapNeovim2 = suffix: config: @@ -68,7 +69,7 @@ let # this plugin checks that it's ftplugin/vim.tex is loaded before $VIMRUNTIME/ftplugin/vim.tex # the answer is store in `plugin_was_loaded_too_late` in the cwd - texFtplugin = (pkgs.runCommandLocal "tex-ftplugin" {} '' + texFtplugin = (pkgs.runCommandLocal "tex-ftplugin" { } '' mkdir -p $out/ftplugin echo 'call system("echo ". exists("b:did_ftplugin") . " > plugin_was_loaded_too_late")' > $out/ftplugin/tex.vim echo ':q!' >> $out/ftplugin/tex.vim @@ -77,20 +78,22 @@ let # neovim-drv must be a wrapped neovim runTest = neovim-drv: buildCommand: - runCommandLocal "test-${neovim-drv.name}" ({ - nativeBuildInputs = [ ]; - meta.platforms = neovim-drv.meta.platforms; - }) ('' + runCommandLocal "test-${neovim-drv.name}" + { + nativeBuildInputs = [ ]; + meta.platforms = neovim-drv.meta.platforms; + } '' source ${nmt}/bash-lib/assertions.sh vimrc="${writeText "init.vim" neovim-drv.initRc}" vimrcGeneric="$out/patched.vim" mkdir $out ${pkgs.perl}/bin/perl -pe "s|\Q$NIX_STORE\E/[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" < "$vimrc" > "$vimrcGeneric" - '' + buildCommand); + ${buildCommand} + ''; in - pkgs.recurseIntoAttrs ( -rec { + +pkgs.recurseIntoAttrs rec { vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; }; ### neovim tests @@ -98,9 +101,9 @@ rec { nvim_with_plugins = wrapNeovim2 "-with-plugins" nvimConfNix; singlelinesconfig = runTest (wrapNeovim2 "-single-lines" nvimConfSingleLines) '' - assertFileContent \ - "$vimrcGeneric" \ - "${./init-single-lines.vim}" + assertFileContent \ + "$vimrcGeneric" \ + "${./init-single-lines.vim}" ''; nvim_via_override = neovim.override { @@ -123,7 +126,7 @@ rec { extraName = "-with-plug"; configure.packages.plugins = with pkgs.vimPlugins; { start = [ - (base16-vim.overrideAttrs(old: { pname = old.pname + "-unique-for-tests-please-dont-use"; })) + (base16-vim.overrideAttrs (old: { pname = old.pname + "-unique-for-tests-please-dont-use"; })) ]; }; configure.customRC = '' @@ -159,7 +162,7 @@ rec { # check that the vim-doc hook correctly generates the tag # we know for a fact packer has a doc folder - checkForTags = vimPlugins.packer-nvim.overrideAttrs(oldAttrs: { + checkForTags = vimPlugins.packer-nvim.overrideAttrs (oldAttrs: { doInstallCheck = true; installCheckPhase = '' [ -f $out/doc/tags ] @@ -179,25 +182,25 @@ rec { }); force-nowrap = runTest nvimDontWrap '' - ! grep -F -- ' -u' ${nvimDontWrap}/bin/nvim + ! grep -F -- ' -u' ${nvimDontWrap}/bin/nvim ''; nvim_via_override-test = runTest nvim_via_override '' - assertFileContent \ - "$vimrcGeneric" \ - "${./init-override.vim}" + assertFileContent \ + "$vimrcGeneric" \ + "${./init-override.vim}" ''; checkAliases = runTest nvim_with_aliases '' - folder=${nvim_with_aliases}/bin - assertFileExists "$folder/vi" - assertFileExists "$folder/vim" + folder=${nvim_with_aliases}/bin + assertFileExists "$folder/vi" + assertFileExists "$folder/vim" ''; # having no RC generated should autodisable init.vim wrapping nvim_autowrap = runTest nvim_via_override '' - ! grep "-u" ${nvimShouldntWrap}/bin/nvim + ! grep "-u" ${nvimShouldntWrap}/bin/nvim ''; @@ -211,7 +214,7 @@ rec { }; nvimWithLuaPackages = wrapNeovim2 "-with-lua-packages" (makeNeovimConfig { - extraLuaPackages = ps: [ps.mpack]; + extraLuaPackages = ps: [ ps.mpack ]; customRC = '' lua require("mpack") ''; @@ -227,7 +230,7 @@ rec { extraName = "-with-opt-plugin"; configure.packages.opt-plugins = with pkgs.vimPlugins; { opt = [ - (dashboard-nvim.overrideAttrs(old: { pname = old.pname + "-unique-for-tests-please-dont-use-opt"; })) + (dashboard-nvim.overrideAttrs (old: { pname = old.pname + "-unique-for-tests-please-dont-use-opt"; })) ]; }; configure.customRC = '' @@ -261,4 +264,9 @@ rec { export HOME=$TMPDIR ${nvim_with_opt_plugin}/bin/nvim -i NONE +quit! -e ''; -}) + + pathDeps = runTest neovimWithCyan '' + export HOME=$(mktemp -d) + ${neovimWithCyan}/bin/nvim --headless -ei NONE '+!cyan version' +quit! + ''; +} diff --git a/pkgs/applications/editors/neovim/utils.nix b/pkgs/applications/editors/neovim/utils.nix index 05037eafcb871..3848d4221fd94 100644 --- a/pkgs/applications/editors/neovim/utils.nix +++ b/pkgs/applications/editors/neovim/utils.nix @@ -32,7 +32,7 @@ let # expects a list of plugin configuration # expects { plugin=far-vim; config = "let g:far#source='rg'"; optional = false; } - , plugins ? [] + , plugins ? [ ] # custom viml config appended after plugin-specific config , customRC ? "" @@ -59,23 +59,25 @@ let in map (x: defaultPlugin // (if (x ? plugin) then x else { plugin = x; })) plugins; - pluginRC = lib.foldl (acc: p: if p.config != null then acc ++ [p.config] else acc) [] pluginsNormalized; + pluginRC = lib.foldl (acc: p: if p.config != null then acc ++ [ p.config ] else acc) [ ] pluginsNormalized; pluginsPartitioned = lib.partition (x: x.optional == true) pluginsNormalized; requiredPlugins = vimUtils.requiredPluginsForPackage myVimPackage; getDeps = attrname: map (plugin: plugin.${attrname} or (_: [ ])); myVimPackage = { - start = map (x: x.plugin) pluginsPartitioned.wrong; - opt = map (x: x.plugin) pluginsPartitioned.right; + start = map (x: x.plugin) pluginsPartitioned.wrong; + opt = map (x: x.plugin) pluginsPartitioned.right; }; + pathDependencies = lib.concatMap (plugin: plugin.pathDependencies or [ ]) requiredPlugins; + pluginPython3Packages = getDeps "python3Dependencies" requiredPlugins; python3Env = python3Packages.python.withPackages (ps: [ ps.pynvim ] ++ (extraPython3Packages ps) ++ (lib.concatMap (f: f ps) pluginPython3Packages)); - luaEnv = neovim-unwrapped.lua.withPackages(extraLuaPackages); + luaEnv = neovim-unwrapped.lua.withPackages extraLuaPackages; # Mapping a boolean argument to a key that tells us whether to add or not to # add to nvim's 'embedded rc' this: @@ -91,11 +93,13 @@ let }; ## Here we calculate all of the arguments to the 1st call of `makeWrapper` # We start with the executable itself NOTE we call this variable "initial" - # because if configure != {} we need to call makeWrapper twice, in order to + # because if configure != { } we need to call makeWrapper twice, in order to # avoid double wrapping, see comment near finalMakeWrapperArgs makeWrapperArgs = let - binPath = lib.makeBinPath (lib.optionals withRuby [ rubyEnv ] ++ lib.optionals withNodeJs [ nodejs ]); + binPath = lib.makeBinPath (pathDependencies + ++ lib.optionals withRuby [ rubyEnv ] + ++ lib.optionals withNodeJs [ nodejs ]); hostProviderViml = lib.mapAttrsToList genProviderSettings hostprog_check_table; @@ -107,7 +111,7 @@ let "--cmd" (lib.intersperse "|" hostProviderViml) "--cmd" "set packpath^=${vimUtils.packDir packDirArgs}" "--cmd" "set rtp^=${vimUtils.packDir packDirArgs}" - ]; + ]; in [ "--inherit-argv0" "--add-flags" (lib.escapeShellArgs flags) @@ -120,13 +124,13 @@ let "--prefix" "LUA_CPATH" ";" (neovim-unwrapped.lua.pkgs.luaLib.genLuaCPathAbsStr luaEnv) ]; - manifestRc = vimUtils.vimrcContent ({ customRC = ""; }) ; + manifestRc = vimUtils.vimrcContent { customRC = ""; } ; # we call vimrcContent without 'packages' to avoid the init.vim generation - neovimRcContent = vimUtils.vimrcContent ({ + neovimRcContent = vimUtils.vimrcContent { beforePlugins = ""; customRC = lib.concatStringsSep "\n" (pluginRC ++ [customRC]); packages = null; - }); + }; in builtins.removeAttrs args ["plugins"] // { @@ -151,16 +155,16 @@ let legacyWrapper = neovim: { extraMakeWrapperArgs ? "" /* the function you would have passed to python.withPackages */ - , extraPythonPackages ? (_: []) + , extraPythonPackages ? (_: [ ]) /* the function you would have passed to python.withPackages */ - , withPython3 ? true, extraPython3Packages ? (_: []) + , withPython3 ? true, extraPython3Packages ? (_: [ ]) /* the function you would have passed to lua.withPackages */ - , extraLuaPackages ? (_: []) + , extraLuaPackages ? (_: [ ]) , withNodeJs ? false , withRuby ? true , vimAlias ? false , viAlias ? false - , configure ? {} + , configure ? { } , extraName ? "" }: let @@ -169,8 +173,8 @@ let plugins = if builtins.hasAttr "plug" configure then throw "The neovim legacy wrapper doesn't support configure.plug anymore, please setup your plugins via 'configure.packages' instead" else - lib.flatten (lib.mapAttrsToList genPlugin (configure.packages or {})); - genPlugin = packageName: {start ? [], opt ? []}: + lib.flatten (lib.mapAttrsToList genPlugin (configure.packages or { })); + genPlugin = packageName: {start ? [ ], opt ? [ ]}: start ++ (map (p: { plugin = p; optional = true; }) opt); res = makeNeovimConfig { @@ -185,8 +189,8 @@ let in wrapNeovimUnstable neovim (res // { wrapperArgs = lib.escapeShellArgs res.wrapperArgs + " " + extraMakeWrapperArgs; - wrapRc = (configure != {}); - }); + wrapRc = configure != { }; + }); in { inherit makeNeovimConfig; diff --git a/pkgs/applications/editors/vim/plugins/overrides.nix b/pkgs/applications/editors/vim/plugins/overrides.nix index 08b8ae20412e6..0101eb3c1d2f5 100644 --- a/pkgs/applications/editors/vim/plugins/overrides.nix +++ b/pkgs/applications/editors/vim/plugins/overrides.nix @@ -674,10 +674,7 @@ self: super: { }); nvim-teal-maker = super.nvim-teal-maker.overrideAttrs (old: { - postPatch = '' - substituteInPlace lua/tealmaker/init.lua \ - --replace cyan ${luaPackages.cyan}/bin/cyan - ''; + passthru.pathDependencies = [ luaPackages.cyan ]; vimCommandCheck = "TealBuild"; });