-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
138 lines (118 loc) · 3.46 KB
/
Copy pathjustfile
File metadata and controls
138 lines (118 loc) · 3.46 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
set quiet
set shell := ['zsh', '-cu']
os := os()
rebuild := if os == 'linux' { 'nixos-rebuild' } else if os == 'macos' { 'darwin-rebuild' } else { error('Unsupported OS: ' + os) }
sudo := if os == 'linux' { 'sudo' } else { '' }
alias b := build
alias c := check
alias f := format
alias h := history
alias s := search
alias u := update
alias up := update
[private]
default:
just -ul --list-heading ''
#
[group('rebuild')]
[private]
rebuild prefix arg *opts:
#!/usr/bin/env zsh
set -euo pipefail
h=$(hostname)
if { fd -gqt d -d 1 $h ~/git/dotfiles/hosts } {
{{ prefix }} {{ rebuild }} {{ arg }} --flake ~/git/dotfiles#$h {{ opts }}
} else {
echo "No config for host: $h"
exit 1
}
# Build and activate the host flake
[group('rebuild')]
switch *opts: (rebuild 'sudo' 'switch' opts)
# Build the host flake, and make it the boot default
[group('rebuild')]
[linux]
boot *opts: (rebuild 'sudo' 'boot' opts)
# Build and activate the host flake, and revert on boot
[group('rebuild')]
[linux]
test *opts: (rebuild 'sudo' 'test' opts)
# Build the host flake
[group('rebuild')]
build *opts: (rebuild '' 'build' opts)
#
# Rollback to the previous generation
[group('history')]
rollback:
{{ sudo }} {{ rebuild }} --rollback
# List available generations
[group('history')]
history limit='10':
#!/usr/bin/env zsh
set -euo pipefail
l={{ if limit == '0' { '+1' } else { limit } }}
# TODO: actually get current gen instead of the most recent
if [[ {{ os }} == linux ]] {
g=$({{ rebuild }} list-generations | tail +2 | tac | tail -n $l |
rg -w '([[:xdigit:]]{7})([[:xdigit:]]{33,})' -r '$1' |
rg '\b {2,}' -r $'\t')
column -tc $COLUMNS -s $'\t' -N Gen,Date,NixOS,Kernel,Rev,Spec \
<<<"$(head -n -1 <<<$g)
{{ CYAN }}${$(tail -1 <<<$g)/current}{{ NORMAL }}"
} else {
g=$(sudo {{ rebuild }} --list-generations | tail -n $l)
print -aC 3 Gen Date ' ' ${=$(head -n -1 <<<$g)} \
'{{ CYAN }}'${(@)$(tail -1 <<<$g)[1,3]}'{{ NORMAL }}'
}
# Delete generations older than input days
[confirm]
[group('history')]
wipe-history days:
{{ sudo }} nix profile wipe-history \
--profile /nix/var/nix/profiles/system \
--older-than {{ days }}d
#
# Run all flake checks
[group('util')]
check:
#!/usr/bin/env zsh
set -uo pipefail
{ e=$(unbuffer nix flake check --log-lines 0 ~/git/dotfiles# \
>&1 >&3 1>/dev/null 3>&- |& tail -1)
} 3>&1
c=$?
if (( c )) {
d=$(rg -o '/nix/store/[0-9a-z]{32}-[-.+_?=0-9a-zA-Z]+.drv' <<<$e)
if [[ -n $d ]] { nix log $d | delta --paging never }
}
exit $c
# Format all files
[group('util')]
format:
nix fmt ~/git/dotfiles
# Start a nix REPL with nixpkgs loaded
[group('util')]
repl:
nix repl -f flake:nixpkgs
# Update the nixpkgs index
[group('util')]
index:
nix-index
# Search for packages and package outputs
[group('util')]
search pattern *args:
#!/usr/bin/env zsh
set -euo pipefail
o=$(nix-locate -rw '{{ pattern }}' {{ args }} | sort -b)
r() rg --passthru -U $(rg '(.)' -r '$1\s*' <<<'{{ pattern }}')
if [[ -z ${=o} ]] exit 0
if [[ {{ os }} == linux ]] {
rg --passthru -w ' {2,}' -r ' ' <<<$o |
column -tc $COLUMNS -N Package,Size,Type,Path -W Path | r
} else {
print -aC 4 Package Size Type Path ${=o} | r
}
# Update flake lockfile for all or specified inputs
[group('util')]
update *args:
nix flake update {{ args }}