nichts/modules/options/style/colors.nix

50 lines
1.4 KiB
Nix
Raw Normal View History

# 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}";
2024-09-03 21:44:59 +02:00
in {
options.modules.style = {
colorScheme = {
name = mkOption {
type = nullOr (enum ["Catppuccin Mocha" "Catppuccin Latte"]);
2024-09-06 08:38:36 +02:00
default = "Catppuccin Mocha";
2024-09-03 21:44:59 +02:00
};
slug = {
2024-09-06 08:38:36 +02:00
type = str;
default = nameToSlug "${toString cfg.colorScheme.name}";
2024-09-03 21:44:59 +02:00
};
variant = {
};
colors = mkOption {
type = colorType;
default = getPaletteFromScheme cfg.colorScheme.slug;
};
2024-09-03 21:44:59 +02:00
};
};
}