forked from pbek/nixcfg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjustfile
263 lines (215 loc) · 6.97 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
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
# Use `just <recipe>` to run a recipe
# https://just.systems/man/en/
# By default, run the `--list` command
default:
@just --list
# Set default shell to bash
set shell := ["bash", "-c"]
# Variables
hostname := `hostname`
user := `whoami`
# Aliases
alias s := switch
alias ss := switch-simple
alias u := upgrade
alias c := cleanup
alias b := build
alias bh := build-on-home01
alias bc := build-on-caliban
alias fix-command-not-found-error := update-channels
alias nixfmt := nix-format
# Notify the user with neosay
@_notify text:
if test -f ~/.config/neosay/config.json; then echo "❄️ nixcfg {{ text }}" | neosay; fi
[group('build')]
test:
sudo nixos-rebuild test --flake .#{{ hostname }} -L
# https://nix.dev/manual/nix/2.18/command-ref/new-cli/nix3-flake-check.html
[group('build')]
check:
nix flake check --no-build --keep-going
[group('build')]
nix-switch:
sudo nixos-rebuild switch --flake .#{{ hostname }} -L
# Build and switch to the new configuration for the current host (no notification)
[group('build')]
switch-simple:
nh os switch -H {{ hostname }} .
# Build and switch to the new configuration for the current host (with notification, use "--max-jobs 1" to restict downloads)
[group('build')]
switch args='':
#!/usr/bin/env bash
echo "❄️ Running switch for {{ hostname }}..."
start_time=$(date +%s)
nh os switch -H {{ hostname }} . -- {{ args }}
end_time=$(date +%s)
exit_code=$?
runtime=$((end_time - start_time))
if [ $runtime -gt 10 ]; then
just _notify "switch finished on {{ hostname }}, exit code: $exit_code (runtime: ${runtime}s)"
fi
# Build the current host with nix-rebuild
[group('build')]
nix-build:
sudo nixos-rebuild build --flake .#{{ hostname }}
# Build a host with nh
[group('build')]
_build hostname:
nh os build -H {{ hostname }} .
just _notify "build finished on {{ hostname }}"
# Build the current host with nh
[group('build')]
build: (_build hostname)
# Build the current host on the Caliban host
[group('build')]
build-on-caliban:
nixos-rebuild --build-host [email protected] --flake .#{{ hostname }} build
just _notify "build-on-caliban finished on {{ hostname }}"
# Build and deploy the astra host
[group('build')]
build-deploy-astra:
nixos-rebuild --target-host [email protected] --flake .#astra build
just _notify "build-deploy-astra finished on {{ hostname }}"
# Build and deploy the ally2 host
[group('build')]
build-deploy-ally2:
nixos-rebuild --target-host [email protected] --flake .#ally2 build
just _notify "build-deploy-ally2 finished on {{ hostname }}"
# Build the current host on the Sinope host
[group('build')]
build-on-sinope:
nixos-rebuild --build-host [email protected] --flake .#{{ hostname }} build
just _notify "build-on-sinope finished on {{ hostname }}"
# Build with nh on caliban (--build-host" not found)
[group('build')]
nh-build-on-caliban:
nh os build -H {{ hostname }} . -- --build-host [email protected]
# Build the current host on the Home01 host (use "--max-jobs 1" to restict downloads)
[group('build')]
build-on-home01 args='':
nixos-rebuild --build-host [email protected] --flake .#{{ hostname }} build {{ args }}
just _notify "build-on-home01 finished on {{ hostname }}"
# Build with nh on homew01 (--build-host" not found)
[group('build')]
nh-build-on-home01:
nh os build -H {{ hostname }} . -- --build-host [email protected]
# Update the flakes
[group('build')]
update:
NIX_CONFIG="access-tokens = github.com=`cat ~/.secrets/github-token`" nix flake update
# Update the flakes and switch to the new configuration
[group('build')]
upgrade: update && switch
# Rebuild the current host
[group('build')]
flake-rebuild-current:
sudo nixos-rebuild switch --flake .#{{ hostname }}
# Update the flakes
[group('build')]
flake-update:
nix flake update
# Clean up the system to free up space
[group('maintenance')]
[confirm("Are you sure you want to clean up the system?")]
cleanup:
duf && \
sudo journalctl --vacuum-time=3d && \
docker system prune -f && \
rm -rf ~/.local/share/Trash/* && \
sudo nix-collect-garbage -d && \
nix-collect-garbage -d && \
duf
# Repair the nix store
[group('maintenance')]
repair-store:
sudo nix-store --verify --check-contents --repair
# List the generations
[group('maintenance')]
list-generations:
nix profile history --profile /nix/var/nix/profiles/system
# Garbage collect the nix store to free up space
[group('maintenance')]
optimize-store:
duf && \
nix store optimise && \
duf
# Do firmware updates
[group('maintenance')]
fwup:
-fwupdmgr refresh
fwupdmgr update
# Open a terminal with the nixcfg session
[group('maintenance')]
term:
zellij --layout term.kdl attach nixcfg -c
# Kill the nixcfg session
[group('maintenance')]
term-kill:
zellij delete-session nixcfg -f
# Replace the current fish shell with a new one
[group('build')]
fish-replace:
exec fish
# Use statix to check the nix files
[group('linter')]
linter-check:
statix check
# Use statix to fix the nix files
[group('linter')]
linter-fix:
statix fix
# Fix "command not found" error
[group('maintenance')]
update-channels:
sudo nix-channel --update
# Build the Venus host with nix
[group('build')]
nix-build-venus:
nixos-rebuild --flake .#venus build
# Build the Venus host with nh
[group('build')]
build-venus: (_build "venus")
# Show home-manager logs
[group('maintenance')]
home-manager-logs:
sudo journalctl --since today | grep "hm-activate-" | bat
# Show home-manager service status
[group('maintenance')]
home-manager-status:
systemctl status home-manager-{{ user }}.service
# Restart nix-serve (use on home01)
[group('maintenance')]
home01-restart-nix-serve:
systemctl restart nix-serve
# Run a fish shell with all needed tools
[group('maintenance')]
shell:
nix-shell --run fish
# Get the nix hash of a QOwnNotes release
[group('qownnotes')]
qownnotes-hash:
#!/usr/bin/env bash
set -euxo pipefail
version=$(gum input --placeholder "QOwnNotes version number")
url="https://github.com/pbek/QOwnNotes/releases/download/v${version}/qownnotes-${version}.tar.xz"
nix-prefetch-url "$url" | xargs nix hash convert --hash-algo sha256
# Get the reverse dependencies of a nix store path
[group('maintenance')]
nix-store-reverse-dependencies:
#!/usr/bin/env bash
set -euxo pipefail
nixStorePath=$(gum input --placeholder "Nix store path (e.g. /nix/store/hbldxn007k0y5qidna6fg0x168gnsmkj-botan-2.19.5.drv)")
nix-store --query --referrers "$nixStorePath"
# Format the nix files
[group('maintenance')]
nix-format:
nix-shell -p fd nixfmt-rfc-style --run "fd -e nix --exec-batch nixfmt"
# Format all justfiles
[group('linter')]
just-format:
#!/usr/bin/env bash
# Find all files named "justfile" recursively and run just --fmt --unstable on them
find . -type f -name "justfile" -print0 | while IFS= read -r -d '' file; do
echo "Formatting $file"
just --fmt --unstable -f "$file"
done