-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
319 lines (276 loc) ยท 15.4 KB
/
flake.nix
File metadata and controls
319 lines (276 loc) ยท 15.4 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
{
description = "CrystalNix - A universal design system for Nix configurations";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
lib = nixpkgs.lib;
# Import our design system library
designSystem = import ./lib { inherit lib; };
# Auto-discover available themes
themesDir = ./themes;
availableThemeFiles = builtins.filter
(name: lib.hasSuffix ".nix" name && name != "default.nix")
(builtins.attrNames (builtins.readDir themesDir));
availableThemes = map (name: lib.removeSuffix ".nix" name) availableThemeFiles;
# Main stylesheet function - now using processTheme
mkStylesheet = { theme ? "dark", overrides ? { } }:
let
# Validate theme exists
themeFile = themesDir + "/${theme}.nix";
themeExists = builtins.pathExists themeFile;
# Load the selected raw theme
rawTheme =
if themeExists
then import themeFile { inherit lib; }
else throw "Theme '${theme}' not found. Available themes: ${lib.concatStringsSep ", " availableThemes}";
# Apply overrides to raw theme before processing
rawThemeWithOverrides = lib.recursiveUpdate rawTheme overrides;
# Process the raw theme into full stylesheet
finalStylesheet = designSystem.processTheme rawThemeWithOverrides;
in
finalStylesheet // {
# Expose metadata for tooling/discovery
_meta = {
inherit availableThemes;
currentTheme = theme;
hasOverrides = overrides != { };
# Add info about the design system
designSystemVersion = "2.0.0";
transformsApplied = true;
};
};
in
{
# Main library functions
lib = {
inherit mkStylesheet;
listThemes = availableThemes;
# Also expose the design system for advanced usage
inherit (designSystem) processTheme themes;
designSystem = designSystem;
};
# Pre-built themes for easy access
packages = {
default = mkStylesheet { };
dark = mkStylesheet { theme = "dark"; };
light = mkStylesheet { theme = "light"; };
};
# Development shell
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [ nix nixfmt jq ];
shellHook = ''
echo "๐ฎ Welcome to CrystalNix development!"
echo "Available themes: ${lib.concatStringsSep ", " availableThemes}"
echo ""
echo "Testing Commands:"
echo " nix run .#validate # Run all validation tests"
echo " nix run .#debug # Debug dark theme"
echo " nix run .#compare # Compare dark vs light"
echo " nix run .#formats # Test format outputs"
echo ""
echo "Quick start: nix run .#debug"
'';
};
# Testing and utility apps
apps = {
# List available themes
list-themes = {
type = "app";
program = toString (pkgs.writeShellScript "list-themes" ''
echo "๐ฎ Available CrystalNix themes:"
${lib.concatMapStringsSep "\n" (theme: "echo ' - ${theme}'") availableThemes}
'');
};
# Debug a specific theme (defaults to dark)
debug = {
type = "app";
program = toString (pkgs.writeShellScript "crystalnix-debug" ''
theme=''${1:-dark}
echo "๐ฎ CrystalNix Debug: $theme theme"
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
# Check if theme exists by trying to evaluate it
if ! nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json >/dev/null 2>&1; then
echo "โ Theme '$theme' not found"
echo ""
echo "Available themes:"
${lib.concatMapStringsSep "\n" (theme: "echo ' - ${theme}'") availableThemes}
exit 1
fi
# Load the theme and extract key info
echo "๐ Theme Metadata:"
nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '._meta | to_entries[] | " \(.key): \(.value)"'
echo ""
echo "๐จ Key Colors (multiple formats):"
echo " Primary (hex): $(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '.colors.primary."500".hex')"
echo " Primary (conf): $(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '.colors.primary."500".conf')"
echo " Background: $(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '.colors.background.primary.hex')"
echo ""
echo "๐ Layout Values:"
echo " Spacing md (px): $(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '.spacing.md.px')"
echo " Spacing md (rem): $(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '.spacing.md.rem')"
echo " Spacing md (raw): $(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '.spacing.md.raw')"
echo ""
echo "โก Motion Settings:"
echo " Duration fast: $(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '.motion.duration.fast.ms')"
echo " Easing smooth: $(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '.motion.easing.smooth.raw')"
echo ""
echo "๐ก Usage examples:"
echo " # Hyprland config"
echo " stylesheet.colors.primary.\"500\".conf"
echo " # CSS"
echo " stylesheet.colors.primary.\"500\".hex"
echo " stylesheet.spacing.md.rem"
'');
};
# Test format outputs
formats = {
type = "app";
program = toString (pkgs.writeShellScript "crystalnix-formats" ''
theme=''${1:-dark}
echo "๐ฎ CrystalNix Format Testing: $theme theme"
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
echo "๐จ Color Formats:"
primary_hex=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '.colors.primary."500".hex')
primary_conf=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '.colors.primary."500".conf')
echo " .hex: $primary_hex"
echo " .conf: $primary_conf"
echo ""
echo "๐ Spacing Formats:"
spacing_px=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '.spacing.md.px')
spacing_rem=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '.spacing.md.rem')
spacing_raw=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '.spacing.md.raw')
echo " .px: $spacing_px"
echo " .rem: $spacing_rem"
echo " .raw: $spacing_raw"
echo ""
echo "โฑ๏ธ Duration Formats:"
duration_ms=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '.motion.duration.fast.ms')
duration_s=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '.motion.duration.fast.s')
duration_raw=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme\"; }" --json | ${pkgs.jq}/bin/jq -r '.motion.duration.fast.raw')
echo " .ms: $duration_ms"
echo " .s: $duration_s"
echo " .raw: $duration_raw"
'');
};
# Compare two themes
compare = {
type = "app";
program = toString (pkgs.writeShellScript "crystalnix-compare" ''
theme1=''${1:-dark}
theme2=''${2:-light}
echo "๐ฎ Comparing CrystalNix Themes: $theme1 vs $theme2"
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
# Get theme data using the lib
t1_primary=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme1\"; }" --json | ${pkgs.jq}/bin/jq -r '.colors.primary."500".hex')
t1_bg=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme1\"; }" --json | ${pkgs.jq}/bin/jq -r '.colors.background.primary.hex')
t1_spacing=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme1\"; }" --json | ${pkgs.jq}/bin/jq -r '.spacing.md.px')
t2_primary=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme2\"; }" --json | ${pkgs.jq}/bin/jq -r '.colors.primary."500".hex')
t2_bg=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme2\"; }" --json | ${pkgs.jq}/bin/jq -r '.colors.background.primary.hex')
t2_spacing=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"$theme2\"; }" --json | ${pkgs.jq}/bin/jq -r '.spacing.md.px')
echo "๐จ Primary Colors:"
echo " $theme1: $t1_primary"
echo " $theme2: $t2_primary"
echo ""
echo "๐ Background Colors:"
echo " $theme1: $t1_bg"
echo " $theme2: $t2_bg"
echo ""
echo "๐ Spacing (md):"
echo " $theme1: $t1_spacing"
echo " $theme2: $t2_spacing"
# Check if they're different
if [ "$t1_primary" != "$t2_primary" ] || [ "$t1_bg" != "$t2_bg" ]; then
echo ""
echo "โ
Themes are different - switching will change your appearance"
else
echo ""
echo "โ ๏ธ Themes appear identical - you may need to check theme definitions"
fi
'');
};
# Validate all functionality
validate = {
type = "app";
program = toString (pkgs.writeShellScript "crystalnix-validate" ''
set -e
echo "๐ฎ CrystalNix Validation Tests"
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
errors=0
# Test 1: Check all themes load
echo "๐ Test 1: Theme Loading"
${lib.concatMapStringsSep "\n" (theme: ''
echo -n " Testing ${theme}... "
if nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"${theme}\"; }" --json >/dev/null 2>&1; then
echo "โ
"
else
echo "โ"
((errors++))
fi
'') availableThemes}
# Test 2: Check format transforms work
echo ""
echo "๐ Test 2: Format Transforms"
echo -n " Testing color formats... "
hex_format=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"dark\"; }" --json | ${pkgs.jq}/bin/jq -r '.colors.primary."500".hex // empty')
conf_format=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"dark\"; }" --json | ${pkgs.jq}/bin/jq -r '.colors.primary."500".conf // empty')
if [ -n "$hex_format" ] && [ -n "$conf_format" ] && [ "$hex_format" != "$conf_format" ]; then
echo "โ
"
else
echo "โ"
((errors++))
fi
# Test 3: Check overrides work
echo ""
echo "๐ Test 3: Override Functionality"
original=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"dark\"; }" --json | ${pkgs.jq}/bin/jq -r '.colors.primary."500".hex')
override=$(nix eval .#lib --apply "lib: lib.mkStylesheet { theme = \"dark\"; overrides = { colors.primary.\"500\" = \"#ff0000\"; }; }" --json | ${pkgs.jq}/bin/jq -r '.colors.primary."500".hex')
echo " Original: $original"
echo " Override: $override"
if [ "$original" != "$override" ] && [ "$override" = "#ff0000" ]; then
echo " โ
Overrides working"
else
echo " โ Overrides not working"
((errors++))
fi
echo ""
if [ $errors -eq 0 ]; then
echo "๐ All tests passed! CrystalNix is working correctly."
echo ""
echo "Try: nix run .#debug dark"
echo "Try: nix run .#formats dark"
else
echo "๐ฅ $errors test(s) failed"
exit 1
fi
'');
};
};
}) // {
# System-agnostic lib for use in other flakes
lib = {
mkStylesheet = { theme ? "dark", overrides ? { } }:
let
lib = nixpkgs.lib;
designSystem = import ./lib { inherit lib; };
rawTheme = import (./themes + "/${theme}.nix") { inherit lib; };
rawThemeWithOverrides = lib.recursiveUpdate rawTheme overrides;
finalStylesheet = designSystem.processTheme rawThemeWithOverrides;
in
finalStylesheet // {
_meta = {
currentTheme = theme;
hasOverrides = overrides != { };
designSystemVersion = "2.0.0";
};
};
# Also expose the design system components
processTheme = (import ./lib { inherit (nixpkgs) lib; }).processTheme;
};
};
}