From a37625c3b0d9b3f0143955b54cf35587d9d9a7d6 Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Sat, 18 Jan 2025 22:45:57 +0100 Subject: [PATCH] confusion --- flake.lock | 14 ++-- flake.nix | 2 +- modules/plugins/theme/default.nix | 1 + .../plugins/theme/supported-themes/base16.nix | 25 +++++++ .../theme/supported-themes/cattpuccin.nix | 70 +++++++++++++++++++ .../theme/supported-themes/default.nix | 12 ++++ .../theme/supported-themes/dracula.nix | 23 ++++++ .../theme/supported-themes/gruvbox.nix | 65 +++++++++++++++++ .../theme/supported-themes/onedark.nix | 25 +++++++ .../theme/supported-themes/rose-pine.nix | 45 ++++++++++++ .../theme/supported-themes/tokyonight.nix | 24 +++++++ modules/plugins/theme/theme.nix | 45 ++++++------ 12 files changed, 319 insertions(+), 32 deletions(-) create mode 100644 modules/plugins/theme/supported-themes/base16.nix create mode 100644 modules/plugins/theme/supported-themes/cattpuccin.nix create mode 100644 modules/plugins/theme/supported-themes/default.nix create mode 100644 modules/plugins/theme/supported-themes/dracula.nix create mode 100644 modules/plugins/theme/supported-themes/gruvbox.nix create mode 100644 modules/plugins/theme/supported-themes/onedark.nix create mode 100644 modules/plugins/theme/supported-themes/rose-pine.nix create mode 100644 modules/plugins/theme/supported-themes/tokyonight.nix diff --git a/flake.lock b/flake.lock index 918b0ce1..0bf54cb9 100644 --- a/flake.lock +++ b/flake.lock @@ -154,16 +154,16 @@ "plugin-base16": { "flake": false, "locked": { - "lastModified": 1716483968, - "narHash": "sha256-GRF/6AobXHamw8TZ3FjL7SI6ulcpwpcohsIuZeCSh2A=", - "owner": "rrethy", - "repo": "base16-nvim", - "rev": "6ac181b5733518040a33017dde654059cd771b7c", + "lastModified": 1734960100, + "narHash": "sha256-VGs4k/xDujPcA0Nv5T18ybSv1iqnzg0AFmaweRdhvDM=", + "owner": "echasnovski", + "repo": "mini.base16", + "rev": "23453dacc1606e5d42238d82f0b42a2985386b62", "type": "github" }, "original": { - "owner": "rrethy", - "repo": "base16-nvim", + "owner": "echasnovski", + "repo": "mini.base16", "type": "github" } }, diff --git a/flake.nix b/flake.nix index 02ceb667..95a88448 100644 --- a/flake.nix +++ b/flake.nix @@ -380,7 +380,7 @@ # Themes plugin-base16 = { - url = "github:rrethy/base16-nvim"; + url = "github:echasnovski/mini.base16"; flake = false; }; diff --git a/modules/plugins/theme/default.nix b/modules/plugins/theme/default.nix index 3b379287..a316279b 100644 --- a/modules/plugins/theme/default.nix +++ b/modules/plugins/theme/default.nix @@ -2,5 +2,6 @@ imports = [ ./theme.nix ./config.nix + ./supported-themes ]; } diff --git a/modules/plugins/theme/supported-themes/base16.nix b/modules/plugins/theme/supported-themes/base16.nix new file mode 100644 index 00000000..f9227598 --- /dev/null +++ b/modules/plugins/theme/supported-themes/base16.nix @@ -0,0 +1,25 @@ +{lib, ...}: let + inherit (lib.strings) hasPrefix; + inherit (lib.attrsets) listToAttrs; + inherit (lib.options) mkOption; + inherit (lib.nvim.types) hexColor mkPluginSetupOption; + + numbers = ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F"]; + base16Options = listToAttrs (map (n: { + name = "base0${n}"; + value = mkOption { + description = "The base0${n} color to use"; + type = hexColor; + apply = v: + if hasPrefix "#" v + then v + else "#${v}"; + }; + }) + numbers); +in { + base16 = { + setupOpts = mkPluginSetupOption "base16" base16Options; + setup = ""; + }; +} diff --git a/modules/plugins/theme/supported-themes/cattpuccin.nix b/modules/plugins/theme/supported-themes/cattpuccin.nix new file mode 100644 index 00000000..eb42f187 --- /dev/null +++ b/modules/plugins/theme/supported-themes/cattpuccin.nix @@ -0,0 +1,70 @@ +{ + config, + lib, + ... +}: let + inherit (lib.attrsets) genAttrs; + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) bool str; + inherit (lib.nvim.types) mkPluginSetupOption; + cfg = config.vim.theme; + + mkEnableOption' = name: mkEnableOption name // {default = true;}; +in { + catppuccin = { + setupOpts = mkPluginSetupOption "catppuccin" { + flavour = mkOption { + type = str; + default = cfg.style; + # internal = true; + }; + transparent_background = mkOption { + type = bool; + default = cfg.transparent; + internal = true; + }; + term_colors = mkEnableOption' "term_colors"; + integrations = + { + nvimtree = { + enabled = mkEnableOption' "enabled"; + transparent_panel = mkOption { + type = bool; + default = cfg.transparent; + }; + show_root = mkEnableOption' "show_root"; + }; + + navic = { + enabled = mkEnableOption' "enabled"; + # lualine will set backgound to mantle + custom_bg = mkOption { + type = str; + default = "NONE"; + }; + }; + } + // genAttrs [ + "hop" + "gitsigns" + "telescope" + "treesitter" + "treesitter_context" + "ts_rainbow" + "fidget" + "alpha" + "leap" + "markdown" + "noice" + "notify" + "which_key" + ] (name: mkEnableOption' name); + }; + setup = '' + -- Catppuccin theme + -- setup must be called before loading + vim.cmd.colorscheme "catppuccin" + ''; + styles = ["mocha" "latte" "frappe" "macchiato"]; + }; +} diff --git a/modules/plugins/theme/supported-themes/default.nix b/modules/plugins/theme/supported-themes/default.nix new file mode 100644 index 00000000..b9d4d1fc --- /dev/null +++ b/modules/plugins/theme/supported-themes/default.nix @@ -0,0 +1,12 @@ +_: { + imports = [ + ./base16.nix + ./cattpuccin.nix + ./dracula.nix + ./dracula.nix + ./gruvbox.nix + ./onedark.nix + ./rose-pine.nix + ./tokyonight.nix + ]; +} diff --git a/modules/plugins/theme/supported-themes/dracula.nix b/modules/plugins/theme/supported-themes/dracula.nix new file mode 100644 index 00000000..4590857b --- /dev/null +++ b/modules/plugins/theme/supported-themes/dracula.nix @@ -0,0 +1,23 @@ +{ + config, + lib, + ... +}: let + inherit (lib.options) mkOption; + inherit (lib.types) bool; + inherit (lib.nvim.types) mkPluginSetupOption; + cfg = config.vim.theme; +in { + dracula = { + setupOpts = mkPluginSetupOption "dracula" { + transparent_bg = mkOption { + type = bool; + default = cfg.transparent; + internal = true; + }; + }; + setup = '' + require('dracula').load(); + ''; + }; +} diff --git a/modules/plugins/theme/supported-themes/gruvbox.nix b/modules/plugins/theme/supported-themes/gruvbox.nix new file mode 100644 index 00000000..6b801a98 --- /dev/null +++ b/modules/plugins/theme/supported-themes/gruvbox.nix @@ -0,0 +1,65 @@ +{ + config, + lib, + ... +}: let + inherit (lib.attrsets) genAttrs mergeAttrsList; + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) bool str; + inherit (lib.nvim.types) mkPluginSetupOption; + cfg = config.vim.theme; + + mkEnableOption' = name: mkEnableOption name // {default = true;}; +in { + gruvbox = { + setupOpts = + mkPluginSetupOption "gruvbox" { + transparent_mode = mkOption { + type = bool; + default = cfg.transparent; + internal = true; + }; + italic = + { + operators = mkEnableOption "operators"; + } + // genAttrs [ + "strings" + "emphasis" + "comments" + "folds" + ] (name: mkEnableOption' name); + + contrast = mkOption { + type = str; + default = ""; + }; + # TODO: fix these + # palette_overrides = mkLuaInline "{}"; + # overrides = mkLuaInline "{}"; + } + // mergeAttrsList [ + (genAttrs [ + "terminal_colors" + "undercurls" + "underline" + "bold" + "strikethrough" + "inverse" + ] (name: mkEnableOption' name)) + (genAttrs [ + "invert_selection" + "invert_signs" + "invert_tabline" + "invert_intend_guides" + "dim_inactive" + ] (name: mkEnableOption name)) + ]; + setup = '' + -- Gruvbox theme + vim.o.background = "${cfg.style}" + vim.cmd("colorscheme gruvbox") + ''; + styles = ["dark" "light"]; + }; +} diff --git a/modules/plugins/theme/supported-themes/onedark.nix b/modules/plugins/theme/supported-themes/onedark.nix new file mode 100644 index 00000000..ba4c6fd2 --- /dev/null +++ b/modules/plugins/theme/supported-themes/onedark.nix @@ -0,0 +1,25 @@ +{ + config, + lib, + ... +}: let + inherit (lib.options) mkOption; + inherit (lib.types) str; + inherit (lib.nvim.types) mkPluginSetupOption; + cfg = config.vim.theme; +in { + onedark = { + setupOpts = mkPluginSetupOption "onedark" { + style = mkOption { + type = str; + default = cfg.style; + internal = true; + }; + }; + setup = '' + -- OneDark theme + require('onedark').load() + ''; + styles = ["dark" "darker" "cool" "deep" "warm" "warmer"]; + }; +} diff --git a/modules/plugins/theme/supported-themes/rose-pine.nix b/modules/plugins/theme/supported-themes/rose-pine.nix new file mode 100644 index 00000000..217609ea --- /dev/null +++ b/modules/plugins/theme/supported-themes/rose-pine.nix @@ -0,0 +1,45 @@ +{ + config, + lib, + ... +}: let + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) bool str; + inherit (lib.nvim.types) mkPluginSetupOption; + cfg = config.vim.theme; + + mkEnableOption' = name: mkEnableOption name // {default = true;}; +in { + rose-pine = { + setupOpts = mkPluginSetupOption "rose-pine" { + dark_variant = mkOption { + type = str; + default = cfg.style; + internal = true; + }; + dim_inactive_windows = mkEnableOption "dim_inactive_windows"; + extend_background_behind_borders = mkEnableOption' "extend_background_behind_borders"; + + enable = { + terminal = mkEnableOption' "terminal"; + migrations = mkEnableOption' "migrations"; + }; + + styles = { + bold = mkEnableOption "bold"; + # I would like to add more options for this + italic = mkEnableOption "italic"; + transparency = mkOption { + type = bool; + default = cfg.transparent; + internal = true; + }; + }; + }; + + setup = '' + vim.cmd("colorscheme rose-pine") + ''; + styles = ["main" "moon" "dawn"]; + }; +} diff --git a/modules/plugins/theme/supported-themes/tokyonight.nix b/modules/plugins/theme/supported-themes/tokyonight.nix new file mode 100644 index 00000000..993d033a --- /dev/null +++ b/modules/plugins/theme/supported-themes/tokyonight.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + ... +}: let + inherit (lib.options) mkOption; + inherit (lib.types) bool; + inherit (lib.nvim.types) mkPluginSetupOption; + cfg = config.vim.theme; +in { + tokyonight = { + setupOpts = mkPluginSetupOption "tokyonight" { + transparent = mkOption { + type = bool; + default = cfg.transparent; + internal = true; + }; + }; + setup = '' + vim.cmd[[colorscheme tokyonight-${cfg.style}]] + ''; + styles = ["night" "day" "storm" "moon"]; + }; +} diff --git a/modules/plugins/theme/theme.nix b/modules/plugins/theme/theme.nix index b3147c00..f6fa4c51 100644 --- a/modules/plugins/theme/theme.nix +++ b/modules/plugins/theme/theme.nix @@ -5,34 +5,20 @@ }: let inherit (lib.options) mkOption; inherit (lib.attrsets) attrNames; - inherit (lib.strings) hasPrefix; + inherit (lib.strings) elemAt; inherit (lib.types) bool lines enum; inherit (lib.modules) mkIf; - inherit (lib.nvim.attrsets) mapListToAttrs; inherit (lib.nvim.dag) entryBefore; - inherit (lib.nvim.types) hexColor; + inherit (lib.nvim.lua) toLuaObject; cfg = config.vim.theme; supportedThemes = import ./supported-themes.nix { inherit lib config; }; - - numbers = ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F"]; - base16Options = - mapListToAttrs (n: { - name = "base0${n}"; - value = mkOption { - description = "The base0${n} color to use"; - type = hexColor; - apply = v: - if hasPrefix "#" v - then v - else "#${v}"; - }; - }) - numbers; in { options.vim.theme = { + inherit (supportedThemes.${cfg.name}) setupOpts; + enable = mkOption { type = bool; description = "Enable theming"; @@ -45,10 +31,9 @@ in { requires all of the colors in {option}`vim.theme.base16-colors` to be set. ''; }; - base16-colors = base16Options; - style = mkOption { type = enum supportedThemes.${cfg.name}.styles; + default = elemAt supportedThemes.${cfg.name}.styles 0; description = "Specific style for theme if it supports it"; }; transparent = mkOption { @@ -64,11 +49,23 @@ in { }; config = mkIf cfg.enable { - vim = { + vim = let + name' = + if cfg.name == "base16" + then "mini.base16" + else cfg.name; + in { startPlugins = [cfg.name]; - luaConfigRC.theme = entryBefore ["pluginConfigs" "lazyConfigs"] '' - ${cfg.extraConfig} - ${supportedThemes.${cfg.name}.setup {inherit (cfg) style transparent base16-colors;}} + luaConfigRC.theme = entryBefore ["pluginConfigs"] '' + ${cfg.extraConfig} + + ${ + if name' != "oxocarbon" + then "require('${name'}').setup(${toLuaObject cfg.setupOpts})" + else "" + } + + ${supportedThemes.${cfg.name}.setup} ''; }; };