-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjustfile
More file actions
621 lines (523 loc) · 21.2 KB
/
justfile
File metadata and controls
621 lines (523 loc) · 21.2 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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
# Configuration
SOPS_FILE := "../nix-secrets/.sops.yaml"
NIX_FLAGS := "--experimental-features 'nix-command flakes'"
NIX_FLAGS_NO_TESTS := "--experimental-features 'nix-command flakes' --option check false --option pure-eval false"
HOSTNAME := `hostname`
# =============================================================================
# Helper Functions
# =============================================================================
# Ensure we're not running as root (but allow sudo usage within commands)
_check-non-root:
#!/usr/bin/env bash
if [ ${EUID:-0} -eq 0 ] || [ "$(id -u)" -eq 0 ]; then
echo "❌ This script requires non-root access (but may use sudo internally)."
exit 42
fi
# Ensure we're running as root
_check-must-be-root:
#!/usr/bin/env bash
if [ ${EUID:-0} -ne 0 ] || [ "$(id -u)" -ne 0 ]; then
echo "❌ This script requires root access."
exit 42
fi
# Check if Nix is installed
_check-nix:
#!/usr/bin/env bash
if ! command -v nix 1>/dev/null 2>&1; then
echo "❌ Nix is not installed!"
exit 42
fi
# Ensure darwin-rebuild is available
_ensure-darwin-rebuild:
#!/usr/bin/env bash
if ! command -v darwin-rebuild 1>/dev/null 2>&1; then
echo "📦 darwin-rebuild is not installed, installing..."
sudo nix run nix-darwin {{ NIX_FLAGS }} -- switch --flake ".#{{ HOSTNAME }}"
fi
# Conditionally use nom for better output formatting
_nom CMD:
#!/usr/bin/env bash
if command -v nom 1>/dev/null 2>&1; then
set -o pipefail
{{ CMD }} |& nom --json
else
{{ CMD }}
fi
# Execute command with optional file logging
_nom-with-log CMD LOGFILE="":
#!/usr/bin/env bash
if [ -n "{{ LOGFILE }}" ]; then
echo "📝 Saving logs to: {{ LOGFILE }}"
if command -v nom 1>/dev/null 2>&1; then
set -o pipefail
# Use process substitution to save raw output to file while showing nom output
{{ CMD }} 2>&1 | tee "{{ LOGFILE }}" | nom --json
else
{{ CMD }} 2>&1 | tee "{{ LOGFILE }}"
fi
else
just _nom "{{ CMD }}"
fi
# Print a section separator
_separator:
@echo "# ======================================================================="
# Execute nix flake commands with optional nom support and logging
_nix-flake SUBCOMMAND USE_NOM="" LOGFILE="":
#!/usr/bin/env bash
if [ "{{ USE_NOM }}" = "nom" ]; then
CMD="nix {{ NIX_FLAGS }} flake {{ SUBCOMMAND }} --log-format internal-json --verbose --print-build-logs"
if [ -n "{{ LOGFILE }}" ]; then
just _nom-with-log "$CMD" "{{ LOGFILE }}"
else
just _nom "$CMD"
fi
else
CMD="nix {{ NIX_FLAGS }} flake {{ SUBCOMMAND }} --print-build-logs"
if [ -n "{{ LOGFILE }}" ]; then
echo "📝 Saving logs to: {{ LOGFILE }}"
eval "$CMD" 2>&1 | tee "{{ LOGFILE }}"
else
eval "$CMD"
fi
fi
# Execute nh darwin commands with optional logging
_nh-darwin SUBCOMMAND USE_NOM="" LOGFILE="":
#!/usr/bin/env bash
echo "🔨 Using nh for darwin {{ SUBCOMMAND }}..."
if [ "{{ USE_NOM }}" = "nom" ]; then
CMD="nh darwin {{ SUBCOMMAND }} --hostname '{{ HOSTNAME }}' . --log-format internal-json --verbose"
else
CMD="nh darwin {{ SUBCOMMAND }} --hostname '{{ HOSTNAME }}' ."
fi
if [ -n "{{ LOGFILE }}" ]; then
if [ "{{ USE_NOM }}" = "nom" ]; then
just _nom-with-log "$CMD" "{{ LOGFILE }}"
else
echo "📝 Saving logs to: {{ LOGFILE }}"
eval "$CMD" 2>&1 | tee "{{ LOGFILE }}"
fi
else
if [ "{{ USE_NOM }}" = "nom" ]; then
just _nom "$CMD"
else
eval "$CMD"
fi
fi
# Execute darwin-rebuild commands with optional logging
_darwin-rebuild SUBCOMMAND USE_NOM="" LOGFILE="":
#!/usr/bin/env bash
echo "🔨 Using darwin-rebuild for {{ SUBCOMMAND }}..."
if [ "{{ SUBCOMMAND }}" = "switch" ]; then
CMD="sudo darwin-rebuild {{ SUBCOMMAND }} --print-build-logs --flake '.#{{ HOSTNAME }}'"
else
CMD="darwin-rebuild {{ SUBCOMMAND }} --print-build-logs --flake '.#{{ HOSTNAME }}'"
fi
if [ -n "{{ LOGFILE }}" ]; then
if [ "{{ USE_NOM }}" = "nom" ]; then
just _nom-with-log "$CMD" "{{ LOGFILE }}"
else
echo "📝 Saving logs to: {{ LOGFILE }}"
eval "$CMD" 2>&1 | tee "{{ LOGFILE }}"
fi
else
if [ "{{ USE_NOM }}" = "nom" ]; then
just _nom "$CMD"
else
eval "$CMD"
fi
fi
# Perform full system switch workflow with optional logging (uses darwin-rebuild)
_switch-workflow USE_NOM="" LOGFILE="":
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
just _separator
echo "🔍 Checking flake..."
just _nix-flake "check" "{{ USE_NOM }}" "{{ LOGFILE }}"
just _separator
just _ensure-darwin-rebuild
# just _separator
# echo "✅ Checking darwin configuration..."
# if [ -n "{{ LOGFILE }}" ]; then
# sudo darwin-rebuild check --flake ".#{{ HOSTNAME }}" --show-trace 2>&1 | tee -a "{{ LOGFILE }}"
# else
# sudo darwin-rebuild check --flake ".#{{ HOSTNAME }}" --show-trace
# fi
just _separator
echo "🚀 Switching system configuration..."
just _darwin-rebuild "switch" "{{ USE_NOM }}" "{{ LOGFILE }}"
just _separator
echo "✅ System switch completed!"
# Perform full system switch workflow using nh with optional logging
_switch-nh-workflow USE_NOM="" LOGFILE="":
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
just _separator
echo "🔍 Checking flake..."
just _nix-flake "check" "{{ USE_NOM }}" "{{ LOGFILE }}"
just _separator
echo "🚀 Switching system configuration with nh..."
just _nh-darwin "switch" "{{ USE_NOM }}" "{{ LOGFILE }}"
just _separator
echo "✅ NH switch completed!"
# =============================================================================
# Main Commands
# =============================================================================
default:
@just --list
[doc('Show current staged and unstaged changes')]
diff:
git diff ':!flake.lock'
[doc('Format Nix files in the workspace')]
format FORMATTER="auto":
#!/usr/bin/env bash
case "{{ FORMATTER }}" in
"auto"|"nix")
echo "🎨 Formatting Nix files with nix fmt..."
nix {{ NIX_FLAGS }} fmt
;;
"nix-fmt")
echo "🎨 Formatting Nix files with nix-fmt..."
nix-shell --packages nix-fmt --run 'find . -name "*.nix" -not -path "./result*" -exec nix-fmt {} +'
;;
"nixfmt-rfc-style")
echo "🎨 Formatting Nix files with nixfmt-rfc-style..."
nix-shell --packages nixfmt-rfc-style --run 'find . -name "*.nix" -not -path "./result*" -exec nixfmt-rfc-style {} +'
;;
"nixpkgs-fmt")
echo "🎨 Formatting Nix files with nixpkgs-fmt..."
nix-shell --packages nixpkgs-fmt --run 'find . -name "*.nix" -not -path "./result*" -exec nixpkgs-fmt {} +'
;;
"alejandra")
echo "🎨 Formatting Nix files with alejandra..."
nix-shell --packages alejandra --run 'alejandra .'
;;
"nixfmt")
echo "🎨 Formatting Nix files with nixfmt..."
nix-shell --packages nixfmt --run 'find . -name "*.nix" -not -path "./result*" -exec nixfmt {} +'
;;
*)
echo "❌ Unknown formatter: {{ FORMATTER }}."
echo "Available formatters:"
echo " auto (default) - Use nix fmt"
echo " nix - Use nix fmt explicitly"
echo " nix-fmt - Use nix-fmt tool"
echo " nixfmt-rfc-style - RFC-style formatter"
echo " nixpkgs-fmt - Official Nixpkgs formatter"
echo " alejandra - Modern, opinionated formatter"
echo " nixfmt - Classic formatter"
exit 1
;;
esac
echo "✅ Formatting completed!"
[doc('Check if sops-nix activated successfully')]
check-sops:
scripts/check-sops.sh
[doc('Update nix-secrets repository')]
update-nix-secrets:
@(cd ../nix-secrets && git fetch && git rebase > /dev/null) || true
nix flake update nix-secrets --timeout 5
[doc('Update flake.lock file')]
update:
just _nix-flake "update --refresh" ""
[doc('Update flake.lock file with nom output')]
update-nom:
just _nix-flake "update --refresh" "nom"
[doc('Update flake.lock file and save logs to specified file')]
update-to-file LOGFILE:
#!/usr/bin/env bash
echo "📝 Saving update logs to: {{ LOGFILE }}"
just _nix-flake "update --refresh" "" 2>&1 | tee "{{ LOGFILE }}"
echo "✅ Update completed. Logs saved to: {{ LOGFILE }}"
[doc('Update flake.lock file and save logs with timestamp')]
update-log:
#!/usr/bin/env bash
LOGFILE="update-$(date +%Y%m%d-%H%M%S).log"
echo "📝 Saving update logs to: $LOGFILE"
just _nix-flake "update --refresh" "" 2>&1 | tee "$LOGFILE"
echo "✅ Update completed. Logs saved to: $LOGFILE"
[doc('Commit updated flake.lock file')]
commit:
# Equivalent to: nix --experimental-features 'nix-command flakes' flake update --commit-lock-file |& nom
just _nix-flake "update --commit-lock-file" ""
[doc('Check flake for errors')]
check:
just _nix-flake "check"
[doc('Check flake for errors with nom output')]
check-nom:
just _nix-flake "check" "nom"
[doc('Check flake for errors and save logs to specified file')]
check-to-file LOGFILE:
#!/usr/bin/env bash
echo "📝 Saving check logs to: {{ LOGFILE }}"
just _nix-flake "check" "" 2>&1 | tee "{{ LOGFILE }}"
echo "✅ Check completed. Logs saved to: {{ LOGFILE }}"
[doc('Check flake for errors and save logs with timestamp')]
check-log:
#!/usr/bin/env bash
LOGFILE="check-$(date +%Y%m%d-%H%M%S).log"
echo "📝 Saving check logs to: $LOGFILE"
just _nix-flake "check" "" 2>&1 | tee "$LOGFILE"
echo "✅ Check completed. Logs saved to: $LOGFILE"
[doc('Build darwin configuration without switching')]
build: _check-non-root _check-nix
just _darwin-rebuild "build"
[doc('Build darwin configuration with nom output')]
build-nom: _check-non-root _check-nix
just _darwin-rebuild "build" "nom"
[doc('Build darwin configuration and save logs to specified file')]
build-to-file LOGFILE: _check-non-root _check-nix
#!/usr/bin/env bash
echo "📝 Saving build logs to: {{ LOGFILE }}"
just _darwin-rebuild "build" "" 2>&1 | tee "{{ LOGFILE }}"
echo "✅ Build completed. Logs saved to: {{ LOGFILE }}"
[doc('Build darwin configuration and save logs with timestamp')]
build-log: _check-non-root _check-nix
#!/usr/bin/env bash
LOGFILE="build-$(date +%Y%m%d-%H%M%S).log"
echo "📝 Saving build logs to: $LOGFILE"
just _darwin-rebuild "build" "" 2>&1 | tee "$LOGFILE"
echo "✅ Build completed. Logs saved to: $LOGFILE"
[doc('Build darwin configuration and show diff with nvd')]
build-diff: _check-non-root _check-nix
#!/usr/bin/env bash
echo "🔨 Building darwin configuration..."
darwin-rebuild build --print-build-logs --flake '.#{{ HOSTNAME }}'
if [ -e /run/current-system ]; then
echo ""
echo "📊 Comparing package versions..."
nvd --nix-bin-dir="$(dirname "$(command -v nix)")" --color=always diff /run/current-system result
else
echo "⚠️ No current system found (initial installation?)"
fi
[doc('Build darwin configuration and show diff with nvd (using nom)')]
build-diff-nom: _check-non-root _check-nix
#!/usr/bin/env bash
echo "🔨 Building darwin configuration..."
darwin-rebuild build --print-build-logs --flake '.#{{ HOSTNAME }}' |& nom
if [ -e /run/current-system ]; then
echo ""
echo "📊 Comparing package versions..."
nvd --nix-bin-dir="$(dirname "$(command -v nix)")" --color=always diff /run/current-system result
else
echo "⚠️ No current system found (initial installation?)"
fi
[doc('Check darwin-rebuild configuration')]
check-darwin: _check-non-root
#!/usr/bin/env bash
echo "✅ Checking darwin configuration..."
sudo darwin-rebuild check --flake ".#{{ HOSTNAME }}" --show-trace
[doc('Switch system configuration (recommended)')]
switch: _check-non-root _check-nix
just _switch-workflow
[doc('Switch system configuration without running tests (faster)')]
switch-fast: _check-non-root _check-nix
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
just _separator
echo "🔍 Checking flake (without tests)..."
nix {{ NIX_FLAGS_NO_TESTS }} flake check --print-build-logs
just _separator
just _ensure-darwin-rebuild
just _separator
echo "🚀 Switching system configuration (skipping tests)..."
sudo darwin-rebuild switch --print-build-logs --flake '.#{{ HOSTNAME }}' --option check false
just _separator
echo "✅ Fast system switch completed!"
[doc('Switch system configuration without running tests with nom output (faster)')]
switch-fast-nom: _check-non-root _check-nix
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
just _separator
echo "🔍 Checking flake (without tests)..."
nix {{ NIX_FLAGS_NO_TESTS }} flake check --log-format internal-json --verbose --print-build-logs | nom --json
just _separator
just _ensure-darwin-rebuild
just _separator
echo "🚀 Switching system configuration (skipping tests)..."
sudo darwin-rebuild switch --print-build-logs --flake '.#{{ HOSTNAME }}' --option check false | nom
just _separator
echo "✅ Fast system switch with nom completed!"
[doc('Switch system configuration with nom output')]
switch-nom: _check-non-root _check-nix
just _switch-workflow "nom"
[doc('Switch system configuration and save logs to specified file')]
switch-to-file LOGFILE: _check-non-root _check-nix
#!/usr/bin/env bash
echo "📝 Saving switch logs to: {{ LOGFILE }}"
just _switch-workflow "" 2>&1 | tee "{{ LOGFILE }}"
echo "✅ Switch completed. Logs saved to: {{ LOGFILE }}"
[doc('Switch system configuration and save logs with timestamp')]
switch-log: _check-non-root _check-nix
#!/usr/bin/env bash
LOGFILE="switch-$(date +%Y%m%d-%H%M%S).log"
echo "📝 Saving switch logs to: $LOGFILE"
just _switch-workflow "" 2>&1 | tee "$LOGFILE"
echo "✅ Switch completed. Logs saved to: $LOGFILE"
# =============================================================================
# NH-specific Commands
# =============================================================================
[doc('Build darwin configuration using nh')]
build-nh: _check-non-root _check-nix
just _nh-darwin "build"
[doc('Build darwin configuration using nh with nom output')]
build-nh-nom: _check-non-root _check-nix
just _nh-darwin "build" "nom"
[doc('Build darwin configuration using nh and save logs to specified file')]
build-nh-to-file LOGFILE: _check-non-root _check-nix
#!/usr/bin/env bash
echo "📝 Saving nh build logs to: {{ LOGFILE }}"
just _nh-darwin "build" "" "{{ LOGFILE }}"
echo "✅ NH build completed. Logs saved to: {{ LOGFILE }}"
[doc('Build darwin configuration using nh and save logs with timestamp')]
build-nh-log: _check-non-root _check-nix
#!/usr/bin/env bash
LOGFILE="build-nh-$(date +%Y%m%d-%H%M%S).log"
echo "📝 Saving nh build logs to: $LOGFILE"
just _nh-darwin "build" "" "$LOGFILE"
echo "✅ NH build completed. Logs saved to: $LOGFILE"
[doc('Switch system configuration using nh')]
switch-nh: _check-non-root _check-nix
just _switch-nh-workflow
[doc('Switch system configuration using nh with nom output')]
switch-nh-nom: _check-non-root _check-nix
just _switch-nh-workflow "nom"
[doc('Switch system configuration using nh and save logs to specified file')]
switch-nh-to-file LOGFILE: _check-non-root _check-nix
#!/usr/bin/env bash
echo "📝 Saving nh switch logs to: {{ LOGFILE }}"
just _switch-nh-workflow "" "{{ LOGFILE }}"
echo "✅ NH switch completed! Logs saved to: {{ LOGFILE }}"
[doc('Switch system configuration using nh and save logs with timestamp')]
switch-nh-log: _check-non-root _check-nix
#!/usr/bin/env bash
LOGFILE="switch-nh-$(date +%Y%m%d-%H%M%S).log"
echo "📝 Saving nh switch logs to: $LOGFILE"
just _switch-nh-workflow "" "$LOGFILE"
echo "✅ NH switch completed! Logs saved to: $LOGFILE"
[doc('Update flake and switch system configuration using nh')]
update-switch-nh: _check-non-root _check-nix
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
just _separator
echo "📦 Updating flake..."
just _nix-flake "update"
just _switch-nh-workflow
[doc('Update flake and switch system configuration using nh with nom output')]
update-switch-nh-nom: _check-non-root _check-nix
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
just _separator
echo "📦 Updating flake..."
just _nix-flake "update" "nom"
just _switch-nh-workflow "nom"
[doc('Update flake.lock file using nh')]
update-nh:
#!/usr/bin/env bash
if command -v nh 1>/dev/null 2>&1; then
echo "🔨 Using nh for update..."
nh home switch --update .
else
echo "❌ nh is not available, falling back to regular update."
just update
fi
[doc('Update flake.lock file using nh with nom output')]
update-nh-nom:
#!/usr/bin/env bash
if command -v nh 1>/dev/null 2>&1; then
echo "🔨 Using nh for update with nom..."
just _nom "nh home switch --update ."
else
echo "❌ nh is not available, falling back to regular update with nom."
just update-nom
fi
[doc('Update flake and switch system configuration')]
update-switch: _check-non-root _check-nix
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
just _separator
echo "📦 Updating flake..."
just _nix-flake "update"
just _switch-workflow
[doc('Update flake and switch system configuration with nom output')]
update-switch-nom: _check-non-root _check-nix
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
just _separator
echo "📦 Updating flake..."
just _nix-flake "update" "nom"
just _switch-workflow "nom"
[doc('Update flake and switch system configuration with nom output (alias)')]
switch-update-nom: _check-non-root _check-nix
just update-switch-nom
[doc('Switch system configuration using morlana')]
switch-morlana: _check-non-root _check-nix
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
just _separator
echo "🔍 Checking flake..."
just _nix-flake "check"
just _separator
echo "🚀 Switching with morlana..."
nix run github:ryanccn/morlana -- switch --flake ~/github/sheeeng/nix
[doc('Show darwin-rebuild changelog')]
changelog:
#!/usr/bin/env bash
darwin-rebuild changelog --flake ".#{{ HOSTNAME }}"
[doc('Build with logs saved to file')]
build-with-logs: _check-non-root _check-nix
#!/usr/bin/env bash
LOGFILE="build-$(date +%Y%m%d-%H%M%S).log"
echo "📝 Saving build logs to: $LOGFILE"
just _darwin-rebuild "build" "nom" "$LOGFILE"
echo "✅ Build completed. Logs saved to: $LOGFILE"
[doc('Switch with logs saved to file')]
switch-with-logs: _check-non-root _check-nix
#!/usr/bin/env bash
LOGFILE="switch-$(date +%Y%m%d-%H%M%S).log"
echo "📝 Saving switch logs to: $LOGFILE"
just _switch-workflow "nom" "$LOGFILE"
echo "✅ Switch completed. Logs saved to: $LOGFILE"
[doc('Build with verbose debugging and logs')]
build-debug: _check-non-root _check-nix
#!/usr/bin/env bash
LOGFILE="build-debug-$(date +%Y%m%d-%H%M%S).log"
echo "🐛 Building with debug info. Logs saved to: $LOGFILE"
CMD="darwin-rebuild build --print-build-logs --show-trace --keep-failed --flake '.#{{ HOSTNAME }}'"
eval "$CMD" 2>&1 | tee "$LOGFILE"
[doc('Show recent build failures and their logs')]
show-failed-builds:
#!/usr/bin/env bash
echo "🔍 Looking for failed builds in /tmp..."
find /tmp -name "nix-build-*" -type d 2>/dev/null | head -10
echo ""
echo "💡 To examine a failed build:"
echo " cd /tmp/nix-build-<hash>"
echo " ls -la"
[doc('Set experimental features for Nix')]
set-experimental-features: _check-must-be-root
#!/usr/bin/env bash
if grep --quiet "experimental-features =" /etc/nix/nix.conf; then
echo "✅ Experimental features already configured."
else
echo "⚙️ Setting experimental features..."
echo "experimental-features = nix-command flakes" | sudo tee --append /etc/nix/nix.conf >/dev/null
echo "✅ Experimental features configured."
fi
[doc('Set GitHub token for higher rate limit')]
set-github-token: _check-must-be-root
#!/usr/bin/env bash
if [ -z "${GITHUB_TOKEN_NIX:-}" ]; then
echo "❌ GITHUB_TOKEN_NIX is not set or empty."
echo "💡 Please set the GITHUB_TOKEN_NIX environment variable."
exit 1
fi
echo "✅ Token is set and its length is ${#GITHUB_TOKEN_NIX}."
if grep --quiet "^access-tokens = github.com=" /etc/nix/nix.conf; then
echo "⚙️ Replacing existing GitHub token configuration..."
nix-shell --packages gnused --run "sudo sed --in-place 's|^access-tokens = github.com=.*|access-tokens = github.com=${GITHUB_TOKEN_NIX}|' /etc/nix/nix.conf"
echo "✅ GitHub token configured."
else
echo "⚙️ Adding GitHub token configuration..."
echo "access-tokens = github.com=${GITHUB_TOKEN_NIX}" | sudo tee --append /etc/nix/nix.conf >/dev/null
echo "✅ GitHub token configured."
fi