From b41163959b1d01ccf0329c2c3585eff8f10db6be Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Mon, 7 Oct 2024 00:02:51 +0200 Subject: [PATCH 01/10] theme/supported-themes.nix: switch to setupOpts --- modules/plugins/theme/supported-themes.nix | 212 ++++++++++----------- 1 file changed, 98 insertions(+), 114 deletions(-) diff --git a/modules/plugins/theme/supported-themes.nix b/modules/plugins/theme/supported-themes.nix index ca539b1d..3ae26d3e 100644 --- a/modules/plugins/theme/supported-themes.nix +++ b/modules/plugins/theme/supported-themes.nix @@ -3,86 +3,79 @@ lib, }: let inherit (lib.strings) optionalString; - inherit (lib.trivial) boolToString warnIf; - inherit (lib.nvim.lua) toLuaObject; + inherit (lib.modules) mkDefault; + cfg = config.vim.theme; in { base16 = { - setup = {base16-colors, ...}: '' - -- Base16 theme - require('base16-colorscheme').setup(${toLuaObject base16-colors}) - ''; + setupOpts = { + inherit (cfg) base16-colors; + }; }; onedark = { - setup = {style ? "dark", ...}: '' + setupOpts = { + style = cfg.style ? "dark"; + }; + setup = _: '' -- OneDark theme - require('onedark').setup { - style = "${style}" - } - require('onedark').load() + require('onedark').load() ''; styles = ["dark" "darker" "cool" "deep" "warm" "warmer"]; }; tokyonight = { - setup = { - style ? "night", - transparent, - ... - }: '' - require('tokyonight').setup { - transparent = ${boolToString transparent}; - } + setupOpts = { + inherit (cfg) transparent; + }; + setup = {style ? "night", ...}: '' vim.cmd[[colorscheme tokyonight-${style}]] ''; styles = ["day" "night" "storm" "moon"]; }; dracula = { - setup = {transparent, ...}: '' - require('dracula').setup({ - transparent_bg = ${boolToString transparent}, - }); + setupOpts = { + transparent_bg = cfg.transparent; + }; + setup = _: '' require('dracula').load(); ''; }; catppuccin = { - setup = { - style ? "mocha", - transparent ? false, - ... - }: '' - -- Catppuccin theme - require('catppuccin').setup { - flavour = "${style}", - transparent_background = ${boolToString transparent}, - term_colors = true, - integrations = { - nvimtree = { - enabled = true, - transparent_panel = ${boolToString transparent}, - show_root = true, - }, + setupOpts = { + flavour = cfg.style ? "mocha"; + transparent_background = cfg.transparent; + term_colors = mkDefault true; + integrations = { + nvimtree = { + enabled = mkDefault true; + transparent_panel = cfg.transparent; + show_root = mkDefault true; + }; - hop = true, - gitsigns = true, - telescope = true, - treesitter = true, - treesitter_context = true, - ts_rainbow = true, - fidget = true, - alpha = true, - leap = true, - markdown = true, - noice = true, - notify = true, -- nvim-notify - which_key = true, - navic = { - enabled = true, - custom_bg = "NONE", -- "lualine" will set background to mantle - }, - }, - } + hop = mkDefault true; + gitsigns = mkDefault true; + telescope = mkDefault true; + treesitter = mkDefault true; + treesitter_context = mkDefault true; + ts_rainbow = mkDefault true; + fidget = mkDefault true; + alpha = mkDefault true; + leap = mkDefault true; + markdown = mkDefault true; + noice = mkDefault true; + # nvim-notify + notify = mkDefault true; + which_key = mkDefault true; + navic = { + enabled = mkDefault true; + # lualine will set backgound to mantle + custom_bg = "NONE"; + }; + }; + }; + setup = _: '' + -- Catppuccin theme -- setup must be called before loading vim.cmd.colorscheme "catppuccin" ''; @@ -90,17 +83,12 @@ in { }; oxocarbon = { - setup = { - style ? "dark", - transparent ? false, - }: let - style' = - warnIf (style == "light") "oxocarbon: light theme is not well-supported" style; - in '' + setupOpts = {}; + setup = _: '' require('oxocarbon') - vim.opt.background = "${style'}" + vim.opt.background = "${cfg.style ? "dark"}" vim.cmd.colorscheme = "oxocarbon" - ${optionalString transparent '' + ${optionalString cfg.transparent '' vim.api.nvim_set_hl(0, "Normal", { bg = "none" }) vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" }) vim.api.nvim_set_hl(0, "LineNr", { bg = "none" }) @@ -114,62 +102,58 @@ in { }; gruvbox = { - setup = { - style ? "dark", - transparent ? false, - }: '' + setupOpts = { + transparent_mode = cfg.transparent; + # add neovim terminal colors + terminal_colors = mkDefault true; + undercurl = mkDefault true; + underline = mkDefault true; + bold = mkDefault true; + italic = { + strings = mkDefault true; + emphasis = mkDefault true; + comments = mkDefault true; + operators = mkDefault false; + folds = mkDefault true; + }; + strikethrough = mkDefault true; + invert_selection = mkDefault false; + invert_signs = mkDefault false; + invert_tabline = mkDefault false; + invert_intend_guides = mkDefault false; + inverse = mkDefault true; + contrast = ""; + palette_overrides = {}; + overrides = {}; + dim_inactive = mkDefault false; + }; + setup = _: '' -- Gruvbox theme - require("gruvbox").setup({ - terminal_colors = true, -- add neovim terminal colors - undercurl = true, - underline = true, - bold = true, - italic = { - strings = true, - emphasis = true, - comments = true, - operators = false, - folds = true, - }, - strikethrough = true, - invert_selection = false, - invert_signs = false, - invert_tabline = false, - invert_intend_guides = false, - inverse = true, - contrast = "", - palette_overrides = {}, - overrides = {}, - dim_inactive = false, - transparent_mode = ${boolToString transparent}, - }) - vim.o.background = "${style}" + vim.o.background = "${cfg.style ? "dark"}" vim.cmd("colorscheme gruvbox") ''; styles = ["dark" "light"]; }; rose-pine = { - setup = { - style ? "main", - transparent ? false, - }: '' - require("rose-pine").setup({ - dark_variant = "${style}", -- main, moon, or dawn - dim_inactive_windows = false, - extend_background_behind_borders = true, + setupOpts = { + dark_variant = cfg.style ? "main"; + dim_inactive_windows = mkDefault false; + extend_background_behind_borders = mkDefault true; - enable = { - terminal = true, - migrations = true, - }, + enable = { + terminal = mkDefault true; + migrations = mkDefault true; + }; - styles = { - bold = false, - italic = false, -- I would like to add more options for this - transparency = ${boolToString transparent}, - }, - }) + styles = { + bold = mkDefault false; + # I would like to add more options for this + italic = mkDefault false; + transparency = cfg.transparent; + }; + }; + setup = _: '' vim.cmd("colorscheme rose-pine") ''; styles = ["main" "moon" "dawn"]; From ba1c3645ee32f323d0310795ed1fba0d805c9b30 Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Mon, 7 Oct 2024 00:16:22 +0200 Subject: [PATCH 02/10] theme/supported-themes.nix: switch to setupOpts --- modules/plugins/theme/supported-themes.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/plugins/theme/supported-themes.nix b/modules/plugins/theme/supported-themes.nix index 3ae26d3e..71fe984d 100644 --- a/modules/plugins/theme/supported-themes.nix +++ b/modules/plugins/theme/supported-themes.nix @@ -26,8 +26,8 @@ in { setupOpts = { inherit (cfg) transparent; }; - setup = {style ? "night", ...}: '' - vim.cmd[[colorscheme tokyonight-${style}]] + setup = _: '' + vim.cmd[[colorscheme tokyonight-${cfg.style ? "night"}]] ''; styles = ["day" "night" "storm" "moon"]; }; From b66ee19ff3e2425f75ab9157f51b95c33ab8aa2c Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Mon, 7 Oct 2024 01:22:41 +0200 Subject: [PATCH 03/10] theme: finish switching to setupOpts, not building --- modules/plugins/theme/supported-themes.nix | 168 +++++++++++++-------- modules/plugins/theme/theme.nix | 17 ++- 2 files changed, 116 insertions(+), 69 deletions(-) diff --git a/modules/plugins/theme/supported-themes.nix b/modules/plugins/theme/supported-themes.nix index 71fe984d..a0661130 100644 --- a/modules/plugins/theme/supported-themes.nix +++ b/modules/plugins/theme/supported-themes.nix @@ -3,19 +3,28 @@ lib, }: let inherit (lib.strings) optionalString; - inherit (lib.modules) mkDefault; + 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;}; + # mkEnableOption' = name: mkEnableOption name; in { base16 = { - setupOpts = { + setupOpts = mkPluginSetupOption "base16" { inherit (cfg) base16-colors; }; }; onedark = { - setupOpts = { - style = cfg.style ? "dark"; + setupOpts = mkPluginSetupOption "onedark" { + style = mkOption { + type = str; + default = "dark"; + internal = true; + }; }; - setup = _: '' + setup = '' -- OneDark theme require('onedark').load() ''; @@ -23,54 +32,77 @@ in { }; tokyonight = { - setupOpts = { - inherit (cfg) transparent; + setupOpts = mkPluginSetupOption "tokyonight" { + transparent = mkOption { + type = bool; + default = cfg.transparent; + internal = true; + }; }; - setup = _: '' + setup = '' vim.cmd[[colorscheme tokyonight-${cfg.style ? "night"}]] ''; styles = ["day" "night" "storm" "moon"]; }; dracula = { - setupOpts = { - transparent_bg = cfg.transparent; + setupOpts = mkPluginSetupOption "dracula" { + transparent_bg = mkOption { + type = bool; + default = cfg.transparent; + internal = true; + }; }; - setup = _: '' + setup = '' require('dracula').load(); ''; }; catppuccin = { - setupOpts = { - flavour = cfg.style ? "mocha"; - transparent_background = cfg.transparent; - term_colors = mkDefault true; + setupOpts = mkPluginSetupOption "catppuccin" { + # flavour = cfg.style ? "mocha"; + flavour = mkOption { + type = str; + default = cfg.style ? "mocha"; + internal = true; + }; + transparent_background = mkOption { + type = bool; + default = cfg.transparency; + internal = true; + }; + term_colors = mkEnableOption' "term_colors"; integrations = { nvimtree = { - enabled = mkDefault true; - transparent_panel = cfg.transparent; - show_root = mkDefault true; + enabled = mkEnableOption' "enabled"; + transparent_panel = mkOption { + type = bool; + default = cfg.transparency; + }; + show_root = mkEnableOption' "show_root"; }; - hop = mkDefault true; - gitsigns = mkDefault true; - telescope = mkDefault true; - treesitter = mkDefault true; - treesitter_context = mkDefault true; - ts_rainbow = mkDefault true; - fidget = mkDefault true; - alpha = mkDefault true; - leap = mkDefault true; - markdown = mkDefault true; - noice = mkDefault true; + hop = mkEnableOption' "hop"; + gitsigns = mkEnableOption' "gitsigns"; + telescope = mkEnableOption' "telescope"; + treesitter = mkEnableOption' "treesitter"; + treesitter_context = mkEnableOption' "treesitter_context"; + ts_rainbow = mkEnableOption' "ts_rainbow"; + fidget = mkEnableOption' "fidget"; + alpha = mkEnableOption' "alpha"; + leap = mkEnableOption' "leap"; + markdown = mkEnableOption' "markdown"; + noice = mkEnableOption' "noice"; # nvim-notify - notify = mkDefault true; - which_key = mkDefault true; - navic = { - enabled = mkDefault true; + notify = mkEnableOption' "notify"; + which_key = mkEnableOption' "which_key"; + navic = mkOption { + enabled = mkEnableOption' "enabled"; # lualine will set backgound to mantle - custom_bg = "NONE"; + custom_bg = mkOption { + type = str; + default = "NONE"; + }; }; }; }; @@ -83,8 +115,8 @@ in { }; oxocarbon = { - setupOpts = {}; - setup = _: '' + setupOpts = mkPluginSetupOption "oxocarbon" {}; + setup = '' require('oxocarbon') vim.opt.background = "${cfg.style ? "dark"}" vim.cmd.colorscheme = "oxocarbon" @@ -102,32 +134,32 @@ in { }; gruvbox = { - setupOpts = { + setupOpts = mkPluginSetupOption "gruvbox" { transparent_mode = cfg.transparent; # add neovim terminal colors - terminal_colors = mkDefault true; - undercurl = mkDefault true; - underline = mkDefault true; - bold = mkDefault true; + terminal_colors = mkEnableOption' "terminal_colors"; + undercurl = mkEnableOption' "undercurls"; + underline = mkEnableOption' "underline"; + bold = mkEnableOption' "bold"; italic = { - strings = mkDefault true; - emphasis = mkDefault true; - comments = mkDefault true; - operators = mkDefault false; - folds = mkDefault true; + strings = mkEnableOption' "strings"; + emphasis = mkEnableOption' "emphasis"; + comments = mkEnableOption' "comments"; + operators = mkEnableOption "operators"; + folds = mkEnableOption' "folds"; }; - strikethrough = mkDefault true; - invert_selection = mkDefault false; - invert_signs = mkDefault false; - invert_tabline = mkDefault false; - invert_intend_guides = mkDefault false; - inverse = mkDefault true; + strikethrough = mkEnableOption' "strikethrough"; + invert_selection = mkEnableOption "invert_selection"; + invert_signs = mkEnableOption "invert_signs"; + invert_tabline = mkEnableOption "invert_tabline"; + invert_intend_guides = mkEnableOption "invert_intend_guides"; + inverse = mkEnableOption' "inverse"; contrast = ""; palette_overrides = {}; overrides = {}; - dim_inactive = mkDefault false; + dim_inactive = mkEnableOption "dim_inactive"; }; - setup = _: '' + setup = '' -- Gruvbox theme vim.o.background = "${cfg.style ? "dark"}" vim.cmd("colorscheme gruvbox") @@ -135,25 +167,33 @@ in { styles = ["dark" "light"]; }; rose-pine = { - setupOpts = { - dark_variant = cfg.style ? "main"; - dim_inactive_windows = mkDefault false; - extend_background_behind_borders = mkDefault true; + setupOpts = mkPluginSetupOption "rose-pine" { + dark_variant = mkOption { + type = str; + style = cfg.style ? "main"; + internal = true; + }; + dim_inactive_windows = mkEnableOption "dim_inactive_windows"; + extend_background_behind_borders = mkEnableOption' "extend_background_behind_borders"; enable = { - terminal = mkDefault true; - migrations = mkDefault true; + terminal = mkEnableOption' "terminal"; + migrations = mkEnableOption' "migrations"; }; styles = { - bold = mkDefault false; + bold = mkEnableOption "bold"; # I would like to add more options for this - italic = mkDefault false; - transparency = cfg.transparent; + italic = mkEnableOption "italic"; + transparency = mkOption { + type = bool; + default = cfg.transparent; + internal = true; + }; }; }; - setup = _: '' + setup = '' vim.cmd("colorscheme rose-pine") ''; styles = ["main" "moon" "dawn"]; diff --git a/modules/plugins/theme/theme.nix b/modules/plugins/theme/theme.nix index 95d15d40..8fa5a292 100644 --- a/modules/plugins/theme/theme.nix +++ b/modules/plugins/theme/theme.nix @@ -10,12 +10,11 @@ inherit (lib.modules) mkIf; 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 = listToAttrs (map (n: { name = "base0${n}"; @@ -62,11 +61,19 @@ in { }; config = mkIf cfg.enable { - vim = { + vim = let + name' = + if cfg.name == "base16" + then "base16-colorscheme" + else cfg.name; + in { startPlugins = [cfg.name]; luaConfigRC.theme = entryBefore ["pluginConfigs"] '' - ${cfg.extraConfig} - ${supportedThemes.${cfg.name}.setup {inherit (cfg) style transparent base16-colors;}} + ${cfg.extraConfig} + + require(${name'}).setup(${toLuaObject supportedThemes.${cfg.name}.setupOpts}) + + ${supportedThemes.${cfg.name}.setup} ''; }; }; From 59b8335a263d47bc48fe40414111c86b29f98d6d Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Mon, 7 Oct 2024 10:47:17 +0200 Subject: [PATCH 04/10] more progress --- modules/plugins/theme/supported-themes.nix | 65 ++++++++++++++-------- modules/plugins/theme/theme.nix | 6 +- 2 files changed, 46 insertions(+), 25 deletions(-) diff --git a/modules/plugins/theme/supported-themes.nix b/modules/plugins/theme/supported-themes.nix index a0661130..6560caa5 100644 --- a/modules/plugins/theme/supported-themes.nix +++ b/modules/plugins/theme/supported-themes.nix @@ -3,24 +3,35 @@ lib, }: let inherit (lib.strings) optionalString; + inherit (lib.attrsets) listToAttrs; inherit (lib.options) mkOption mkEnableOption; inherit (lib.types) bool str; - inherit (lib.nvim.types) mkPluginSetupOption; + inherit (lib.nvim.types) hexColor mkPluginSetupOption; cfg = config.vim.theme; mkEnableOption' = name: mkEnableOption name // {default = true;}; - # mkEnableOption' = name: mkEnableOption name; + + 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; + default = cfg.base16-colors."base0${n}"; + }; + }) + numbers); in { base16 = { - setupOpts = mkPluginSetupOption "base16" { - inherit (cfg) base16-colors; - }; + setupOpts = mkPluginSetupOption "base16" base16Options; + setup = ""; }; + onedark = { setupOpts = mkPluginSetupOption "onedark" { style = mkOption { type = str; - default = "dark"; + default = cfg.style; internal = true; }; }; @@ -40,9 +51,9 @@ in { }; }; setup = '' - vim.cmd[[colorscheme tokyonight-${cfg.style ? "night"}]] + vim.cmd[[colorscheme tokyonight-${cfg.style}]] ''; - styles = ["day" "night" "storm" "moon"]; + styles = ["night" "day" "storm" "moon"]; }; dracula = { @@ -60,15 +71,14 @@ in { catppuccin = { setupOpts = mkPluginSetupOption "catppuccin" { - # flavour = cfg.style ? "mocha"; flavour = mkOption { type = str; - default = cfg.style ? "mocha"; - internal = true; + default = cfg.style; + # internal = true; }; transparent_background = mkOption { type = bool; - default = cfg.transparency; + default = cfg.transparent; internal = true; }; term_colors = mkEnableOption' "term_colors"; @@ -77,7 +87,7 @@ in { enabled = mkEnableOption' "enabled"; transparent_panel = mkOption { type = bool; - default = cfg.transparency; + default = cfg.transparent; }; show_root = mkEnableOption' "show_root"; }; @@ -96,7 +106,7 @@ in { # nvim-notify notify = mkEnableOption' "notify"; which_key = mkEnableOption' "which_key"; - navic = mkOption { + navic = { enabled = mkEnableOption' "enabled"; # lualine will set backgound to mantle custom_bg = mkOption { @@ -106,19 +116,19 @@ in { }; }; }; - setup = _: '' + setup = '' -- Catppuccin theme -- setup must be called before loading vim.cmd.colorscheme "catppuccin" ''; - styles = ["latte" "frappe" "macchiato" "mocha"]; + styles = ["mocha" "latte" "frappe" "macchiato"]; }; oxocarbon = { setupOpts = mkPluginSetupOption "oxocarbon" {}; setup = '' require('oxocarbon') - vim.opt.background = "${cfg.style ? "dark"}" + vim.opt.background = "${cfg.style}" vim.cmd.colorscheme = "oxocarbon" ${optionalString cfg.transparent '' vim.api.nvim_set_hl(0, "Normal", { bg = "none" }) @@ -135,7 +145,12 @@ in { gruvbox = { setupOpts = mkPluginSetupOption "gruvbox" { - transparent_mode = cfg.transparent; + transparent_mode = mkOption { + type = bool; + default = cfg.transparent; + internal = true; + }; + # transparent_mode = cfg.transparent; # add neovim terminal colors terminal_colors = mkEnableOption' "terminal_colors"; undercurl = mkEnableOption' "undercurls"; @@ -154,14 +169,18 @@ in { invert_tabline = mkEnableOption "invert_tabline"; invert_intend_guides = mkEnableOption "invert_intend_guides"; inverse = mkEnableOption' "inverse"; - contrast = ""; - palette_overrides = {}; - overrides = {}; + contrast = mkOption { + type = str; + default = ""; + }; + # TODO: fix these + # palette_overrides = mkOption{}; + # overrides = {}; dim_inactive = mkEnableOption "dim_inactive"; }; setup = '' -- Gruvbox theme - vim.o.background = "${cfg.style ? "dark"}" + vim.o.background = "${cfg.style}" vim.cmd("colorscheme gruvbox") ''; styles = ["dark" "light"]; @@ -170,7 +189,7 @@ in { setupOpts = mkPluginSetupOption "rose-pine" { dark_variant = mkOption { type = str; - style = cfg.style ? "main"; + default = cfg.style; internal = true; }; dim_inactive_windows = mkEnableOption "dim_inactive_windows"; diff --git a/modules/plugins/theme/theme.nix b/modules/plugins/theme/theme.nix index 8fa5a292..d14e77eb 100644 --- a/modules/plugins/theme/theme.nix +++ b/modules/plugins/theme/theme.nix @@ -5,7 +5,7 @@ }: let inherit (lib.options) mkOption; inherit (lib.attrsets) attrNames listToAttrs; - inherit (lib.strings) hasPrefix; + inherit (lib.strings) elemAt hasPrefix; inherit (lib.types) bool lines enum; inherit (lib.modules) mkIf; inherit (lib.nvim.dag) entryBefore; @@ -42,10 +42,12 @@ in { requires all of the colors in {option}`vim.theme.base16-colors` to be set. ''; }; + themes = supportedThemes; 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 { @@ -71,7 +73,7 @@ in { luaConfigRC.theme = entryBefore ["pluginConfigs"] '' ${cfg.extraConfig} - require(${name'}).setup(${toLuaObject supportedThemes.${cfg.name}.setupOpts}) + require('${name'}').setup(${toLuaObject cfg.themes.${cfg.name}.setupOpts}) ${supportedThemes.${cfg.name}.setup} ''; From c177916790882fab48db01e2c809f359dffd5b71 Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Mon, 7 Oct 2024 17:47:08 +0200 Subject: [PATCH 05/10] more changes --- modules/plugins/theme/supported-themes.nix | 14 +++++++++----- modules/plugins/theme/theme.nix | 20 +++----------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/modules/plugins/theme/supported-themes.nix b/modules/plugins/theme/supported-themes.nix index 6560caa5..e2f37835 100644 --- a/modules/plugins/theme/supported-themes.nix +++ b/modules/plugins/theme/supported-themes.nix @@ -2,9 +2,10 @@ config, lib, }: let - inherit (lib.strings) optionalString; + inherit (lib.strings) hasPrefix optionalString; inherit (lib.attrsets) listToAttrs; inherit (lib.options) mkOption mkEnableOption; + inherit (lib.generators) mkLuaInline; inherit (lib.types) bool str; inherit (lib.nvim.types) hexColor mkPluginSetupOption; cfg = config.vim.theme; @@ -17,7 +18,10 @@ value = mkOption { description = "The base0${n} color to use"; type = hexColor; - default = cfg.base16-colors."base0${n}"; + apply = v: + if hasPrefix "#" v + then v + else "#${v}"; }; }) numbers); @@ -37,7 +41,7 @@ in { }; setup = '' -- OneDark theme - require('onedark').load() + require('onedark').load() ''; styles = ["dark" "darker" "cool" "deep" "warm" "warmer"]; }; @@ -174,8 +178,8 @@ in { default = ""; }; # TODO: fix these - # palette_overrides = mkOption{}; - # overrides = {}; + palette_overrides = mkLuaInline "{}"; + overrides = mkLuaInline "{}"; dim_inactive = mkEnableOption "dim_inactive"; }; setup = '' diff --git a/modules/plugins/theme/theme.nix b/modules/plugins/theme/theme.nix index d14e77eb..06da3a1b 100644 --- a/modules/plugins/theme/theme.nix +++ b/modules/plugins/theme/theme.nix @@ -4,30 +4,16 @@ ... }: let inherit (lib.options) mkOption; - inherit (lib.attrsets) attrNames listToAttrs; - inherit (lib.strings) elemAt hasPrefix; + inherit (lib.attrsets) attrNames; + inherit (lib.strings) elemAt; inherit (lib.types) bool lines enum; inherit (lib.modules) mkIf; 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 = 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 { options.vim.theme = { enable = mkOption { @@ -42,8 +28,8 @@ in { requires all of the colors in {option}`vim.theme.base16-colors` to be set. ''; }; + setupOpts = cfg.themes.${cfg.name}.setupOpts; themes = supportedThemes; - base16-colors = base16Options; style = mkOption { type = enum supportedThemes.${cfg.name}.styles; From 0fa8fbdf6fbbc8ff7e5de2ce0d437a488502824b Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Mon, 7 Oct 2024 22:24:04 +0200 Subject: [PATCH 06/10] theming: works now!!! --- modules/plugins/theme/config.nix | 2 +- modules/plugins/theme/supported-themes.nix | 1 - modules/plugins/theme/theme.nix | 9 +++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/plugins/theme/config.nix b/modules/plugins/theme/config.nix index f6544b33..6c414a05 100644 --- a/modules/plugins/theme/config.nix +++ b/modules/plugins/theme/config.nix @@ -5,7 +5,7 @@ in { vim.theme = { enable = mkDefault false; name = mkDefault "onedark"; - style = mkDefault "darker"; + # style = mkDefault "darker"; transparent = mkDefault false; extraConfig = mkDefault ""; }; diff --git a/modules/plugins/theme/supported-themes.nix b/modules/plugins/theme/supported-themes.nix index e2f37835..2e2dbce8 100644 --- a/modules/plugins/theme/supported-themes.nix +++ b/modules/plugins/theme/supported-themes.nix @@ -11,7 +11,6 @@ cfg = config.vim.theme; mkEnableOption' = name: mkEnableOption name // {default = true;}; - numbers = ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F"]; base16Options = listToAttrs (map (n: { name = "base0${n}"; diff --git a/modules/plugins/theme/theme.nix b/modules/plugins/theme/theme.nix index 06da3a1b..373d20d3 100644 --- a/modules/plugins/theme/theme.nix +++ b/modules/plugins/theme/theme.nix @@ -10,12 +10,16 @@ inherit (lib.modules) mkIf; inherit (lib.nvim.dag) entryBefore; inherit (lib.nvim.lua) toLuaObject; + cfg = config.vim.theme; supportedThemes = import ./supported-themes.nix { inherit lib config; }; in { options.vim.theme = { + themes = supportedThemes; + inherit (supportedThemes.${cfg.name}) setupOpts; + enable = mkOption { type = bool; description = "Enable theming"; @@ -28,9 +32,6 @@ in { requires all of the colors in {option}`vim.theme.base16-colors` to be set. ''; }; - setupOpts = cfg.themes.${cfg.name}.setupOpts; - themes = supportedThemes; - style = mkOption { type = enum supportedThemes.${cfg.name}.styles; default = elemAt supportedThemes.${cfg.name}.styles 0; @@ -59,7 +60,7 @@ in { luaConfigRC.theme = entryBefore ["pluginConfigs"] '' ${cfg.extraConfig} - require('${name'}').setup(${toLuaObject cfg.themes.${cfg.name}.setupOpts}) + require('${name'}').setup(${toLuaObject cfg.setupOpts}) ${supportedThemes.${cfg.name}.setup} ''; From 8f1002844939f311c50fde88919a0f1f83ec6a8e Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Mon, 7 Oct 2024 23:03:59 +0200 Subject: [PATCH 07/10] oxocarbon and gruvbox borked --- modules/plugins/theme/supported-themes.nix | 6 +++--- modules/plugins/theme/theme.nix | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/plugins/theme/supported-themes.nix b/modules/plugins/theme/supported-themes.nix index 2e2dbce8..03549c60 100644 --- a/modules/plugins/theme/supported-themes.nix +++ b/modules/plugins/theme/supported-themes.nix @@ -128,7 +128,7 @@ in { }; oxocarbon = { - setupOpts = mkPluginSetupOption "oxocarbon" {}; + setupOpts = {}; setup = '' require('oxocarbon') vim.opt.background = "${cfg.style}" @@ -177,8 +177,8 @@ in { default = ""; }; # TODO: fix these - palette_overrides = mkLuaInline "{}"; - overrides = mkLuaInline "{}"; + # palette_overrides = mkLuaInline "{}"; + # overrides = mkLuaInline "{}"; dim_inactive = mkEnableOption "dim_inactive"; }; setup = '' diff --git a/modules/plugins/theme/theme.nix b/modules/plugins/theme/theme.nix index 373d20d3..e1bc4719 100644 --- a/modules/plugins/theme/theme.nix +++ b/modules/plugins/theme/theme.nix @@ -60,7 +60,11 @@ in { luaConfigRC.theme = entryBefore ["pluginConfigs"] '' ${cfg.extraConfig} - require('${name'}').setup(${toLuaObject cfg.setupOpts}) + ${ + if name' != "oxocarbon" + then "require('${name'}').setup(${toLuaObject cfg.setupOpts})" + else "" + } ${supportedThemes.${cfg.name}.setup} ''; From 7c01a7c875cce10c42bc51459a364f4b3f930212 Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Tue, 8 Oct 2024 23:57:47 +0200 Subject: [PATCH 08/10] theme: switch to mapAttrs for setupOpts --- modules/plugins/theme/supported-themes.nix | 136 +++++++++++---------- modules/plugins/theme/theme.nix | 1 - 2 files changed, 70 insertions(+), 67 deletions(-) diff --git a/modules/plugins/theme/supported-themes.nix b/modules/plugins/theme/supported-themes.nix index 03549c60..5f32c006 100644 --- a/modules/plugins/theme/supported-themes.nix +++ b/modules/plugins/theme/supported-themes.nix @@ -3,9 +3,8 @@ lib, }: let inherit (lib.strings) hasPrefix optionalString; - inherit (lib.attrsets) listToAttrs; + inherit (lib.attrsets) genAttrs listToAttrs; inherit (lib.options) mkOption mkEnableOption; - inherit (lib.generators) mkLuaInline; inherit (lib.types) bool str; inherit (lib.nvim.types) hexColor mkPluginSetupOption; cfg = config.vim.theme; @@ -85,39 +84,41 @@ in { internal = true; }; term_colors = mkEnableOption' "term_colors"; - integrations = { - nvimtree = { - enabled = mkEnableOption' "enabled"; - transparent_panel = mkOption { - type = bool; - default = cfg.transparent; + integrations = + { + nvimtree = { + enabled = mkEnableOption' "enabled"; + transparent_panel = mkOption { + type = bool; + default = cfg.transparent; + }; + show_root = mkEnableOption' "show_root"; }; - show_root = mkEnableOption' "show_root"; - }; - hop = mkEnableOption' "hop"; - gitsigns = mkEnableOption' "gitsigns"; - telescope = mkEnableOption' "telescope"; - treesitter = mkEnableOption' "treesitter"; - treesitter_context = mkEnableOption' "treesitter_context"; - ts_rainbow = mkEnableOption' "ts_rainbow"; - fidget = mkEnableOption' "fidget"; - alpha = mkEnableOption' "alpha"; - leap = mkEnableOption' "leap"; - markdown = mkEnableOption' "markdown"; - noice = mkEnableOption' "noice"; - # nvim-notify - notify = mkEnableOption' "notify"; - which_key = mkEnableOption' "which_key"; - navic = { - enabled = mkEnableOption' "enabled"; - # lualine will set backgound to mantle - custom_bg = mkOption { - type = str; - default = "NONE"; + 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 @@ -147,40 +148,43 @@ in { }; gruvbox = { - setupOpts = mkPluginSetupOption "gruvbox" { - transparent_mode = mkOption { - type = bool; - default = cfg.transparent; - internal = true; - }; - # transparent_mode = cfg.transparent; - # add neovim terminal colors - terminal_colors = mkEnableOption' "terminal_colors"; - undercurl = mkEnableOption' "undercurls"; - underline = mkEnableOption' "underline"; - bold = mkEnableOption' "bold"; - italic = { - strings = mkEnableOption' "strings"; - emphasis = mkEnableOption' "emphasis"; - comments = mkEnableOption' "comments"; - operators = mkEnableOption "operators"; - folds = mkEnableOption' "folds"; - }; - strikethrough = mkEnableOption' "strikethrough"; - invert_selection = mkEnableOption "invert_selection"; - invert_signs = mkEnableOption "invert_signs"; - invert_tabline = mkEnableOption "invert_tabline"; - invert_intend_guides = mkEnableOption "invert_intend_guides"; - inverse = mkEnableOption' "inverse"; - contrast = mkOption { - type = str; - default = ""; - }; - # TODO: fix these - # palette_overrides = mkLuaInline "{}"; - # overrides = mkLuaInline "{}"; - dim_inactive = mkEnableOption "dim_inactive"; - }; + setupOpts = + mkPluginSetupOption "gruvbox" { + transparent_mode = mkOption { + type = bool; + default = cfg.transparent; + internal = true; + }; + italic = { + strings = mkEnableOption' "strings"; + emphasis = mkEnableOption' "emphasis"; + comments = mkEnableOption' "comments"; + operators = mkEnableOption "operators"; + folds = mkEnableOption' "folds"; + }; + contrast = mkOption { + type = str; + default = ""; + }; + # TODO: fix these + # palette_overrides = mkLuaInline "{}"; + # overrides = mkLuaInline "{}"; + } + // 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}" diff --git a/modules/plugins/theme/theme.nix b/modules/plugins/theme/theme.nix index e1bc4719..4945c6bb 100644 --- a/modules/plugins/theme/theme.nix +++ b/modules/plugins/theme/theme.nix @@ -17,7 +17,6 @@ }; in { options.vim.theme = { - themes = supportedThemes; inherit (supportedThemes.${cfg.name}) setupOpts; enable = mkOption { From e9f9353c45770f3e45dca41f98ae8dbb968583b8 Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Wed, 9 Oct 2024 00:08:30 +0200 Subject: [PATCH 09/10] more mapAttrs because diniamo loves it so much --- modules/plugins/theme/supported-themes.nix | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/plugins/theme/supported-themes.nix b/modules/plugins/theme/supported-themes.nix index 5f32c006..0d42cc14 100644 --- a/modules/plugins/theme/supported-themes.nix +++ b/modules/plugins/theme/supported-themes.nix @@ -155,13 +155,17 @@ in { default = cfg.transparent; internal = true; }; - italic = { - strings = mkEnableOption' "strings"; - emphasis = mkEnableOption' "emphasis"; - comments = mkEnableOption' "comments"; - operators = mkEnableOption "operators"; - folds = mkEnableOption' "folds"; - }; + italic = + { + operators = mkEnableOption "operators"; + } + // genAttrs [ + "strings" + "emphasis" + "comments" + "folds" + ] (name: mkEnableOption' name); + contrast = mkOption { type = str; default = ""; From 67fb3e00a493c68717d25861ab772d47d018b381 Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Wed, 9 Oct 2024 00:17:23 +0200 Subject: [PATCH 10/10] theme/supported-themes.nix: use mergeAttrsList to generate options --- modules/plugins/theme/supported-themes.nix | 34 ++++++++++++---------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/modules/plugins/theme/supported-themes.nix b/modules/plugins/theme/supported-themes.nix index 0d42cc14..83e1a8f9 100644 --- a/modules/plugins/theme/supported-themes.nix +++ b/modules/plugins/theme/supported-themes.nix @@ -3,7 +3,7 @@ lib, }: let inherit (lib.strings) hasPrefix optionalString; - inherit (lib.attrsets) genAttrs listToAttrs; + inherit (lib.attrsets) genAttrs listToAttrs mergeAttrsList; inherit (lib.options) mkOption mkEnableOption; inherit (lib.types) bool str; inherit (lib.nvim.types) hexColor mkPluginSetupOption; @@ -174,21 +174,23 @@ in { # palette_overrides = mkLuaInline "{}"; # overrides = mkLuaInline "{}"; } - // 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); + // 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}"