mirror of
https://github.com/nix-community/home-manager
synced 2024-11-27 05:29:46 +01:00
neovim: support different configuration languages (#2637)
Plugins now accept a "type" element describing the language (viml, lua , teal, fennel, ...) in which they are configured. The configuration of the different plugins is aggregated per language and made available as a key in the attribute set `programs.neovim.generatedConfigs` For instance if you want to configure a lua package: ``` programs.neovim.plugins = [ { plugin = packer-nvim; type = "lua"; config = '' require('packer').init({ luarocks = { python_cmd = 'python' -- Set the python command to use for running hererocks }, }) ''; } ] ``` and you can save the generated lua config to a file via ``` xdg.configFile = { "nvim/init.generated.lua".text = config.programs.neovim.generatedConfigs.lua; }; ```
This commit is contained in:
parent
24ed6e6d4d
commit
8d3fe1366b
1 changed files with 53 additions and 3 deletions
|
@ -20,10 +20,19 @@ let
|
||||||
options = {
|
options = {
|
||||||
config = mkOption {
|
config = mkOption {
|
||||||
type = types.lines;
|
type = types.lines;
|
||||||
description = "vimscript for this plugin to be placed in init.vim";
|
description =
|
||||||
|
"Script to configure this plugin. The scripting language should match type.";
|
||||||
default = "";
|
default = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type = mkOption {
|
||||||
|
type =
|
||||||
|
types.either (types.enum [ "lua" "viml" "teal" "fennel" ]) types.str;
|
||||||
|
description =
|
||||||
|
"Language used in config. Configurations are aggregated per-language.";
|
||||||
|
default = "viml";
|
||||||
|
};
|
||||||
|
|
||||||
optional = mkEnableOption "optional" // {
|
optional = mkEnableOption "optional" // {
|
||||||
description = "Don't load by default (load with :packadd)";
|
description = "Don't load by default (load with :packadd)";
|
||||||
};
|
};
|
||||||
|
@ -141,6 +150,28 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
generatedConfigs = mkOption {
|
||||||
|
type = types.attrsOf types.lines;
|
||||||
|
visible = true;
|
||||||
|
readOnly = true;
|
||||||
|
example = literalExpression ''
|
||||||
|
{
|
||||||
|
viml = '''
|
||||||
|
" Generated by home-manager
|
||||||
|
set packpath^=/nix/store/cn8vvv4ymxjf8cfzg7db15b2838nqqib-vim-pack-dir
|
||||||
|
set runtimepath^=/nix/store/cn8vvv4ymxjf8cfzg7db15b2838nqqib-vim-pack-dir
|
||||||
|
''';
|
||||||
|
|
||||||
|
lua = '''
|
||||||
|
-- Generated by home-manager
|
||||||
|
vim.opt.background = "dark"
|
||||||
|
''';
|
||||||
|
}'';
|
||||||
|
description = ''
|
||||||
|
Generated configurations with as key their language (set via type).
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
package = mkOption {
|
package = mkOption {
|
||||||
type = types.package;
|
type = types.package;
|
||||||
default = pkgs.neovim-unwrapped;
|
default = pkgs.neovim-unwrapped;
|
||||||
|
@ -270,12 +301,25 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
config = let
|
config = let
|
||||||
|
# transform all plugins into an attrset
|
||||||
|
pluginsNormalized = map (x:
|
||||||
|
if (x ? plugin) then
|
||||||
|
x
|
||||||
|
else {
|
||||||
|
type = x.type or "viml";
|
||||||
|
plugin = x;
|
||||||
|
config = "";
|
||||||
|
optional = false;
|
||||||
|
}) cfg.plugins;
|
||||||
|
suppressNotVimlConfig = p:
|
||||||
|
if p.type != "viml" then p // { config = ""; } else p;
|
||||||
|
|
||||||
neovimConfig = pkgs.neovimUtils.makeNeovimConfig {
|
neovimConfig = pkgs.neovimUtils.makeNeovimConfig {
|
||||||
inherit (cfg)
|
inherit (cfg)
|
||||||
extraPython3Packages withPython3 withNodeJs withRuby viAlias vimAlias;
|
extraPython3Packages withPython3 withNodeJs withRuby viAlias vimAlias;
|
||||||
configure = cfg.configure // moduleConfigure;
|
configure = cfg.configure // moduleConfigure;
|
||||||
plugins = cfg.plugins
|
plugins = (map suppressNotVimlConfig pluginsNormalized)
|
||||||
++ optionals cfg.coc.enable [ pkgs.vimPlugins.coc-nvim ];
|
++ optionals cfg.coc.enable [{ plugin = pkgs.vimPlugins.coc-nvim; }];
|
||||||
customRC = cfg.extraConfig;
|
customRC = cfg.extraConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -291,6 +335,12 @@ in {
|
||||||
|
|
||||||
programs.neovim.generatedConfigViml = neovimConfig.neovimRcContent;
|
programs.neovim.generatedConfigViml = neovimConfig.neovimRcContent;
|
||||||
|
|
||||||
|
programs.neovim.generatedConfigs = let
|
||||||
|
grouped = lib.lists.groupBy (x: x.type) pluginsNormalized;
|
||||||
|
concatConfigs =
|
||||||
|
lib.concatMapStrings (p: builtins.trace p.plugin.name p.config);
|
||||||
|
in mapAttrs (name: vals: concatConfigs vals) grouped;
|
||||||
|
|
||||||
home.packages = [ cfg.finalPackage ];
|
home.packages = [ cfg.finalPackage ];
|
||||||
|
|
||||||
xdg.configFile."nvim/init.vim" = mkIf (neovimConfig.neovimRcContent != "") {
|
xdg.configFile."nvim/init.vim" = mkIf (neovimConfig.neovimRcContent != "") {
|
||||||
|
|
Loading…
Reference in a new issue