From a27db3020e364aad9aad1d3627c9d866b9937e27 Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Sun, 15 Sep 2024 20:59:53 +0200 Subject: [PATCH] colors: add color options, add catpuccin-mocha.nix --- modules/options/style/colors.nix | 43 +++++++++++++++---- modules/options/style/module.nix | 1 + .../style/palettes/catppuccin-mocha.nix | 25 +++++++++++ 3 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 modules/options/style/palettes/catppuccin-mocha.nix diff --git a/modules/options/style/colors.nix b/modules/options/style/colors.nix index ac71257..fe51a2c 100644 --- a/modules/options/style/colors.nix +++ b/modules/options/style/colors.nix @@ -1,22 +1,49 @@ -{lib, ...}: let - inherit (lib) mkOption; - inherit (lib.types) str; +# 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! +{ + config, + lib, + ... +}: let + inherit (lib) mkOptionType isString mkOption; + inherit (lib.strings) replaceStrings hasPrefix removePrefix toLower; + inherit (lib.types) enum str coercedTo nullOr attrsOf; + + cfg = config.modules.style; + + nameToSlug = name: toLower (replaceStrings [" "] ["-"] name); + + 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); + + 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 = str; + type = nullOr (enum ["Catppuccin Mocha" "Catppuccin Latte"]); default = "Catppuccin Mocha"; }; slug = { type = str; - default = "catppuccin-mocha"; + default = nameToSlug "${toString cfg.colorScheme.name}"; }; variant = { }; - colors = - mkOption { - }; + colors = mkOption { + type = colorType; + default = getPaletteFromScheme cfg.colorScheme.slug; + }; }; }; } diff --git a/modules/options/style/module.nix b/modules/options/style/module.nix index a8323b7..1800d2f 100644 --- a/modules/options/style/module.nix +++ b/modules/options/style/module.nix @@ -10,6 +10,7 @@ in { ./qt.nix ./gtk.nix ./fonts.nix + ./colors.nix ]; options.modules.style = { diff --git a/modules/options/style/palettes/catppuccin-mocha.nix b/modules/options/style/palettes/catppuccin-mocha.nix new file mode 100644 index 0000000..814e1b1 --- /dev/null +++ b/modules/options/style/palettes/catppuccin-mocha.nix @@ -0,0 +1,25 @@ +{ + colorscheme = { + slug = "catppuccin-mocha"; + name = "Catppuccin Mocha"; + variant = "dark"; + palette = { + 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 + }; + }; +}