From 47ed783712fd390bcdec3c1f1fc2c5f6f1758237 Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Wed, 26 Mar 2025 19:15:51 +0100 Subject: [PATCH] style: move colorscheme settings --- modules/options/style/colors.nix | 105 ----------------- modules/style/colors.nix | 106 +++++++++++++++++- .../style/palettes/black-metal-venom.nix | 0 .../style/palettes/catppuccin-mocha.nix | 0 .../{options => }/style/palettes/gruvbox.nix | 0 .../{options => }/style/palettes/zenburn.nix | 0 6 files changed, 105 insertions(+), 106 deletions(-) delete mode 100644 modules/options/style/colors.nix rename modules/{options => }/style/palettes/black-metal-venom.nix (100%) rename modules/{options => }/style/palettes/catppuccin-mocha.nix (100%) rename modules/{options => }/style/palettes/gruvbox.nix (100%) rename modules/{options => }/style/palettes/zenburn.nix (100%) diff --git a/modules/options/style/colors.nix b/modules/options/style/colors.nix deleted file mode 100644 index ba2a272..0000000 --- a/modules/options/style/colors.nix +++ /dev/null @@ -1,105 +0,0 @@ -# NOTE: This module is entirely inspired by raf, -# most of the nix code is also taken from him, -# so please do check out his configuration! -# raf himself took it from misterio77 -# and adapted it for his personal use, -# so look there too. -# -{ - config, - lib, - ... -}: let - inherit (lib.options) mkOption literalExpression; - inherit (lib.types) str nullOr enum mkOptionType attrsOf coercedTo; - inherit (lib.strings) toLower replaceStrings removePrefix hasPrefix isString; - # inherit (lib) serializeTheme; - - cfg = config.modules.style; - - hexColorType = mkOptionType { - name = "hex-color"; - descriptionClass = "noun"; - description = "RGB color in hex format"; - check = x: isString x && !(hasPrefix "#" x); - }; - colorType = attrsOf (coercedTo str (removePrefix "#") hexColorType); - - nameToSlug = name: toLower (replaceStrings [" "] ["-"] name); - getPaletteFromScheme = slug: - if builtins.pathExists ./palettes/${slug}.nix - then (import ./palettes/${slug}.nix).colorscheme.palette - else throw "The following colorscheme was imported but not found: ${slug}"; -in { - options.modules.style = { - colorScheme = { - name = mkOption { - type = nullOr (enum ["Catppuccin Mocha" "Zenburn" "Black Metal Venom" "Gruvbox"]); - description = "The colorscheme that should be used globally to theme your system."; - default = "Gruvbox"; - }; - - slug = mkOption { - type = str; - default = nameToSlug "${toString cfg.colorScheme.name}"; # toString to avoid type errors if null, returns "" - description = '' - The serialized slug for the colorScheme you are using. - - Defaults to a lowercased version of the theme name with spaces - replaced with hyphens. - - Must only be changed if the slug is expected to be different than - the serialized theme name." - ''; - }; - - colors = mkOption { - type = colorType; - default = getPaletteFromScheme cfg.colorScheme.slug; - description = '' - An attribute set containing active colors of the system. Follows base16 - scheme by default but can be expanded to base24 or anything "above" as - seen fit as the module option is actually not checked in any way - ''; - example = literalExpression '' - { - base00 = "#1e1e2e"; # Base - base01 = "#181825"; # Mantle - base02 = "#313244"; # Surface0 - base03 = "#45475a"; # Surface1 - base04 = "#585b70"; # Surface2 - base05 = "#cdd6f4"; # text - base06 = "#f5e0dc"; # rosewater - base07 = "#b4befe"; # lavender - base08 = "#f38ba8"; # red - base09 = "#fab387"; # peach - base0A = "#a6e3a1"; # yellow - base0B = "#94e2d5"; # green - base0C = "#94e2d5"; # teal - base0D = "#89b4fa"; # blue - base0E = "#cba6f7"; # mauve - base0F = "#f2cdcd"; # flamingo - } - ''; - }; - - variant = mkOption { - type = enum ["dark" "light"]; - default = - if builtins.substring 0 1 cfg.colorScheme.colors.base00 < "5" - then "dark" - else "light"; - description = '' - Whether the scheme is dark or light - ''; - }; - alpha = mkOption { - type = str; - default = 1.0; - description = '' - The alpha value for the colorscheme - ''; - }; - }; - }; -} diff --git a/modules/style/colors.nix b/modules/style/colors.nix index eed7124..ba2a272 100644 --- a/modules/style/colors.nix +++ b/modules/style/colors.nix @@ -1 +1,105 @@ -_: {} +# NOTE: This module is entirely inspired by raf, +# most of the nix code is also taken from him, +# so please do check out his configuration! +# raf himself took it from misterio77 +# and adapted it for his personal use, +# so look there too. +# +{ + config, + lib, + ... +}: let + inherit (lib.options) mkOption literalExpression; + inherit (lib.types) str nullOr enum mkOptionType attrsOf coercedTo; + inherit (lib.strings) toLower replaceStrings removePrefix hasPrefix isString; + # inherit (lib) serializeTheme; + + cfg = config.modules.style; + + hexColorType = mkOptionType { + name = "hex-color"; + descriptionClass = "noun"; + description = "RGB color in hex format"; + check = x: isString x && !(hasPrefix "#" x); + }; + colorType = attrsOf (coercedTo str (removePrefix "#") hexColorType); + + nameToSlug = name: toLower (replaceStrings [" "] ["-"] name); + getPaletteFromScheme = slug: + if builtins.pathExists ./palettes/${slug}.nix + then (import ./palettes/${slug}.nix).colorscheme.palette + else throw "The following colorscheme was imported but not found: ${slug}"; +in { + options.modules.style = { + colorScheme = { + name = mkOption { + type = nullOr (enum ["Catppuccin Mocha" "Zenburn" "Black Metal Venom" "Gruvbox"]); + description = "The colorscheme that should be used globally to theme your system."; + default = "Gruvbox"; + }; + + slug = mkOption { + type = str; + default = nameToSlug "${toString cfg.colorScheme.name}"; # toString to avoid type errors if null, returns "" + description = '' + The serialized slug for the colorScheme you are using. + + Defaults to a lowercased version of the theme name with spaces + replaced with hyphens. + + Must only be changed if the slug is expected to be different than + the serialized theme name." + ''; + }; + + colors = mkOption { + type = colorType; + default = getPaletteFromScheme cfg.colorScheme.slug; + description = '' + An attribute set containing active colors of the system. Follows base16 + scheme by default but can be expanded to base24 or anything "above" as + seen fit as the module option is actually not checked in any way + ''; + example = literalExpression '' + { + base00 = "#1e1e2e"; # Base + base01 = "#181825"; # Mantle + base02 = "#313244"; # Surface0 + base03 = "#45475a"; # Surface1 + base04 = "#585b70"; # Surface2 + base05 = "#cdd6f4"; # text + base06 = "#f5e0dc"; # rosewater + base07 = "#b4befe"; # lavender + base08 = "#f38ba8"; # red + base09 = "#fab387"; # peach + base0A = "#a6e3a1"; # yellow + base0B = "#94e2d5"; # green + base0C = "#94e2d5"; # teal + base0D = "#89b4fa"; # blue + base0E = "#cba6f7"; # mauve + base0F = "#f2cdcd"; # flamingo + } + ''; + }; + + variant = mkOption { + type = enum ["dark" "light"]; + default = + if builtins.substring 0 1 cfg.colorScheme.colors.base00 < "5" + then "dark" + else "light"; + description = '' + Whether the scheme is dark or light + ''; + }; + alpha = mkOption { + type = str; + default = 1.0; + description = '' + The alpha value for the colorscheme + ''; + }; + }; + }; +} diff --git a/modules/options/style/palettes/black-metal-venom.nix b/modules/style/palettes/black-metal-venom.nix similarity index 100% rename from modules/options/style/palettes/black-metal-venom.nix rename to modules/style/palettes/black-metal-venom.nix diff --git a/modules/options/style/palettes/catppuccin-mocha.nix b/modules/style/palettes/catppuccin-mocha.nix similarity index 100% rename from modules/options/style/palettes/catppuccin-mocha.nix rename to modules/style/palettes/catppuccin-mocha.nix diff --git a/modules/options/style/palettes/gruvbox.nix b/modules/style/palettes/gruvbox.nix similarity index 100% rename from modules/options/style/palettes/gruvbox.nix rename to modules/style/palettes/gruvbox.nix diff --git a/modules/options/style/palettes/zenburn.nix b/modules/style/palettes/zenburn.nix similarity index 100% rename from modules/options/style/palettes/zenburn.nix rename to modules/style/palettes/zenburn.nix