mirror of
https://github.com/nix-community/home-manager
synced 2024-11-11 07:34:17 +00: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 {
|
||||
options = {
|
||||
config = mkOption {
|
||||
type = types.lines;
|
||||
type = types.nullOr types.lines;
|
||||
description =
|
||||
"Script to configure this plugin. The scripting language should match type.";
|
||||
default = "";
|
||||
default = null;
|
||||
};
|
||||
|
||||
type = mkOption {
|
||||
|
@ -326,7 +326,7 @@ in {
|
|||
defaultPlugin = {
|
||||
type = "viml";
|
||||
plugin = null;
|
||||
config = "";
|
||||
config = null;
|
||||
optional = false;
|
||||
runtime = { };
|
||||
};
|
||||
|
@ -337,7 +337,7 @@ in {
|
|||
allPlugins;
|
||||
|
||||
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 {
|
||||
inherit (cfg) extraPython3Packages withPython3 withRuby viAlias vimAlias;
|
||||
|
@ -353,26 +353,33 @@ in {
|
|||
programs.neovim.generatedConfigs = let
|
||||
grouped = lib.lists.groupBy (x: x.type) pluginsNormalized;
|
||||
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 ];
|
||||
|
||||
xdg.configFile = mkMerge (
|
||||
# writes runtime
|
||||
(map (x: x.runtime) pluginsNormalized) ++ [{
|
||||
"nvim/init.vim" = mkIf (neovimConfig.neovimRcContent != "") {
|
||||
text = neovimConfig.neovimRcContent + lib.optionalString
|
||||
(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;
|
||||
xdg.configFile =
|
||||
let hasLuaConfig = hasAttr "lua" config.programs.neovim.generatedConfigs;
|
||||
in mkMerge (
|
||||
# writes runtime
|
||||
(map (x: x.runtime) pluginsNormalized) ++ [{
|
||||
"nvim/init.vim" = mkIf (neovimConfig.neovimRcContent != "") {
|
||||
text = neovimConfig.neovimRcContent;
|
||||
};
|
||||
"nvim/coc-settings.json" = mkIf cfg.coc.enable {
|
||||
source = jsonFormat.generate "coc-settings.json" cfg.coc.settings;
|
||||
};
|
||||
}]);
|
||||
"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 {
|
||||
source = jsonFormat.generate "coc-settings.json" cfg.coc.settings;
|
||||
};
|
||||
}]);
|
||||
|
||||
programs.neovim.finalPackage = pkgs.wrapNeovimUnstable cfg.package
|
||||
(neovimConfig // {
|
||||
|
|
|
@ -12,10 +12,14 @@ with lib;
|
|||
withRuby = false;
|
||||
|
||||
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 = ''
|
||||
vimrc="home-files/.config/nvim/init.vim"
|
||||
assertPathNotExists "$vimrc"
|
||||
nvimFolder="home-files/.config/nvim"
|
||||
assertPathNotExists "$nvimFolder/init.vim"
|
||||
assertPathNotExists "$nvimFolder/init.lua"
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
" plugin-specific config
|
||||
autocmd FileType c setlocal commentstring=//\ %s
|
||||
autocmd FileType c setlocal comments=://
|
||||
|
|
Loading…
Reference in a new issue