mirror of
https://github.com/nix-community/home-manager
synced 2024-11-23 19:49:45 +01:00
programs.neovim: default to init.lua (#3233)
We change the current logic: instead of writing an init.vim which loads lua/init-home-manager.lua, we write an init.lua that sources init.vim This commit also avoids writing any of these files if the plugins have no config.
This commit is contained in:
parent
f17819f4f1
commit
bd83eab622
3 changed files with 33 additions and 23 deletions
|
@ -35,10 +35,10 @@ let
|
||||||
pluginWithConfigType = types.submodule {
|
pluginWithConfigType = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
config = mkOption {
|
config = mkOption {
|
||||||
type = types.lines;
|
type = types.nullOr types.lines;
|
||||||
description =
|
description =
|
||||||
"Script to configure this plugin. The scripting language should match type.";
|
"Script to configure this plugin. The scripting language should match type.";
|
||||||
default = "";
|
default = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
type = mkOption {
|
type = mkOption {
|
||||||
|
@ -326,7 +326,7 @@ in {
|
||||||
defaultPlugin = {
|
defaultPlugin = {
|
||||||
type = "viml";
|
type = "viml";
|
||||||
plugin = null;
|
plugin = null;
|
||||||
config = "";
|
config = null;
|
||||||
optional = false;
|
optional = false;
|
||||||
runtime = { };
|
runtime = { };
|
||||||
};
|
};
|
||||||
|
@ -337,7 +337,7 @@ in {
|
||||||
allPlugins;
|
allPlugins;
|
||||||
|
|
||||||
suppressNotVimlConfig = p:
|
suppressNotVimlConfig = p:
|
||||||
if p.type != "viml" then p // { config = ""; } else p;
|
if p.type != "viml" then p // { config = null; } else p;
|
||||||
|
|
||||||
neovimConfig = pkgs.neovimUtils.makeNeovimConfig {
|
neovimConfig = pkgs.neovimUtils.makeNeovimConfig {
|
||||||
inherit (cfg) extraPython3Packages withPython3 withRuby viAlias vimAlias;
|
inherit (cfg) extraPython3Packages withPython3 withRuby viAlias vimAlias;
|
||||||
|
@ -353,22 +353,29 @@ in {
|
||||||
programs.neovim.generatedConfigs = let
|
programs.neovim.generatedConfigs = let
|
||||||
grouped = lib.lists.groupBy (x: x.type) pluginsNormalized;
|
grouped = lib.lists.groupBy (x: x.type) pluginsNormalized;
|
||||||
concatConfigs = lib.concatMapStrings (p: p.config);
|
concatConfigs = lib.concatMapStrings (p: p.config);
|
||||||
in mapAttrs (name: vals: concatConfigs vals) grouped;
|
configsOnly = lib.foldl
|
||||||
|
(acc: p: if p.config != null then acc ++ [ (p.config) ] else acc) [ ];
|
||||||
|
in mapAttrs (name: vals: lib.concatStringsSep "\n" (configsOnly vals))
|
||||||
|
grouped;
|
||||||
|
|
||||||
home.packages = [ cfg.finalPackage ];
|
home.packages = [ cfg.finalPackage ];
|
||||||
|
|
||||||
xdg.configFile = mkMerge (
|
xdg.configFile =
|
||||||
|
let hasLuaConfig = hasAttr "lua" config.programs.neovim.generatedConfigs;
|
||||||
|
in mkMerge (
|
||||||
# writes runtime
|
# writes runtime
|
||||||
(map (x: x.runtime) pluginsNormalized) ++ [{
|
(map (x: x.runtime) pluginsNormalized) ++ [{
|
||||||
"nvim/init.vim" = mkIf (neovimConfig.neovimRcContent != "") {
|
"nvim/init.vim" = mkIf (neovimConfig.neovimRcContent != "") {
|
||||||
text = neovimConfig.neovimRcContent + lib.optionalString
|
text = neovimConfig.neovimRcContent;
|
||||||
(hasAttr "lua" config.programs.neovim.generatedConfigs)
|
|
||||||
"lua require('init-home-manager')";
|
|
||||||
};
|
|
||||||
"nvim/lua/init-home-manager.lua" =
|
|
||||||
mkIf (hasAttr "lua" config.programs.neovim.generatedConfigs) {
|
|
||||||
text = config.programs.neovim.generatedConfigs.lua;
|
|
||||||
};
|
};
|
||||||
|
"nvim/init.lua" = let
|
||||||
|
luaRcContent =
|
||||||
|
lib.optionalString (neovimConfig.neovimRcContent != "")
|
||||||
|
"vim.cmd.source ${config.xdg.configHome}/nvim/init.vim"
|
||||||
|
+ lib.optionalString hasLuaConfig
|
||||||
|
config.programs.neovim.generatedConfigs.lua;
|
||||||
|
in mkIf (luaRcContent != "") { text = luaRcContent; };
|
||||||
|
|
||||||
"nvim/coc-settings.json" = mkIf cfg.coc.enable {
|
"nvim/coc-settings.json" = mkIf cfg.coc.enable {
|
||||||
source = jsonFormat.generate "coc-settings.json" cfg.coc.settings;
|
source = jsonFormat.generate "coc-settings.json" cfg.coc.settings;
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,10 +12,14 @@ with lib;
|
||||||
withRuby = false;
|
withRuby = false;
|
||||||
|
|
||||||
extraPython3Packages = (ps: with ps; [ jedi pynvim ]);
|
extraPython3Packages = (ps: with ps; [ jedi pynvim ]);
|
||||||
|
|
||||||
|
# plugins without associated config should not trigger the creation of init.vim
|
||||||
|
plugins = with pkgs.vimPlugins; [ fugitive ({ plugin = vim-sensible; }) ];
|
||||||
};
|
};
|
||||||
nmt.script = ''
|
nmt.script = ''
|
||||||
vimrc="home-files/.config/nvim/init.vim"
|
nvimFolder="home-files/.config/nvim"
|
||||||
assertPathNotExists "$vimrc"
|
assertPathNotExists "$nvimFolder/init.vim"
|
||||||
|
assertPathNotExists "$nvimFolder/init.lua"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
" plugin-specific config
|
" plugin-specific config
|
||||||
autocmd FileType c setlocal commentstring=//\ %s
|
autocmd FileType c setlocal commentstring=//\ %s
|
||||||
autocmd FileType c setlocal comments=://
|
autocmd FileType c setlocal comments=://
|
||||||
|
|
Loading…
Reference in a new issue