From 264855146ce619d73fb422b757fa66a937b4a556 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Sun, 4 May 2025 08:36:03 +0200 Subject: [PATCH 1/2] wrapNeovimUnstable: do not generate empty init.vim file The concatStringsSep function will always return a string so the check was actually wrong. --- pkgs/applications/editors/neovim/wrapper.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/applications/editors/neovim/wrapper.nix b/pkgs/applications/editors/neovim/wrapper.nix index 97c7409404b6..d3bc6f347081 100644 --- a/pkgs/applications/editors/neovim/wrapper.nix +++ b/pkgs/applications/editors/neovim/wrapper.nix @@ -119,7 +119,7 @@ let '' ${luaRcContent} '' - + lib.optionalString (neovimRcContent' != null) '' + + lib.optionalString (neovimRcContent' != "") '' vim.cmd.source "${writeText "init.vim" neovimRcContent'}" '' + lib.concatStringsSep "\n" luaPluginRC; From 7102d2f9e2d46e11503547d17a98a9e051e386e1 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Thu, 8 May 2025 20:40:17 +0200 Subject: [PATCH 2/2] neovim.tests: add a check that init.vim is not build if not needed --- .../applications/editors/neovim/tests/default.nix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkgs/applications/editors/neovim/tests/default.nix b/pkgs/applications/editors/neovim/tests/default.nix index 42ca99ea2aa8..06818b5680b3 100644 --- a/pkgs/applications/editors/neovim/tests/default.nix +++ b/pkgs/applications/editors/neovim/tests/default.nix @@ -260,6 +260,21 @@ pkgs.recurseIntoAttrs (rec { [ "$result" = 0 ] ''; + # Generate a neovim wrapper with only a init.lua and no init.vim file + nvim_with_only_init_lua = wrapNeovim2 "-only-lua-init-file" { + luaRcContent = "-- some text"; + }; + + # check that we do not generate an init.vim file if it is not needed + no_init_vim_file = runTest nvim_with_only_init_lua '' + ${nvim_with_only_init_lua}/bin/nvim -i NONE -e --headless -c 'if len(getscriptinfo({"name":"init.vim"})) == 0 | quit | else | cquit | fi' + # This does now work because the lua file is sourced via loadfile() which + # does not add the file name to :scriptnames and getscriptinfo(). + #${nvim_with_only_init_lua}/bin/nvim -i NONE -e --headless -c 'if len(getscriptinfo({"name":"init.lua"})) == 1 | quit | else | cquit | fi' + + assertFileRegex ${nvim_with_only_init_lua}/bin/nvim 'VIMINIT=.*init.lua' + ''; + # 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: {