mirror of
https://github.com/nix-community/home-manager
synced 2024-11-30 06:59:45 +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:
parent
55b71223d4
commit
f1146a1fef
2 changed files with 60 additions and 13 deletions
|
@ -1176,6 +1176,15 @@ in
|
|||
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.
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ with lib;
|
|||
let
|
||||
|
||||
cfg = config.programs.vim;
|
||||
defaultPlugins = [ "sensible" ];
|
||||
defaultPlugins = [ pkgs.vimPlugins.sensible ];
|
||||
|
||||
knownSettings = {
|
||||
background = types.enum [ "dark" "light" ];
|
||||
|
@ -55,6 +55,16 @@ let
|
|||
in
|
||||
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
|
||||
|
||||
{
|
||||
|
@ -63,12 +73,16 @@ in
|
|||
enable = mkEnableOption "Vim";
|
||||
|
||||
plugins = mkOption {
|
||||
type = types.listOf types.str;
|
||||
type = with types; listOf (either str package);
|
||||
default = defaultPlugins;
|
||||
example = [ "YankRing" ];
|
||||
example = literalExample ''[ pkgs.vimPlugins.YankRing ]'';
|
||||
description = ''
|
||||
List of vim plugins to install. To get a list of supported plugins run:
|
||||
<command>nix-env -f '<nixpkgs>' -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 {
|
||||
name = "vim";
|
||||
vimrcConfig.customRC = customRC;
|
||||
vimrcConfig.vam.knownPlugins = pkgs.vimPlugins;
|
||||
vimrcConfig.vam.pluginDictionaries = [
|
||||
{ names = defaultPlugins ++ cfg.plugins; }
|
||||
];
|
||||
};
|
||||
vimrcConfig = {
|
||||
inherit customRC;
|
||||
|
||||
packages.home-manager.start = plugins;
|
||||
};
|
||||
};
|
||||
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.
|
||||
'';
|
||||
|
||||
in mkIf cfg.enable {
|
||||
programs.vim.package = vim;
|
||||
home.packages = [ cfg.package ];
|
||||
|
||||
programs.vim.package = vim;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue