helpers/vim-plugin/mkVimPlugin: add a colorscheme argument and factor out logic

This commit is contained in:
Gaetan Lepage 2024-03-08 12:06:00 +01:00 committed by Gaétan Lepage
parent 3c9a4b67ae
commit 601010900b
2 changed files with 12 additions and 6 deletions

View file

@ -6,7 +6,7 @@
with lib; { with lib; {
mkVimPlugin = config: { mkVimPlugin = config: {
name, name,
namespace ? "plugins", colorscheme ? false,
url ? url ?
if defaultPackage != null if defaultPackage != null
then defaultPackage.meta.homepage then defaultPackage.meta.homepage
@ -29,6 +29,11 @@ with lib; {
extraPlugins ? [], extraPlugins ? [],
extraPackages ? [], extraPackages ? [],
}: let }: let
namespace =
if colorscheme
then "colorschemes"
else "plugins";
cfg = config.${namespace}.${name}; cfg = config.${namespace}.${name};
# TODO support nested options! # TODO support nested options!
@ -143,6 +148,11 @@ with lib; {
# does this evaluate package? it would not be desired to evaluate package if we use another package. # does this evaluate package? it would not be desired to evaluate package if we use another package.
extraPlugins = extraPlugins ++ optional (defaultPackage != null) cfg.package; extraPlugins = extraPlugins ++ optional (defaultPackage != null) cfg.package;
} }
(optionalAttrs colorscheme {
# We use `mkDefault` here to let individual plugins override this option.
# For instance, setting it to `null` a specific way of setting the coloscheme.
colorscheme = lib.mkDefault name;
})
(extraConfig cfg) (extraConfig cfg)
] ]
); );

View file

@ -6,8 +6,8 @@
... ...
}: }:
helpers.vim-plugin.mkVimPlugin config { helpers.vim-plugin.mkVimPlugin config {
namespace = "colorschemes";
name = "nord"; name = "nord";
colorscheme = true;
originalName = "nord.nvim"; originalName = "nord.nvim";
defaultPackage = pkgs.vimPlugins.nord-nvim; defaultPackage = pkgs.vimPlugins.nord-nvim;
globalPrefix = "nord_"; globalPrefix = "nord_";
@ -61,8 +61,4 @@ helpers.vim-plugin.mkVimPlugin config {
disable_background = true; disable_background = true;
italic = false; italic = false;
}; };
extraConfig = cfg: {
colorscheme = "nord";
};
} }