From e80dedd098e76175808f1d95d54f10f3ea5d3502 Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Sun, 29 Sep 2024 23:22:26 +0200 Subject: [PATCH] modules: add base16 Theming support theme/theme.nix: fix formatting supported-themes.nix: formatting clean up base16-colors.nix theme: fix plugin setup, change base16 flake input --- flake.lock | 17 ++++++ flake.nix | 5 ++ lib/types/default.nix | 2 + lib/types/theme.nix | 13 ++++ modules/plugins/theme/base16-colors.nix | 69 ++++++++++++++++++++++ modules/plugins/theme/supported-themes.nix | 10 ++++ modules/plugins/theme/theme.nix | 16 +++-- 7 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 lib/types/theme.nix create mode 100644 modules/plugins/theme/base16-colors.nix diff --git a/flake.lock b/flake.lock index ecc02f27..c7447b47 100644 --- a/flake.lock +++ b/flake.lock @@ -172,6 +172,22 @@ "type": "github" } }, + "plugin-base16": { + "flake": false, + "locked": { + "lastModified": 1716483968, + "narHash": "sha256-GRF/6AobXHamw8TZ3FjL7SI6ulcpwpcohsIuZeCSh2A=", + "owner": "rrethy", + "repo": "base16-nvim", + "rev": "6ac181b5733518040a33017dde654059cd771b7c", + "type": "github" + }, + "original": { + "owner": "rrethy", + "repo": "base16-nvim", + "type": "github" + } + }, "plugin-bufdelete-nvim": { "flake": false, "locked": { @@ -1802,6 +1818,7 @@ "nixpkgs": "nixpkgs", "nmd": "nmd", "plugin-alpha-nvim": "plugin-alpha-nvim", + "plugin-base16": "plugin-base16", "plugin-bufdelete-nvim": "plugin-bufdelete-nvim", "plugin-catppuccin": "plugin-catppuccin", "plugin-ccc": "plugin-ccc", diff --git a/flake.nix b/flake.nix index 987e3e59..c4a1a2a8 100644 --- a/flake.nix +++ b/flake.nix @@ -349,6 +349,11 @@ }; # Themes + plugin-base16 = { + url = "github:rrethy/base16-nvim"; + flake = false; + }; + plugin-tokyonight = { url = "github:folke/tokyonight.nvim"; flake = false; diff --git a/lib/types/default.nix b/lib/types/default.nix index 6751229c..d7ddd240 100644 --- a/lib/types/default.nix +++ b/lib/types/default.nix @@ -7,9 +7,11 @@ typesPlugin = import ./plugins.nix {inherit inputs lib;}; typesLanguage = import ./languages.nix {inherit lib;}; typesCustom = import ./custom.nix {inherit lib;}; + typesTheme = import ./theme.nix {inherit lib;}; in { inherit (typesDag) dagOf; inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType; inherit (typesLanguage) diagnostics mkGrammarOption; inherit (typesCustom) anythingConcatLists char; + inherit (typesTheme) hexColorType; } diff --git a/lib/types/theme.nix b/lib/types/theme.nix new file mode 100644 index 00000000..98c0f0fd --- /dev/null +++ b/lib/types/theme.nix @@ -0,0 +1,13 @@ +{lib}: let + inherit (lib.strings) isString hasPrefix; + inherit (lib.types) mkOptionType; + inherit (builtins) stringLength; + # This was almost entirely taken from raf himself. +in { + hexColorType = mkOptionType { + name = "hex-color"; + descriptionClass = "noun"; + description = "RGB color in hex format"; + check = x: isString x && hasPrefix "#" x && stringLength x == 7; + }; +} diff --git a/modules/plugins/theme/base16-colors.nix b/modules/plugins/theme/base16-colors.nix new file mode 100644 index 00000000..95ff2e82 --- /dev/null +++ b/modules/plugins/theme/base16-colors.nix @@ -0,0 +1,69 @@ +{lib}: let + inherit (lib.options) mkOption; + inherit (lib.nvim.types) hexColorType; +in { + base00 = mkOption { + type = hexColorType; + default = "#1e1e2e"; + }; + base01 = mkOption { + type = hexColorType; + default = "#181825"; + }; + base02 = mkOption { + type = hexColorType; + default = "#313244"; + }; + base03 = mkOption { + type = hexColorType; + default = "#45475a"; + }; + base04 = mkOption { + type = hexColorType; + default = "#585b70"; + }; + base05 = mkOption { + type = hexColorType; + default = "#cdd6f4"; + }; + base06 = mkOption { + type = hexColorType; + default = "#f5e0dc"; + }; + base07 = mkOption { + type = hexColorType; + default = "#b4befe"; + }; + base08 = mkOption { + type = hexColorType; + default = "#f38ba8"; + }; + base09 = mkOption { + type = hexColorType; + default = "#fab387"; + }; + base0A = mkOption { + type = hexColorType; + default = "#a6e3a1"; + }; + base0B = mkOption { + type = hexColorType; + default = "#94e2d5"; + }; + base0C = mkOption { + type = hexColorType; + default = "#a6e3a1"; + }; + base0D = mkOption { + type = hexColorType; + default = "#89b4fa"; + }; + base0E = mkOption { + type = hexColorType; + default = "#cba6f4"; + }; + base0F = mkOption { + type = hexColorType; + default = "#f2cdcd"; + }; +} diff --git a/modules/plugins/theme/supported-themes.nix b/modules/plugins/theme/supported-themes.nix index 63335e41..24f54222 100644 --- a/modules/plugins/theme/supported-themes.nix +++ b/modules/plugins/theme/supported-themes.nix @@ -4,7 +4,15 @@ }: let inherit (lib.strings) optionalString; inherit (lib.trivial) boolToString warnIf; + inherit (lib.nvim.lua) toLuaObject; + cfg = config.vim.theme; in { + base16 = { + setup = {base16-colors, ...}: '' + -- Base-16 theme + require('base16-colorscheme').setup(${toLuaObject cfg.base16-colors}) + ''; + }; onedark = { setup = {style ? "dark", ...}: '' -- OneDark theme @@ -20,6 +28,7 @@ in { setup = { style ? "night", transparent, + ... }: '' require('tokyonight').setup { transparent = ${boolToString transparent}; @@ -42,6 +51,7 @@ in { setup = { style ? "mocha", transparent ? false, + ... }: '' -- Catppuccin theme require('catppuccin').setup { diff --git a/modules/plugins/theme/theme.nix b/modules/plugins/theme/theme.nix index 85f8430f..b0a7a188 100644 --- a/modules/plugins/theme/theme.nix +++ b/modules/plugins/theme/theme.nix @@ -13,13 +13,16 @@ supportedThemes = import ./supported-themes.nix { inherit lib config; }; + base16-colors = import ./base16-colors.nix { + inherit lib; + }; in { options.vim.theme = { enable = mkOption { type = bool; description = "Enable theming"; }; - + inherit base16-colors; name = mkOption { type = enum (attrNames supportedThemes); description = "Supported themes can be found in `supportedThemes.nix`"; @@ -29,7 +32,6 @@ in { type = enum supportedThemes.${cfg.name}.styles; description = "Specific style for theme if it supports it"; }; - transparent = mkOption { type = bool; default = false; @@ -45,10 +47,12 @@ in { config = mkIf cfg.enable { vim = { startPlugins = [cfg.name]; - luaConfigRC.theme = entryBefore ["pluginConfigs"] '' - ${cfg.extraConfig} - ${supportedThemes.${cfg.name}.setup {inherit (cfg) style transparent;}} - ''; + luaConfigRC = { + theme = entryBefore ["pluginConfigs"] '' + ${cfg.extraConfig} + ${supportedThemes.${cfg.name}.setup {inherit (cfg) style transparent base16-colors;}} + ''; + }; }; }; }