neovim: Add missing newlines to init.lua

When generating `init.lua` the Lua config would be placed immediately
after the nvim config without a new line.

```
vim.cmd [[source /nix/store/cs3al9x1ml5ds3n6n433wcdxp89awac4-nvim-init-home-manager.vim]]--first line of Lua config
```

This change places a newline after each config portion.

```
vim.cmd [[source /nix/store/cs3al9x1ml5ds3n6n433wcdxp89awac4-nvim-init-home-manager.vim]]
--first line of Lua config
```
This commit is contained in:
Joe Wasson 2023-08-13 00:02:34 -07:00 committed by Matthieu Coudron
parent 8765d4e38a
commit 29078da204
3 changed files with 48 additions and 20 deletions

View file

@ -392,22 +392,21 @@ in {
home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "nvim"; };
xdg.configFile =
let hasLuaConfig = hasAttr "lua" config.programs.neovim.generatedConfigs;
xdg.configFile = let
hasLuaConfig = hasAttr "lua" config.programs.neovim.generatedConfigs;
vimRcContent = lib.optionalString (neovimConfig != "") pkgs.writeText
"nvim-init-home-manager.vim" neovimConfig.neovimRcContent;
luaRcContent = lib.concatStringsSep "\n" (lib.remove "" [
(lib.optionalString (vimRcContent != "")
"vim.cmd [[source ${vimRcContent}]]")
(config.programs.neovim.extraLuaConfig)
(lib.optionalString hasLuaConfig
config.programs.neovim.generatedConfigs.lua)
]);
in mkMerge (
# writes runtime
(map (x: x.runtime) pluginsNormalized) ++ [{
"nvim/init.lua" = let
luaRcContent =
lib.optionalString (neovimConfig.neovimRcContent != "")
"vim.cmd [[source ${
pkgs.writeText "nvim-init-home-manager.vim"
neovimConfig.neovimRcContent
}]]" + config.programs.neovim.extraLuaConfig
+ lib.optionalString hasLuaConfig
config.programs.neovim.generatedConfigs.lua;
in mkIf (luaRcContent != "") { text = luaRcContent; };
"nvim/init.lua" = mkIf (luaRcContent != "") { text = luaRcContent; };
"nvim/coc-settings.json" = mkIf cfg.coc.enable {
source = jsonFormat.generate "coc-settings.json" cfg.coc.settings;
};

View file

@ -6,4 +6,5 @@
# waiting for a nixpkgs patch
neovim-no-init = ./no-init.nix;
neovim-extra-lua-init = ./extra-lua-init.nix;
neovim-init-newline = ./init-newline.nix;
}

View file

@ -0,0 +1,28 @@
{ config, lib, pkgs, ... }:
with lib;
let
extraConfig = ''
echo extraConfigVim
'';
in {
config = {
programs.neovim = {
enable = true;
inherit extraConfig;
extraLuaConfig = ''
-- extraLuaConfig
'';
};
nmt.script = ''
nvimFolder="home-files/.config/nvim"
assertFileContent "$nvimFolder/init.lua" ${
pkgs.writeText "init.lua-expected" ''
vim.cmd [[source ${
pkgs.writeText "nvim-init-home-manager.vim" extraConfig
}]]
-- extraLuaConfig
''
}
'';
};
}