From c2cd3cb7a13c0677c49f46d55a8c65b50b7d9431 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Fri, 8 Mar 2024 14:25:07 +0100 Subject: [PATCH] colorschemes/base16: use mkVimPlugin --- plugins/colorschemes/base16/default.nix | 194 +++++++++--------- .../plugins/colorschemes/base16.nix | 7 +- 2 files changed, 101 insertions(+), 100 deletions(-) diff --git a/plugins/colorschemes/base16/default.nix b/plugins/colorschemes/base16/default.nix index 51f59a56..233305a8 100644 --- a/plugins/colorschemes/base16/default.nix +++ b/plugins/colorschemes/base16/default.nix @@ -5,108 +5,112 @@ pkgs, ... }: -with lib; let - cfg = config.colorschemes.base16; - themes = import ./theme-list.nix; -in { - options = { - colorschemes.base16 = { - enable = mkEnableOption "base16"; +with lib; +# We configure this plugin manually (no `settings` option) so there is no point in using +# `mkNeovimPlugin` here. + helpers.vim-plugin.mkVimPlugin config { + name = "base16"; + isColorscheme = true; + originalName = "base16.nvim"; + defaultPackage = pkgs.vimPlugins.base16-nvim; - package = helpers.mkPackageOption "base16" pkgs.vimPlugins.base16-nvim; + maintainers = [maintainers.GaetanLepage]; - useTruecolor = mkOption { - type = types.bool; - default = true; - description = "Whether to use truecolor for the colorschemes. If set to false, you'll need to set up base16 in your shell."; - }; + # We manually set the colorscheme if needed. + colorscheme = null; - colorscheme = mkOption { - type = types.nullOr (types.enum themes); - description = "The base16 colorscheme to use"; - default = null; - }; + # TODO introduced 2024-03-12: remove 2024-05-12 + imports = let + basePluginPath = ["colorschemes" "base16"]; + in [ + ( + mkRenamedOptionModule + (basePluginPath ++ ["customColorScheme"]) + (basePluginPath ++ ["colorscheme"]) + ) + ( + mkRenamedOptionModule + (basePluginPath ++ ["useTruecolor"]) + ["options" "termguicolors"] + ) + ]; + + extraOptions = { + colorscheme = let + customColorschemeType = types.submodule { + options = + listToAttrs + ( + map + ( + colorId: rec { + name = "base0" + colorId; + value = mkOption { + type = types.str; + description = "The value for color `${name}`."; + example = "#16161D"; + }; + } + ) + ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F"] + ); + }; + in + 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 for the latter: + ```nix + { + base00 = "#16161D"; + base01 = "#2c313c"; + base02 = "#3e4451"; + base03 = "#6c7891"; + base04 = "#565c64"; + base05 = "#abb2bf"; + base06 = "#9a9bb3"; + base07 = "#c5c8e6"; + base08 = "#e06c75"; + base09 = "#d19a66"; + base0A = "#e5c07b"; + base0B = "#98c379"; + base0C = "#56b6c2"; + base0D = "#0184bc"; + base0E = "#c678dd"; + base0F = "#a06949"; + } + ``` + ''; + example = "edge-light"; + }; setUpBar = mkOption { type = types.bool; default = true; - description = "Whether to install the matching plugin for your statusbar. This does nothing as of yet, waiting for upstream support."; + description = "Whether to set your status bar theme to 'base16'."; }; - - customColorScheme = - helpers.mkNullOrOption - (with types; - submodule { - options = - listToAttrs - ( - map - ( - colorId: rec { - name = "base0" + colorId; - value = mkOption { - type = types.str; - description = "The value for color ${name}."; - example = "#16161D"; - }; - } - ) - ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F"] - ); - }) - '' - Optionally, you can provide a table specifying your colors to the setup function. - - Example: - ```nix - { - base00 = "#16161D"; - base01 = "#2c313c"; - base02 = "#3e4451"; - base03 = "#6c7891"; - base04 = "#565c64"; - base05 = "#abb2bf"; - base06 = "#9a9bb3"; - base07 = "#c5c8e6"; - base08 = "#e06c75"; - base09 = "#d19a66"; - base0A = "#e5c07b"; - base0B = "#98c379"; - base0C = "#56b6c2"; - base0D = "#0184bc"; - base0E = "#c678dd"; - base0F = "#a06949"; - } - ``` - ''; }; - }; - config = mkIf cfg.enable { - warnings = optional (cfg.colorscheme != null && cfg.customColorScheme != null) " - 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.lualine.theme = mkIf cfg.setUpBar "base16"; - plugins.lightline.colorscheme = null; - - options.termguicolors = mkIf cfg.useTruecolor true; - - extraConfigLuaPre = mkIf (cfg.customColorScheme != null) '' - require('base16-colorscheme').setup(${helpers.toLuaObject cfg.customColorScheme}) - ''; - }; -} + extraConfig = cfg: + mkMerge [ + { + plugins.airline.settings.theme = mkIf cfg.setUpBar "base16"; + plugins.lualine.theme = mkIf cfg.setUpBar "base16"; + plugins.lightline.colorscheme = null; + } + (mkIf (isString cfg.colorscheme) { + colorscheme = "base16-${cfg.colorscheme}"; + }) + (mkIf (isAttrs cfg.colorscheme) { + extraConfigLuaPre = '' + require('base16-colorscheme').setup(${helpers.toLuaObject cfg.colorscheme}) + ''; + }) + ]; + } diff --git a/tests/test-sources/plugins/colorschemes/base16.nix b/tests/test-sources/plugins/colorschemes/base16.nix index ae996df7..9f5c68b4 100644 --- a/tests/test-sources/plugins/colorschemes/base16.nix +++ b/tests/test-sources/plugins/colorschemes/base16.nix @@ -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 = { colorschemes.base16 = { enable = true; - useTruecolor = true; colorscheme = "gruvbox-dark-hard"; setUpBar = true; - customColorScheme = null; }; }; @@ -17,7 +14,7 @@ colorschemes.base16 = { enable = true; - customColorScheme = { + colorscheme = { base00 = "#16161D"; base01 = "#2c313c"; base02 = "#3e4451";