neovim: separate init.lua parts with newlines

Parts of init.lua are now separated with newlines.
This commit is contained in:
Stanislav Asunkin 2023-02-19 19:38:02 +03:00
parent 5ffb0f1f81
commit c08bb8405c
4 changed files with 59 additions and 18 deletions

View file

@ -384,7 +384,6 @@ in {
programs.neovim.generatedConfigs = let
grouped = lib.lists.groupBy (x: x.type) pluginsNormalized;
concatConfigs = lib.concatMapStrings (p: p.config);
configsOnly = lib.foldl
(acc: p: if p.config != null then acc ++ [ p.config ] else acc) [ ];
in mapAttrs (name: vals: lib.concatStringsSep "\n" (configsOnly vals))
@ -394,26 +393,32 @@ in {
home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "nvim"; };
xdg.configFile =
let hasLuaConfig = hasAttr "lua" config.programs.neovim.generatedConfigs;
in mkMerge (
# writes runtime
(map (x: x.runtime) pluginsNormalized) ++ [{
"nvim/init.lua" = let
luaRcContent =
lib.optionalString (neovimConfig.neovimRcContent != "")
"vim.cmd [[source ${
xdg.configFile = mkMerge (
# writes runtime
(map (x: x.runtime) pluginsNormalized) ++ [{
"nvim/init.lua" = let
vimlConfig =
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; };
}]]
'';
luaPluginsConfig =
lib.optionalString (hasAttr "lua" cfg.generatedConfigs)
cfg.generatedConfigs.lua;
luaRcContent = builtins.concatStringsSep "\n"
(builtins.filter (str: str != "") [
vimlConfig
cfg.extraLuaConfig
luaPluginsConfig
]);
in mkIf (luaRcContent != "") { text = luaRcContent; };
"nvim/coc-settings.json" = mkIf cfg.coc.enable {
source = jsonFormat.generate "coc-settings.json" cfg.coc.settings;
};
}]);
"nvim/coc-settings.json" = mkIf cfg.coc.enable {
source = jsonFormat.generate "coc-settings.json" cfg.coc.settings;
};
}]);
programs.neovim.finalPackage = pkgs.wrapNeovimUnstable cfg.package
(neovimConfig // {

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-multiple-rc-sources = ./multiple-rc-sources.nix;
}

View file

@ -0,0 +1,5 @@
vim.cmd [[source /nix/store/00000000000000000000000000000000-nvim-init-home-manager.vim]]
vim.opt.expandtab = false
vim.g.test_plugin2 = 1

View file

@ -0,0 +1,30 @@
{ config, pkgs, ... }:
{
config = {
programs.neovim = {
enable = true;
extraConfig = ''
set sw=4
'';
extraLuaConfig = ''
vim.opt.expandtab = false
'';
plugins = [{
plugin = pkgs.emptyDirectory;
type = "lua";
config = ''
vim.g.test_plugin2 = 1
'';
}];
};
nmt.script = ''
initLua="$TESTED/home-files/.config/nvim/init.lua"
initLuaNormalized="$(normalizeStorePaths "$initLua")"
assertFileExists "$initLua"
assertFileContent "$initLuaNormalized" "${./multiple-rc-sources.expected}"
'';
};
}