From 1df816c407d3a5090c8496c9b00170af7891f021 Mon Sep 17 00:00:00 2001 From: Evgeny Zislis Date: Mon, 9 Jun 2025 23:10:54 +0300 Subject: [PATCH] fix: ensure newline after vim.cmd[[source...]] in neovim init.lua (#7219) Fix an issue where the generated ~/.config/nvim/init.lua lacks a newline after the vim.cmd [[source ...]] directive. Without this newline, subsequent lua configuration is concatenated onto the same line, breaking lua syntax. init.lua Before: vim.cmd [[source /nix/store/...]]vim.opt.rtp:prepend(...) After: vim.cmd [[source /nix/store/...]] vim.opt.rtp:prepend(...) --- modules/programs/neovim.nix | 2 +- tests/modules/programs/neovim/plugin-config.expected | 3 +++ tests/modules/programs/neovim/plugin-config.nix | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/modules/programs/neovim/plugin-config.expected diff --git a/modules/programs/neovim.nix b/modules/programs/neovim.nix index fea556d4..7c5baafe 100644 --- a/modules/programs/neovim.nix +++ b/modules/programs/neovim.nix @@ -472,7 +472,7 @@ in luaRcContent = lib.optionalString ( wrappedNeovim'.initRc != "" - ) "vim.cmd [[source ${pkgs.writeText "nvim-init-home-manager.vim" wrappedNeovim'.initRc}]]" + ) "vim.cmd [[source ${pkgs.writeText "nvim-init-home-manager.vim" wrappedNeovim'.initRc}]]\n" + config.programs.neovim.extraLuaConfig + lib.optionalString hasLuaConfig config.programs.neovim.generatedConfigs.lua; in diff --git a/tests/modules/programs/neovim/plugin-config.expected b/tests/modules/programs/neovim/plugin-config.expected new file mode 100644 index 00000000..d09807c7 --- /dev/null +++ b/tests/modules/programs/neovim/plugin-config.expected @@ -0,0 +1,3 @@ +vim.cmd [[source /nix/store/szdyh45rf0rgiq35zgy5b3z99f8lx8f2-nvim-init-home-manager.vim]] +function HM_PLUGIN_LUA_CONFIG () +end diff --git a/tests/modules/programs/neovim/plugin-config.nix b/tests/modules/programs/neovim/plugin-config.nix index 51c7ff50..ca4c96d6 100644 --- a/tests/modules/programs/neovim/plugin-config.nix +++ b/tests/modules/programs/neovim/plugin-config.nix @@ -20,6 +20,14 @@ lib.mkIf config.test.enableBig { let g:hmPlugins='HM_PLUGINS_CONFIG' ''; } + { + plugin = vim-nix; + type = "lua"; + config = '' + function HM_PLUGIN_LUA_CONFIG () + end + ''; + } ]; extraLuaPackages = ps: [ ps.luautf8 ]; }; @@ -33,5 +41,8 @@ lib.mkIf config.test.enableBig { > "$vimout" || true assertFileContains "$vimout" "HM_EXTRA_CONFIG" assertFileContains "$vimout" "HM_PLUGINS_CONFIG" + + initLua="$TESTED/home-files/.config/nvim/init.lua" + assertFileContent "$initLua" ${./plugin-config.expected} ''; }