colorschemes/base16: use mkVimPlugin

This commit is contained in:
Gaetan Lepage 2024-03-08 14:25:07 +01:00 committed by Gaétan Lepage
parent 4fd3cd1203
commit c2cd3cb7a1
2 changed files with 101 additions and 100 deletions

View file

@ -5,38 +5,39 @@
pkgs, pkgs,
... ...
}: }:
with lib; let with lib;
cfg = config.colorschemes.base16; # We configure this plugin manually (no `settings` option) so there is no point in using
themes = import ./theme-list.nix; # `mkNeovimPlugin` here.
in { helpers.vim-plugin.mkVimPlugin config {
options = { name = "base16";
colorschemes.base16 = { isColorscheme = true;
enable = mkEnableOption "base16"; originalName = "base16.nvim";
defaultPackage = pkgs.vimPlugins.base16-nvim;
package = helpers.mkPackageOption "base16" pkgs.vimPlugins.base16-nvim; maintainers = [maintainers.GaetanLepage];
useTruecolor = mkOption { # We manually set the colorscheme if needed.
type = types.bool; colorscheme = null;
default = true;
description = "Whether to use truecolor for the colorschemes. If set to false, you'll need to set up base16 in your shell.";
};
colorscheme = mkOption { # TODO introduced 2024-03-12: remove 2024-05-12
type = types.nullOr (types.enum themes); imports = let
description = "The base16 colorscheme to use"; basePluginPath = ["colorschemes" "base16"];
default = null; in [
}; (
mkRenamedOptionModule
(basePluginPath ++ ["customColorScheme"])
(basePluginPath ++ ["colorscheme"])
)
(
mkRenamedOptionModule
(basePluginPath ++ ["useTruecolor"])
["options" "termguicolors"]
)
];
setUpBar = mkOption { extraOptions = {
type = types.bool; colorscheme = let
default = true; customColorschemeType = types.submodule {
description = "Whether to install the matching plugin for your statusbar. This does nothing as of yet, waiting for upstream support.";
};
customColorScheme =
helpers.mkNullOrOption
(with types;
submodule {
options = options =
listToAttrs listToAttrs
( (
@ -46,18 +47,25 @@ in {
name = "base0" + colorId; name = "base0" + colorId;
value = mkOption { value = mkOption {
type = types.str; type = types.str;
description = "The value for color ${name}."; description = "The value for color `${name}`.";
example = "#16161D"; example = "#16161D";
}; };
} }
) )
["0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F"] ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F"]
); );
}) };
'' in
Optionally, you can provide a table specifying your colors to the setup function. mkOption {
type = with types;
either
(enum (import ./theme-list.nix))
customColorschemeType;
description = ''
The base16 colorscheme to use.
It can either be the name of a builtin colorscheme or an attrs specifying each color explicitly.
Example: Example for the latter:
```nix ```nix
{ {
base00 = "#16161D"; base00 = "#16161D";
@ -79,34 +87,30 @@ in {
} }
``` ```
''; '';
example = "edge-light";
};
setUpBar = mkOption {
type = types.bool;
default = true;
description = "Whether to set your status bar theme to 'base16'.";
}; };
}; };
config = mkIf cfg.enable { extraConfig = cfg:
warnings = optional (cfg.colorscheme != null && cfg.customColorScheme != null) " mkMerge [
You have set both `colorschemes.base16.colorscheme` and `colorschemes.base16.customColorScheme`, `colorscheme` will be preferred.
";
assertions = [
{ {
assertion = cfg.colorscheme != null || cfg.customColorScheme != null;
message = ''
You have enabled `colorschemes.base16` but haven't set a specific color scheme.
Please set a color scheme using `colorschemes.base16.colorscheme` or `colorschemes.base16.customColorScheme`.
'';
}
];
colorscheme = mkIf (cfg.colorscheme != null) "base16-${cfg.colorscheme}";
extraPlugins = [cfg.package];
plugins.airline.settings.theme = mkIf cfg.setUpBar "base16"; plugins.airline.settings.theme = mkIf cfg.setUpBar "base16";
plugins.lualine.theme = mkIf cfg.setUpBar "base16"; plugins.lualine.theme = mkIf cfg.setUpBar "base16";
plugins.lightline.colorscheme = null; plugins.lightline.colorscheme = null;
}
options.termguicolors = mkIf cfg.useTruecolor true; (mkIf (isString cfg.colorscheme) {
colorscheme = "base16-${cfg.colorscheme}";
extraConfigLuaPre = mkIf (cfg.customColorScheme != null) '' })
require('base16-colorscheme').setup(${helpers.toLuaObject cfg.customColorScheme}) (mkIf (isAttrs cfg.colorscheme) {
extraConfigLuaPre = ''
require('base16-colorscheme').setup(${helpers.toLuaObject cfg.colorscheme})
''; '';
}; })
} ];
}

View file

@ -1,15 +1,12 @@
{ {
# No empty test because not setting `colorscheme` and `customColorScheme` would error # No empty test because not setting `colorscheme` would error
# All the upstream default options of poimandres
defaults = { defaults = {
colorschemes.base16 = { colorschemes.base16 = {
enable = true; enable = true;
useTruecolor = true;
colorscheme = "gruvbox-dark-hard"; colorscheme = "gruvbox-dark-hard";
setUpBar = true; setUpBar = true;
customColorScheme = null;
}; };
}; };
@ -17,7 +14,7 @@
colorschemes.base16 = { colorschemes.base16 = {
enable = true; enable = true;
customColorScheme = { colorscheme = {
base00 = "#16161D"; base00 = "#16161D";
base01 = "#2c313c"; base01 = "#2c313c";
base02 = "#3e4451"; base02 = "#3e4451";