-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjustfile
124 lines (109 loc) · 3.63 KB
/
justfile
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
# Variables
hostname := `hostname`
flake_dir := env_var_or_default("FLAKE_DIR", "~/.config/nixos")
flake_url := env_var_or_default("FLAKE_URL", "github:airone01/flake")
# Default recipe to display help
default:
@just --list
# Build and switch to a new configuration
switch host=hostname *args="": check-dirty
#!/usr/bin/env bash
set -euo pipefail
echo "🔄 Rebuilding system for {{host}}..."
sudo nixos-rebuild switch --flake {{flake_dir}}#{{host}} {{args}} 2>&1 | tee nixos-switch.log || (
grep --color error nixos-switch.log && false
)
echo "✅ System successfully rebuilt!"
# Build and test configuration without switching
test host=hostname *args="": check-dirty
#!/usr/bin/env bash
set -euo pipefail
echo "🧪 Testing configuration for {{host}}..."
nixos-rebuild test --flake {{flake_dir}}#{{host}} {{args}} 2>&1 | tee nixos-test.log || (
grep --color error nixos-test.log && false
)
echo "✅ Test build successful!"
# Build an ISO image
iso system="ursamajor" format="install-iso":
#!/usr/bin/env bash
set -euo pipefail
echo "📀 Building {{format}} for {{system}}..."
nix build {{flake_dir}}#{{system}}-{{format}}
echo "✅ ISO build complete!"
# Update all flake inputs
update:
#!/usr/bin/env bash
set -euo pipefail
echo "⬆️ Updating flake inputs..."
nix flake update --flake {{flake_dir}}
echo "✅ Flake inputs updated!"
# Update specific flake input
update-input input:
#!/usr/bin/env bash
set -euo pipefail
echo "⬆️ Updating {{input}}..."
nix flake lock {{flake_dir}} --update-input {{input}}
echo "✅ {{input}} updated!"
# Format all nix files
fmt:
#!/usr/bin/env bash
set -euo pipefail
echo "🎨 Formatting nix files..."
find . -name "*.nix" -exec alejandra {} +
echo "✅ Formatting complete!"
# Check nix file formatting
fmt-check:
#!/usr/bin/env bash
set -euo pipefail
echo "🔍 Checking nix formatting..."
find . -name "*.nix" -exec alejandra --check {} +
echo "✅ Format check passed!"
# Run checks on the flake
check:
#!/usr/bin/env bash
set -euo pipefail
echo "🔍 Running flake checks..."
nix flake check {{flake_dir}}
echo "✅ All checks passed!"
# Clean old generations
clean generations="14d":
#!/usr/bin/env bash
set -euo pipefail
echo "🧹 Cleaning generations older than {{generations}}..."
sudo nix-collect-garbage --delete-older-than {{generations}}
sudo /run/current-system/bin/switch-to-configuration switch
echo "✅ System cleaned!"
# Enter a development shell
develop shell="commitlint":
#!/usr/bin/env bash
set -euo pipefail
echo "🚀 Launching {{shell}} development environment..."
nix develop {{flake_dir}}#{{shell}}
# Show the diff of staged nix files
show-diff:
git diff -U0 *.nix
# Internal recipe to check for dirty git state
[private]
check-dirty:
#!/usr/bin/env bash
if [ -n "$(git status --porcelain)" ]; then
echo "⚠️ Warning: Working directory is dirty. Uncommitted changes may be lost."
echo "Continue? [y/N]"
read -r response
if [[ ! "$response" =~ ^[Yy]$ ]]; then
echo "Operation cancelled."
exit 1
fi
fi
# Generate an initial SOPS key
sops-key:
#!/usr/bin/env bash
set -euo pipefail
echo "🔑 Generating SOPS age key..."
mkdir -p ~/.config/sops/age
if [ ! -f ~/.config/sops/age/keys.txt ]; then
age-keygen -o ~/.config/sops/age/keys.txt
echo "✅ Key generated at ~/.config/sops/age/keys.txt"
else
echo "⚠️ Key already exists at ~/.config/sops/age/keys.txt"
fi