2024-04-16 09:44:26 -07:00
|
|
|
{ config
|
|
|
|
, lib
|
|
|
|
, pkgs
|
|
|
|
, ...
|
|
|
|
}:
|
2023-07-13 09:17:51 -07:00
|
|
|
let
|
|
|
|
# string -> type -> string -> a -> a
|
|
|
|
# this is an internal function and shouldn't be
|
|
|
|
# used unless you know what you're doing. it takes
|
|
|
|
# a string (the name of the property, i.e., flavour
|
|
|
|
# or accent), the type of the property, the name of
|
|
|
|
# the module, followed by local config attrset
|
2023-11-02 10:55:47 -07:00
|
|
|
mkBasicOpt = attr: type: name:
|
2023-07-13 09:17:51 -07:00
|
|
|
lib.mkOption {
|
|
|
|
inherit type;
|
|
|
|
default = config.catppuccin.${attr};
|
|
|
|
description = "Catppuccin ${attr} for ${name}";
|
|
|
|
};
|
2023-04-17 09:44:07 -07:00
|
|
|
|
2023-07-13 09:17:51 -07:00
|
|
|
# string -> a -> a
|
|
|
|
# this creates a flavour option for modules
|
|
|
|
# the first string should be the name of the module,
|
|
|
|
# followed by the local config attrset
|
|
|
|
mkFlavourOpt = mkBasicOpt "flavour" types.flavourOption;
|
2023-04-17 09:44:07 -07:00
|
|
|
|
|
|
|
types = {
|
|
|
|
flavourOption = lib.types.enum [ "latte" "frappe" "macchiato" "mocha" ];
|
|
|
|
accentOption = lib.types.enum [
|
|
|
|
"blue"
|
|
|
|
"flamingo"
|
|
|
|
"green"
|
|
|
|
"lavender"
|
|
|
|
"maroon"
|
|
|
|
"mauve"
|
|
|
|
"peach"
|
|
|
|
"pink"
|
|
|
|
"red"
|
|
|
|
"rosewater"
|
|
|
|
"sapphire"
|
|
|
|
"sky"
|
|
|
|
"teal"
|
|
|
|
"yellow"
|
|
|
|
];
|
|
|
|
};
|
2023-07-13 09:17:51 -07:00
|
|
|
in
|
|
|
|
{
|
|
|
|
inherit mkBasicOpt mkFlavourOpt types;
|
2023-04-17 09:44:07 -07:00
|
|
|
|
2023-07-13 09:17:51 -07:00
|
|
|
# string -> string
|
|
|
|
# this capitalizes the first letter in a string,
|
|
|
|
# which is sometimes needed in order to format
|
|
|
|
# the names of themes correctly
|
|
|
|
mkUpper = str:
|
|
|
|
with builtins;
|
|
|
|
(lib.toUpper (substring 0 1 str)) + (substring 1 (stringLength str) str);
|
2023-04-17 09:44:07 -07:00
|
|
|
|
2023-07-13 09:17:51 -07:00
|
|
|
# a -> path -> a
|
|
|
|
# fromJSON but for yaml (and without readFile)
|
|
|
|
# a should be the local pkgs attrset
|
2023-11-02 10:55:47 -07:00
|
|
|
fromYaml = file:
|
2023-07-13 09:17:51 -07:00
|
|
|
let
|
|
|
|
inherit (builtins) fromJSON readFile;
|
2023-04-17 09:44:07 -07:00
|
|
|
|
2023-07-13 09:17:51 -07:00
|
|
|
# convert to json
|
|
|
|
json = with pkgs;
|
|
|
|
runCommand "converted.json" { } ''
|
|
|
|
${yj}/bin/yj < ${file} > $out
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
fromJSON (readFile json);
|
|
|
|
|
2023-11-02 08:55:47 -07:00
|
|
|
# a -> path -> a
|
|
|
|
# fromJSON but for ini (and without readFile)
|
|
|
|
# a should be the local pkgs attrset
|
2023-11-02 10:55:47 -07:00
|
|
|
fromINI = file:
|
2023-11-02 08:55:47 -07:00
|
|
|
let
|
|
|
|
inherit (builtins) fromJSON readFile;
|
|
|
|
|
|
|
|
# convert to json
|
|
|
|
json = with pkgs;
|
|
|
|
runCommand "converted.json" { } ''
|
|
|
|
${jc}/bin/jc --ini < ${file} > $out
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
fromJSON (readFile json);
|
|
|
|
|
2024-04-16 09:44:26 -07:00
|
|
|
# a -> path -> a
|
|
|
|
# fromJSON but for raw ini (and without readFile)
|
|
|
|
# a should be the local pkgs attrset
|
|
|
|
fromINIRaw = file:
|
|
|
|
let
|
|
|
|
inherit (builtins) fromJSON readFile;
|
|
|
|
|
|
|
|
# convert to json
|
|
|
|
json = with pkgs;
|
|
|
|
runCommand "converted.json" { } ''
|
|
|
|
${jc}/bin/jc --ini -r < ${file} > $out
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
fromJSON (readFile json);
|
|
|
|
|
2023-04-17 09:44:07 -07:00
|
|
|
# string -> a -> a
|
|
|
|
# this creates a basic attrset only containing an
|
|
|
|
# enable and flavour option. the fist string should
|
|
|
|
# be the name of the module, followed by the local config
|
|
|
|
# attrset
|
2023-11-02 10:55:47 -07:00
|
|
|
mkCatppuccinOpt = name: {
|
2023-07-13 09:17:51 -07:00
|
|
|
enable = lib.mkEnableOption "Catppuccin theme";
|
2023-11-02 10:55:47 -07:00
|
|
|
flavour = mkFlavourOpt name;
|
2023-04-17 09:44:07 -07:00
|
|
|
};
|
2023-07-13 09:17:51 -07:00
|
|
|
|
|
|
|
# string -> a -> a
|
|
|
|
# this creates an accent option for modules
|
|
|
|
# the first string should be the name of the module,
|
|
|
|
# followed by the local config attrset
|
|
|
|
mkAccentOpt = mkBasicOpt "accent" types.accentOption;
|
2023-11-03 10:25:24 -07:00
|
|
|
|
|
|
|
assertXdgEnabled = name: {
|
|
|
|
assertion = config.xdg.enable;
|
|
|
|
message = "Option xdg.enable must be enabled to apply Catppuccin theming for ${name}";
|
|
|
|
};
|
2024-04-18 13:10:23 -07:00
|
|
|
|
|
|
|
# see https://nlewo.github.io/nixos-manual-sphinx/development/option-types.xml.html
|
|
|
|
# by default enums cannot be merged, but they keep their passed value in `functor.payload`.
|
|
|
|
# `functor.binOp` can merge those values
|
|
|
|
mergeEnums = a: b: lib.types.enum (a.functor.binOp a.functor.payload b.functor.payload);
|
2023-04-17 09:44:07 -07:00
|
|
|
}
|