colors: add color options, add catpuccin-mocha.nix

This commit is contained in:
Charlie Root 2024-09-15 20:59:53 +02:00
commit a27db3020e
3 changed files with 61 additions and 8 deletions

View file

@ -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;
};
};
};
}