Skip to content

Commit

Permalink
feat: use whickers to generate flavors && allow access to them
Browse files Browse the repository at this point in the history
  • Loading branch information
NikSneMC committed Aug 31, 2024
1 parent 874e668 commit a0692e4
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 24 deletions.
21 changes: 21 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Print out all recipes when running `just`
_default:
@just --list

# Variables
output_dir := "modules/lib"
output_file := "flavors.json"
whiskers_cmd := "whiskers"
template_path := "nix.tera"

# Create the output directory
setup:
mkdir -p {{output_dir}}

# Remove previously generated file
clean:
rm {{output_dir}}/{{output_file}}

# Generate "flavors.nix" file
gen:
{{whiskers_cmd}} {{template_path}} > {{output_dir}}/{{output_file}}
7 changes: 7 additions & 0 deletions modules/home-manager/globals.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
description = "Global Catppuccin accent";
};

lavors = lib.mkOption {
description = '''';
type = lib.types.attrs;
readOnly = true;
default = lib.ctp.flavors;
};

sources =
let
defaultSources = import ../../.sources;
Expand Down
34 changes: 10 additions & 24 deletions modules/lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let
# this is a recursive attribute with all the functions below
inherit (lib) ctp;
in
{
rec {
# string -> type -> string -> a
# this is an internal function and shouldn't be
# used unless you know what you're doing. it takes
Expand All @@ -29,29 +29,15 @@ in
# followed by the local config attrset
mkFlavorOpt = ctp.mkBasicOpt "flavor" ctp.types.flavorOption;

types = {
flavorOption = 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"
];
flavors = builtins.fromJSON (builtins.readFile ./flavors.json);

types = let
flavorOptions = builtins.attrNames flavors;
in {
flavorOption = lib.types.enum flavorOptions;
accentOption = lib.types.enum (builtins.attrNames (
lib.filterAttrs (_: color: color.accent) flavors.${builtins.elemAt flavorOptions 0}.colors
));
};

# string -> string
Expand Down
2 changes: 2 additions & 0 deletions modules/lib/flavors.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions modules/nixos/globals.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
description = "Global Catppuccin accent";
};

flavors = lib.mkOption {
description = '''';
type = lib.types.attrs;
readOnly = true;
default = lib.ctp.flavors;
};

sources =
let
defaultSources = import ../../.sources;
Expand Down
6 changes: 6 additions & 0 deletions nix.tera
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
whiskers:
version: "2.4.0"
---

{{flavors | json_encode()}}

0 comments on commit a0692e4

Please sign in to comment.