1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-27 05:29:46 +01:00

vim: allow packages to be passed as plugins

This change allows to pass custom packages into the `vim.plugins`
option.

Additionally this adds a deprecation warning and an error message if a
vim plugin is not present. This is an improvement because the user
gets instant feedback, when a plugin is not found.
This commit is contained in:
Tobias Happ 2019-08-18 16:36:46 +02:00 committed by Robert Helgesson
parent 55b71223d4
commit f1146a1fef
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
2 changed files with 60 additions and 13 deletions

View file

@ -1176,6 +1176,15 @@ in
A new module is available: 'services.dwm-status'. A new module is available: 'services.dwm-status'.
''; '';
} }
{
time = "2019-08-28T10:18:07+00:00";
condition = config.programs.vim.enable;
message = ''
The 'programs.vim.plugins' option now accepts packages.
Specifying them as strings is deprecated.
'';
}
]; ];
}; };
} }

View file

@ -5,7 +5,7 @@ with lib;
let let
cfg = config.programs.vim; cfg = config.programs.vim;
defaultPlugins = [ "sensible" ]; defaultPlugins = [ pkgs.vimPlugins.sensible ];
knownSettings = { knownSettings = {
background = types.enum [ "dark" "light" ]; background = types.enum [ "dark" "light" ];
@ -55,6 +55,16 @@ let
in in
optionalString (value != null) ("set " + v); optionalString (value != null) ("set " + v);
plugins =
let
vpkgs = pkgs.vimPlugins;
getPkg = p:
if isDerivation p
then [ p ]
else optional (isString p && hasAttr p vpkgs) vpkgs.${p};
in
concatMap getPkg cfg.plugins;
in in
{ {
@ -63,12 +73,16 @@ in
enable = mkEnableOption "Vim"; enable = mkEnableOption "Vim";
plugins = mkOption { plugins = mkOption {
type = types.listOf types.str; type = with types; listOf (either str package);
default = defaultPlugins; default = defaultPlugins;
example = [ "YankRing" ]; example = literalExample ''[ pkgs.vimPlugins.YankRing ]'';
description = '' description = ''
List of vim plugins to install. To get a list of supported plugins run: List of vim plugins to install. To get a list of supported plugins run:
<command>nix-env -f '&lt;nixpkgs&gt;' -qaP -A vimPlugins</command>. <command>nix-env -f '&lt;nixpkgs&gt;' -qaP -A vimPlugins</command>.
</para><para>
Note: String values are deprecated, please use actual packages.
''; '';
}; };
@ -135,16 +149,40 @@ in
vim = pkgs.vim_configurable.customize { vim = pkgs.vim_configurable.customize {
name = "vim"; name = "vim";
vimrcConfig.customRC = customRC; vimrcConfig = {
vimrcConfig.vam.knownPlugins = pkgs.vimPlugins; inherit customRC;
vimrcConfig.vam.pluginDictionaries = [
{ names = defaultPlugins ++ cfg.plugins; }
];
};
in mkIf cfg.enable { packages.home-manager.start = plugins;
programs.vim.package = vim; };
home.packages = [ cfg.package ]; };
} in
mkIf cfg.enable {
assertions =
let
packagesNotFound = filter (p: isString p && (!hasAttr p pkgs.vimPlugins)) cfg.plugins;
in
[
{
assertion = packagesNotFound == [];
message = "Following VIM plugin not found in pkgs.vimPlugins: ${
concatMapStringsSep ", " (p: ''"${p}"'') packagesNotFound
}";
}
];
warnings =
let
stringPlugins = filter isString cfg.plugins;
in
optional (stringPlugins != []) ''
Specifying VIM plugins using strings is deprecated, found ${
concatMapStringsSep ", " (p: ''"${p}"'') stringPlugins
} as strings.
'';
home.packages = [ cfg.package ];
programs.vim.package = vim;
}
); );
} }