-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Justfile
401 lines (334 loc) · 9.11 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
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
# just is a command runner, Justfile is very similar to Makefile, but simpler.
# Use nushell for shell commands
# To use this justfile, you need to enter a shell with just & nushell installed:
#
# nix shell nixpkgs#just nixpkgs#nushell
set shell := ["nu", "-c"]
utils_nu := absolute_path("utils.nu")
############################################################################
#
# Common commands(suitable for all machines)
#
############################################################################
# List all the just commands
default:
@just --list
# Run eval tests
[group('nix')]
test:
nix eval .#evalTests --show-trace --print-build-logs --verbose
# Update all the flake inputs
[group('nix')]
up:
nix flake update
# Update specific input
# Usage: just upp nixpkgs
[group('nix')]
upp input:
nix flake update {{input}}
# List all generations of the system profile
[group('nix')]
history:
nix profile history --profile /nix/var/nix/profiles/system
# Open a nix shell with the flake
[group('nix')]
repl:
nix repl -f flake:nixpkgs
# remove all generations older than 7 days
# on darwin, you may need to switch to root user to run this command
[group('nix')]
clean:
sudo nix profile wipe-history --profile /nix/var/nix/profiles/system --older-than 7d
# Garbage collect all unused nix store entries
[group('nix')]
gc:
# garbage collect all unused nix store entries(system-wide)
sudo nix-collect-garbage --delete-older-than 7d
# garbage collect all unused nix store entries(for the user - home-manager)
# https://github.com/NixOS/nix/issues/8508
nix-collect-garbage --delete-older-than 7d
# Enter a shell session which has all the necessary tools for this flake
[linux]
[group('nix')]
shell:
nix shell nixpkgs#git nixpkgs#neovim nixpkgs#colmena
# Enter a shell session which has all the necessary tools for this flake
[macos]
[group('nix')]
shell:
nix shell nixpkgs#git nixpkgs#neovim
[group('nix')]
fmt:
# format the nix files in this repo
nix fmt
# Show all the auto gc roots in the nix store
[group('nix')]
gcroot:
ls -al /nix/var/nix/gcroots/auto/
# Verify all the store entries
# Nix Store can contains corrupted entries if the nix store object has been modified unexpectedly.
# This command will verify all the store entries,
# and we need to fix the corrupted entries manually via `sudo nix store delete <store-path-1> <store-path-2> ...`
[group('nix')]
verify-store:
nix store verify --all
# Repair Nix Store Objects
[group('nix')]
repair-store *paths:
nix store repair {{paths}}
############################################################################
#
# NixOS Desktop related commands
#
############################################################################
[linux]
[group('desktop')]
hypr mode="default":
#!/usr/bin/env nu
use {{utils_nu}} *;
nixos-switch ai-hyprland {{mode}}
[linux]
[group('desktop')]
s-hypr mode="default":
#!/usr/bin/env nu
use {{utils_nu}} *;
nixos-switch shoukei-hyprland {{mode}}
############################################################################
#
# Darwin related commands, harmonica is my macbook pro's hostname
#
############################################################################
[macos]
[group('desktop')]
darwin-set-proxy:
sudo python3 scripts/darwin_set_proxy.py
sleep 1sec
[macos]
[group('desktop')]
darwin-rollback:
#!/usr/bin/env nu
use {{utils_nu}} *;
darwin-rollback
# Deploy to harmonica(macOS host)
[macos]
[group('desktop')]
ha mode="default":
#!/usr/bin/env nu
use {{utils_nu}} *;
darwin-build "harmonica" {{mode}};
darwin-switch "harmonica" {{mode}}
# Depoly to fern(macOS host)
[macos]
[group('desktop')]
fe mode="default": darwin-set-proxy
#!/usr/bin/env nu
use {{utils_nu}} *;
darwin-build "fern" {{mode}};
darwin-switch "fern" {{mode}}
# Reset launchpad to force it to reindex Applications
[macos]
[group('desktop')]
reset-launchpad:
defaults write com.apple.dock ResetLaunchPad -bool true
killall Dock
############################################################################
#
# Homelab - Kubevirt Cluster related commands
#
############################################################################
# Remote deployment via colmena
[linux]
[group('homelab')]
col tag:
colmena apply --on '@{{tag}}' --verbose --show-trace
[linux]
[group('homelab')]
local name mode="default":
#!/usr/bin/env nu
use {{utils_nu}} *;
nixos-switch {{name}} {{mode}}
# Build and upload a vm image
[linux]
[group('homelab')]
upload-vm name mode="default":
#!/usr/bin/env nu
use {{utils_nu}} *;
upload-vm {{name}} {{mode}}
# Deploy all the KubeVirt nodes(Physical machines running KubeVirt)
[linux]
[group('homelab')]
lab:
colmena apply --on '@virt-*' --verbose --show-trace
[linux]
[group('homelab')]
shoryu:
colmena apply --on '@kubevirt-shoryu' --verbose --show-trace
[linux]
[group('homelab')]
shoryu-local mode="default":
#!/usr/bin/env nu
use {{utils_nu}} *;
nixos-switch kubevirt-shoryu {{mode}}
[linux]
[group('homelab')]
shushou:
colmena apply --on '@kubevirt-shushou' --verbose --show-trace
[linux]
[group('homelab')]
shushou-local mode="default":
#!/usr/bin/env nu
use {{utils_nu}} *;
nixos-switch kubevirt-shushou {{mode}}
[linux]
[group('homelab')]
youko:
colmena apply --on '@kubevirt-youko' --verbose --show-trace
[linux]
[group('homelab')]
youko-local mode="default":
#!/usr/bin/env nu
use {{utils_nu}} *;
nixos-switch kubevirt-youko {{mode}}
############################################################################
#
# Commands for other Virtual Machines
#
############################################################################
# Build and upload a vm image
[linux]
[group('homelab')]
upload-idols mode="default":
#!/usr/bin/env nu
use {{utils_nu}} *;
upload-vm aquamarine {{mode}}
upload-vm ruby {{mode}}
upload-vm kana {{mode}}
[linux]
[group('homelab')]
aqua:
colmena apply --on '@aqua' --verbose --show-trace
[linux]
[group('homelab')]
aqua-local mode="default":
#!/usr/bin/env nu
use {{utils_nu}} *;
nixos-switch aquamarine {{mode}}
[linux]
[group('homelab')]
ruby:
colmena apply --on '@ruby' --verbose --show-trace
[linux]
[group('homelab')]
ruby-local mode="default":
#!/usr/bin/env nu
use {{utils_nu}} *;
nixos-switch ruby {{mode}}
[linux]
[group('homelab')]
kana:
colmena apply --on '@kana' --verbose --show-trace
[linux]
[group('homelab')]
kana-local mode="default":
#!/usr/bin/env nu
use {{utils_nu}} *;
nixos-switch kana {{mode}}
############################################################################
#
# Kubernetes related commands
#
############################################################################
# Build and upload a vm image
[linux]
[group('homelab')]
upload-k3s-prod mode="default":
#!/usr/bin/env nu
use {{utils_nu}} *;
upload-vm k3s-prod-1-master-1 {{mode}};
upload-vm k3s-prod-1-master-2 {{mode}};
upload-vm k3s-prod-1-master-3 {{mode}};
upload-vm k3s-prod-1-worker-1 {{mode}};
upload-vm k3s-prod-1-worker-2 {{mode}};
upload-vm k3s-prod-1-worker-3 {{mode}};
[linux]
[group('homelab')]
upload-k3s-test mode="default":
#!/usr/bin/env nu
use {{utils_nu}} *;
upload-vm k3s-test-1-master-1 {{mode}};
upload-vm k3s-test-1-master-2 {{mode}};
upload-vm k3s-test-1-master-3 {{mode}};
[linux]
[group('homelab')]
k3s-prod:
colmena apply --on '@k3s-prod-*' --verbose --show-trace
[linux]
[group('homelab')]
k3s-test:
colmena apply --on '@k3s-test-*' --verbose --show-trace
# =================================================
# Emacs related commands
# =================================================
[group('emacs')]
emacs-test:
doom clean
doom sync
[group('emacs')]
emacs-purge:
doom purge
doom clean
doom sync
[linux]
[group('emacs')]
emacs-reload:
doom sync
systemctl --user restart emacs.service
systemctl --user status emacs.service
emacs-plist-path := "~/Library/LaunchAgents/org.nix-community.home.emacs.plist"
[macos]
[group('emacs')]
emacs-reload:
doom sync
launchctl unload {{emacs-plist-path}}
launchctl load {{emacs-plist-path}}
tail -f ~/Library/Logs/emacs-daemon.stderr.log
# =================================================
#
# Other useful commands
#
# =================================================
[group('common')]
path:
$env.PATH | split row ":"
[group('common')]
trace-access app *args:
strace -f -t -e trace=file {{app}} {{args}} | complete | $in.stderr | lines | find -v -r "(/nix/store|/newroot|/proc)" | parse --regex '"(/.+)"' | sort | uniq
[linux]
[group('common')]
penvof pid:
sudo cat $"/proc/($pid)/environ" | tr '\0' '\n'
# Remove all reflog entries and prune unreachable objects
[group('git')]
ggc:
git reflog expire --expire-unreachable=now --all
git gc --prune=now
# Amend the last commit without changing the commit message
[group('git')]
game:
git commit --amend -a --no-edit
# Delete all failed pods
[group('k8s')]
del-failed:
kubectl delete pod --all-namespaces --field-selector="status.phase==Failed"
[linux]
[group('services')]
list-inactive:
systemctl list-units -all --state=inactive
[linux]
[group('services')]
list-failed:
systemctl list-units -all --state=failed
[linux]
[group('services')]
list-systemd:
systemctl list-units systemd-*