From 80affffad2758b0ae7931a0e729fdf0bcfd6ddd8 Mon Sep 17 00:00:00 2001 From: figsoda Date: Tue, 27 Dec 2022 15:39:02 -0500 Subject: [PATCH 1/5] neovimUtils.makeNeovimConfig: format --- pkgs/applications/editors/neovim/utils.nix | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/pkgs/applications/editors/neovim/utils.nix b/pkgs/applications/editors/neovim/utils.nix index 05037eafcb871..96a67e022694e 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,14 +59,14 @@ 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; }; pluginPython3Packages = getDeps "python3Dependencies" requiredPlugins; @@ -75,7 +75,7 @@ let ++ (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,7 +91,7 @@ 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 @@ -107,7 +107,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 +120,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 +151,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 +169,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 +185,8 @@ let in wrapNeovimUnstable neovim (res // { wrapperArgs = lib.escapeShellArgs res.wrapperArgs + " " + extraMakeWrapperArgs; - wrapRc = (configure != {}); - }); + wrapRc = configure != { }; + }); in { inherit makeNeovimConfig; From b26c6b6b82aaa0f172f372fccf88d01642e8942b Mon Sep 17 00:00:00 2001 From: figsoda Date: Tue, 27 Dec 2022 15:57:44 -0500 Subject: [PATCH 2/5] neovimUtils.makeNeovimConfig: add pathDependencies --- pkgs/applications/editors/neovim/utils.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/applications/editors/neovim/utils.nix b/pkgs/applications/editors/neovim/utils.nix index 96a67e022694e..3848d4221fd94 100644 --- a/pkgs/applications/editors/neovim/utils.nix +++ b/pkgs/applications/editors/neovim/utils.nix @@ -69,6 +69,8 @@ let 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 ] @@ -95,7 +97,9 @@ let # 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; From 7c0fec51d4328009f5a2d3fcb595b4eee0f2bac2 Mon Sep 17 00:00:00 2001 From: figsoda Date: Tue, 27 Dec 2022 16:01:17 -0500 Subject: [PATCH 3/5] neovim.tests: format --- .../editors/neovim/tests/default.nix | 69 +++++++++---------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/pkgs/applications/editors/neovim/tests/default.nix b/pkgs/applications/editors/neovim/tests/default.nix index 29749c35db1fa..9de30f313f121 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,13 +51,6 @@ let nvimAutoDisableWrap = makeNeovimConfig { }; - nvimConfDontWrap = makeNeovimConfig { - inherit plugins; - customRC = '' - " just a comment - ''; - }; - wrapNeovim2 = suffix: config: wrapNeovimUnstable neovim-unwrapped (config // { extraName = suffix; @@ -68,7 +65,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 +74,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 +97,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 +122,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 +158,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 +178,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 +210,7 @@ rec { }; nvimWithLuaPackages = wrapNeovim2 "-with-lua-packages" (makeNeovimConfig { - extraLuaPackages = ps: [ps.mpack]; + extraLuaPackages = ps: [ ps.mpack ]; customRC = '' lua require("mpack") ''; @@ -227,7 +226,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 +260,4 @@ rec { export HOME=$TMPDIR ${nvim_with_opt_plugin}/bin/nvim -i NONE +quit! -e ''; -}) +} From b76a1489b65871389bfaf6459188af179d2d167e Mon Sep 17 00:00:00 2001 From: figsoda Date: Tue, 27 Dec 2022 16:06:28 -0500 Subject: [PATCH 4/5] vimPlugins.nvim-teal-maker: use pathDependencies --- pkgs/applications/editors/vim/plugins/overrides.nix | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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"; }); From 38a00d052f20ca75c04f17e774d949be0fd73672 Mon Sep 17 00:00:00 2001 From: figsoda Date: Tue, 27 Dec 2022 16:32:17 -0500 Subject: [PATCH 5/5] neovim.tests: add pathDeps --- pkgs/applications/editors/neovim/tests/default.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkgs/applications/editors/neovim/tests/default.nix b/pkgs/applications/editors/neovim/tests/default.nix index 9de30f313f121..84d4433bc68a3 100644 --- a/pkgs/applications/editors/neovim/tests/default.nix +++ b/pkgs/applications/editors/neovim/tests/default.nix @@ -51,6 +51,10 @@ let nvimAutoDisableWrap = makeNeovimConfig { }; + neovimWithCyan = neovim.override { + configure.packages.all.start = [ vimPlugins.nvim-teal-maker ]; + }; + wrapNeovim2 = suffix: config: wrapNeovimUnstable neovim-unwrapped (config // { extraName = suffix; @@ -260,4 +264,9 @@ pkgs.recurseIntoAttrs 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! + ''; }