diff --git a/modules/programs/neovim.nix b/modules/programs/neovim.nix index 858f5576a..48421aed6 100644 --- a/modules/programs/neovim.nix +++ b/modules/programs/neovim.nix @@ -24,12 +24,35 @@ let merge = mergeOneOption; }; + pluginWithConfigType = types.submodule { + options = { + plugin = mkOption { + type = types.package; + description = "vim plugin"; + }; + config = mkOption { + type = types.lines; + description = "vimscript for this plugin to be placed in init.vim"; + default = ""; + }; + }; + }; + + # A function to get the configuration string (if any) from an element of 'plugins' + pluginConfig = p: + if builtins.hasAttr "plugin" p && builtins.hasAttr "config" p then '' + " ${p.plugin.pname} {{{ + ${p.config} + " }}} + '' else ""; + moduleConfigure = - optionalAttrs (cfg.extraConfig != "") { - customRC = cfg.extraConfig; + optionalAttrs (cfg.extraConfig != "" || (lib.filter (hasAttr "config") cfg.plugins) != []) { + customRC = cfg.extraConfig + + pkgs.lib.concatMapStrings pluginConfig cfg.plugins; } - // optionalAttrs (cfg.plugins != []) { - packages.home-manager.start = cfg.plugins; + // optionalAttrs (cfg.plugins != [] ) { + packages.home-manager.start = map (x: x.plugin or x) cfg.plugins; }; in @@ -178,11 +201,20 @@ in }; plugins = mkOption { - type = with types; listOf package; + type = with types; listOf (either package pluginWithConfigType); default = [ ]; - example = literalExample "[ pkgs.vimPlugins.yankring ]"; + example = literalExample '' + with pkgs.vimPlugins; [ + yankring + vim-nix + { plugin = vim-startify; + config = "let g:startify_change_to_vcs_root = 0"; + } + ] + ''; description = '' - List of vim plugins to install. + List of vim plugins to install optionally associated with + configuration to be placed in init.vim. diff --git a/tests/default.nix b/tests/default.nix index a4a4da0c9..7db9b16c0 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -57,6 +57,7 @@ import nmt { ./modules/programs/ncmpcpp ./modules/programs/ne ./modules/programs/neomutt + ./modules/programs/neovim ./modules/programs/newsboat ./modules/programs/nushell ./modules/programs/qutebrowser diff --git a/tests/modules/programs/neovim/default.nix b/tests/modules/programs/neovim/default.nix new file mode 100644 index 000000000..7d6e53aae --- /dev/null +++ b/tests/modules/programs/neovim/default.nix @@ -0,0 +1 @@ +{ neovim-plugin-config = ./plugin-config.nix; } diff --git a/tests/modules/programs/neovim/plugin-config.nix b/tests/modules/programs/neovim/plugin-config.nix new file mode 100644 index 000000000..60edaee82 --- /dev/null +++ b/tests/modules/programs/neovim/plugin-config.nix @@ -0,0 +1,37 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.neovim = { + enable = true; + extraConfig = '' + " This should be present in vimrc + ''; + plugins = with pkgs.vimPlugins; [ + vim-nix + { + plugin = vim-commentary; + config = '' + " This should be present too + autocmd FileType c setlocal commentstring=//\ %s + autocmd FileType c setlocal comments=:// + ''; + } + ]; + }; + + nmt.script = '' + vimrc=$(grep -Po "(?<=-u )[^ ]*" < "${ + builtins.toJSON config.programs.neovim.finalPackage + }/bin/nvim") + # We need to remove the unkown store paths in the config + TESTED="" assertFileContent \ + <( ${pkgs.perl}/bin/perl -pe "s|\Q$NIX_STORE\E/[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" < "$vimrc" + ) \ + "${./plugin-config.vim}" + ''; + }; +} + diff --git a/tests/modules/programs/neovim/plugin-config.vim b/tests/modules/programs/neovim/plugin-config.vim new file mode 100644 index 000000000..a8d833f4e --- /dev/null +++ b/tests/modules/programs/neovim/plugin-config.vim @@ -0,0 +1,22 @@ +" configuration generated by NIX +set nocompatible + + + + + + +set packpath^=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-vim-pack-dir +set runtimepath^=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-vim-pack-dir + +filetype indent plugin on | syn on + + +" This should be present in vimrc +" vim-commentary {{{ +" This should be present too +autocmd FileType c setlocal commentstring=//\ %s +autocmd FileType c setlocal comments=:// + +" }}} +