1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-26 16:38:34 +02: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:
Matthieu Coudron 2022-01-27 16:27:35 +01:00 committed by GitHub
parent 24ed6e6d4d
commit 8d3fe1366b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,10 +20,19 @@ let
options = {
config = mkOption {
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 = "";
};
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" // {
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 {
type = types.package;
default = pkgs.neovim-unwrapped;
@ -270,12 +301,25 @@ in {
};
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 {
inherit (cfg)
extraPython3Packages withPython3 withNodeJs withRuby viAlias vimAlias;
configure = cfg.configure // moduleConfigure;
plugins = cfg.plugins
++ optionals cfg.coc.enable [ pkgs.vimPlugins.coc-nvim ];
plugins = (map suppressNotVimlConfig pluginsNormalized)
++ optionals cfg.coc.enable [{ plugin = pkgs.vimPlugins.coc-nvim; }];
customRC = cfg.extraConfig;
};
@ -291,6 +335,12 @@ in {
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 ];
xdg.configFile."nvim/init.vim" = mkIf (neovimConfig.neovimRcContent != "") {