/
module.nix
139 lines (125 loc) · 4.26 KB
/
module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# this arg is the matugen flake input
matugen: {
pkgs,
lib,
config,
...
} @ args: let
cfg = config.programs.matugen;
osCfg = args.osConfig.programs.matugen or {};
configFormat = pkgs.formats.toml {};
capitalize = str: let
inherit (builtins) substring stringLength;
firstChar = substring 0 1 str;
restOfString = substring 1 (stringLength str) str;
in
lib.concatStrings [(lib.toUpper firstChar) restOfString];
# don't use ~, use $HOME
sanitizedTemplates =
builtins.mapAttrs (_: v: {
mode = capitalize cfg.variant;
input_path = builtins.toString v.input_path;
output_path = builtins.replaceStrings ["$HOME"] ["~"] v.output_path;
})
cfg.templates;
matugenConfig = configFormat.generate "matugen-config.toml" {
config = {};
templates = sanitizedTemplates;
};
# get matugen package
pkg = matugen.packages.${pkgs.system}.default;
themePackage = pkgs.runCommandLocal "matugen-themes-${cfg.variant}" {} ''
mkdir -p $out
cd $out
export HOME=$(pwd)
${pkg}/bin/matugen \
image ${cfg.wallpaper} \
${
if cfg.templates != {}
then "--config ${matugenConfig}"
else ""
} \
--mode ${cfg.variant} \
--type ${cfg.type} \
--json ${cfg.jsonFormat} \
--quiet \
> $out/theme.json
'';
colors = builtins.fromJSON (builtins.readFile "${themePackage}/theme.json");
in {
options.programs.matugen = {
enable = lib.mkEnableOption "Matugen declarative theming";
wallpaper = lib.mkOption {
description = "Path to `wallpaper` that matugen will generate the colorschemes from";
type = lib.types.path;
default = osCfg.wallpaper or "${pkgs.nixos-artwork.wallpapers.simple-blue}/share/backgrounds/nixos/nix-wallpaper-simple-blue.png";
defaultText = lib.literalExample ''
"${pkgs.nixos-artwork.wallpapers.simple-blue}/share/backgrounds/nixos/nix-wallpaper-simple-blue.png"
'';
};
templates = lib.mkOption {
type = with lib.types;
attrsOf (submodule {
options = {
input_path = lib.mkOption {
type = path;
description = "Path to the template";
example = "./style.css";
};
output_path = lib.mkOption {
type = str;
description = "Path where the generated file will be written to";
example = "~/.config/sytle.css";
};
};
});
default = osCfg.templates or {};
description = ''
Templates that have `@{placeholders}` which will be replaced by the respective colors.
See <https://github.com/InioX/matugen/wiki/Configuration#example-of-all-the-color-keywords> for a list of colors.
'';
};
type = lib.mkOption {
description = "Palette used when generating the colorschemes.";
type = lib.types.enum ["scheme-content" "scheme-expressive" "scheme-fidelity" "scheme-fruit-salad" "scheme-monochrome" "scheme-neutral" "scheme-rainbow" "scheme-tonal-spot"];
default = osCfg.palette or "scheme-tonal-spot";
example = "triadic";
};
jsonFormat = lib.mkOption {
description = "Color format of the colorschemes.";
type = lib.types.enum ["rgb" "rgba" "hsl" "hsla" "hex" "strip"];
default = osCfg.jsonFormat or "strip";
example = "rgba";
};
variant = lib.mkOption {
description = "Colorscheme variant.";
type = lib.types.enum ["light" "dark" "amoled"];
default = osCfg.variant or "dark";
example = "light";
};
theme.files = lib.mkOption {
type = lib.types.package;
readOnly = true;
default =
if builtins.hasAttr "templates" osCfg
then
if cfg.templates != osCfg.templates
then themePackage
else osCfg.theme.files
else themePackage;
description = "Generated theme files. Including only the variant chosen.";
};
theme.colors = lib.mkOption {
inherit (pkgs.formats.json {}) type;
readOnly = true;
default =
if builtins.hasAttr "templates" osCfg
then
if cfg.templates != osCfg.templates
then colors
else osCfg.theme.colors
else colors;
description = "Generated theme colors. Includes all variants.";
};
};
}