diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 6c0f88cbd..c3f7c5488 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -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. + ''; + } ]; }; } diff --git a/modules/programs/vim.nix b/modules/programs/vim.nix index 86c6910ec..d9abdc277 100644 --- a/modules/programs/vim.nix +++ b/modules/programs/vim.nix @@ -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: nix-env -f '<nixpkgs>' -qaP -A vimPlugins. + + + + 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; - in mkIf cfg.enable { - programs.vim.package = vim; - home.packages = [ cfg.package ]; - } + 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. + ''; + + home.packages = [ cfg.package ]; + + programs.vim.package = vim; + } ); }