blob: ede837f29ef4cc80eca285b453652b44f163ce2a (
plain) (
blame)
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
|
# Show available recipes (default)
default:
@just --list
# ═══════════════════════════════════════════════════════════════════
# Setup
# ═══════════════════════════════════════════════════════════════════
# First-time machine setup: regenerate chezmoi config, install git hooks, deploy dotfiles, install base packages
init: _chezmoi-init _install-hooks apply (install "base") services-enable
# ═══════════════════════════════════════════════════════════════════
# Day-to-day
# ═══════════════════════════════════════════════════════════════════
# Reconcile everything: deploy dotfiles AND top up partially-installed package groups
sync: apply fix
# Deploy dotfiles (chezmoi apply)
apply:
chezmoi apply -S .
# Top up missing packages in groups that are already ≥50% installed (never installs new groups)
fix:
#!/bin/sh
for file in meta/*.txt; do
group=$(basename "$file" .txt)
pkgs=$(grep -v '^\s*#' "$file" | grep -v '^\s*$')
total=$(echo "$pkgs" | wc -l)
installed=0
for pkg in $pkgs; do
pacman -Qi "$pkg" >/dev/null 2>&1 && installed=$((installed + 1))
done
if [ $((installed * 2)) -ge "$total" ] && [ "$installed" -lt "$total" ]; then
echo ">>> topping up $group ($installed/$total installed)"
echo "$pkgs" | paru -S --needed --noconfirm --ask=4 -
fi
done
# ═══════════════════════════════════════════════════════════════════
# Inspection
# ═══════════════════════════════════════════════════════════════════
# Show package and dotfile drift (runs pkg-drift + dotfile-drift)
status: pkg-drift dotfile-drift
# Show package drift: missing packages in adopted groups + undeclared installed packages
pkg-drift:
#!/bin/sh
active=$(just _active-packages)
echo "=== Package drift ==="
echo "$active" | while read -r pkg; do
[ -z "$pkg" ] && continue
pacman -Qi "$pkg" >/dev/null 2>&1 || echo " missing: $pkg"
done
just undeclared | sed 's/^/ undeclared: /'
# Show dotfile drift (wraps 'chezmoi status')
dotfile-drift:
#!/bin/sh
echo "=== Dotfile drift ==="
chezmoi status -S . || true
# Print undeclared packages one per line, unindented (pipe to 'paru -Rs -' to remove them)
undeclared:
#!/bin/sh
active=$(just _active-packages)
pacman -Qqe | while read -r pkg; do
echo "$active" | grep -qxF "$pkg" || echo "$pkg"
done
# Show dotfile diffs; pass a path to limit to a single file (e.g. just diff .config/nvim/init.lua)
diff file="":
chezmoi diff -S . {{ file }}
# Resolve dotfile conflicts with a 3-way merge; pass a path for one file, or omit to merge all
merge file="":
#!/bin/sh
if [ -n '{{ file }}' ]; then
chezmoi merge -S . '{{ file }}'
else
chezmoi merge-all -S .
fi
# Show per-group install coverage; pass a group name for a per-package breakdown
groups group="":
#!/bin/sh
if [ -n '{{ group }}' ]; then
file="meta/{{ group }}.txt"
if [ ! -f "$file" ]; then
echo "error: $file does not exist" >&2
exit 1
fi
grep -v '^\s*#' "$file" | grep -v '^\s*$' | while read -r pkg; do
if pacman -Qi "$pkg" >/dev/null 2>&1; then
printf ' \033[32m✓\033[0m %s\n' "$pkg"
else
printf ' \033[31m✗\033[0m %s\n' "$pkg"
fi
done
exit 0
fi
for file in meta/*.txt; do
group=$(basename "$file" .txt)
pkgs=$(grep -v '^\s*#' "$file" | grep -v '^\s*$')
total=$(echo "$pkgs" | wc -l)
installed=0
for pkg in $pkgs; do
pacman -Qi "$pkg" >/dev/null 2>&1 && installed=$((installed + 1))
done
if [ "$installed" -eq "$total" ]; then
printf ' \033[32m✓\033[0m %-10s %d/%d\n' "$group" "$installed" "$total"
elif [ $((installed * 2)) -ge "$total" ]; then
printf ' \033[33m~\033[0m %-10s %d/%d\n' "$group" "$installed" "$total"
else
printf ' \033[31m✗\033[0m %-10s %d/%d\n' "$group" "$installed" "$total"
fi
done
# ═══════════════════════════════════════════════════════════════════
# Services
# ═══════════════════════════════════════════════════════════════════
# List curated systemd units (grouped by systemd-units/<group>.txt) with state
services:
#!/bin/sh
for file in systemd-units/*.txt; do
[ -f "$file" ] || continue
group=$(basename "$file" .txt)
echo "=== $group ==="
grep -v '^\s*#' "$file" | grep -v '^\s*$' | while read -r u; do
en=$(systemctl is-enabled "$u" 2>/dev/null); en=${en:-unknown}
ac=$(systemctl is-active "$u" 2>/dev/null); ac=${ac:-unknown}
case "$en" in
enabled|static|alias) c_en=32 ;;
disabled|masked|not-found) c_en=31 ;;
*) c_en=33 ;;
esac
case "$ac" in
active) c_ac=32 ;;
inactive|failed) c_ac=31 ;;
*) c_ac=33 ;;
esac
printf ' %-34s \033[%sm%-10s\033[0m \033[%sm%s\033[0m\n' "$u" "$c_en" "$en" "$c_ac" "$ac"
done
done
# Enable all curated systemd units (idempotent, soft-fail per unit)
services-enable:
#!/bin/sh
for file in systemd-units/*.txt; do
[ -f "$file" ] || continue
grep -v '^\s*#' "$file" | grep -v '^\s*$' | while read -r u; do
sudo systemctl enable --now "$u" \
|| echo " warn: could not enable $u" >&2
done
done
# Show drift between curated services and actually-enabled services
services-drift:
#!/bin/sh
echo "=== Service drift ==="
tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT
cat systemd-units/*.txt 2>/dev/null \
| grep -v '^\s*#' | grep -v '^\s*$' | sort -u > "$tmp/curated"
systemctl list-unit-files --state=enabled --no-legend 2>/dev/null \
| awk '{print $1}' | grep -vE '@\.' | sort -u > "$tmp/enabled"
comm -23 "$tmp/curated" "$tmp/enabled" | sed 's/^/ not-enabled: /'
comm -13 "$tmp/curated" "$tmp/enabled" | sed 's/^/ uncurated: /'
# ═══════════════════════════════════════════════════════════════════
# Package management
# ═══════════════════════════════════════════════════════════════════
# Install one or more package groups (e.g. just install base dev wayland)
install *groups:
#!/bin/sh
for group in {{ groups }}; do
grep -v '^\s*#' "meta/${group}.txt" | grep -v '^\s*$' | paru -S --needed --noconfirm --ask=4 -
done
# Install every package group
install-all:
#!/bin/sh
cat meta/*.txt | grep -v '^\s*#' | grep -v '^\s*$' | sort -u | paru -S --needed --noconfirm --ask=4 -
# Append one or more packages to a group list and install them (e.g. just add dev ripgrep fd)
add group +pkgs:
#!/bin/sh
set -eu
file="meta/{{ group }}.txt"
if [ ! -f "$file" ]; then
echo "error: $file does not exist" >&2
exit 1
fi
for pkg in {{ pkgs }}; do
if grep -qxF "$pkg" "$file"; then
echo "$pkg already in {{ group }}.txt"
else
echo "$pkg" >> "$file"
echo "added $pkg to {{ group }}.txt"
fi
done
paru -S --needed {{ pkgs }}
# Remove one or more packages from a group list (does NOT uninstall; the package may belong to other groups)
remove group +pkgs:
#!/bin/sh
set -eu
file="meta/{{ group }}.txt"
if [ ! -f "$file" ]; then
echo "error: $file does not exist" >&2
exit 1
fi
for pkg in {{ pkgs }}; do
if grep -qxF "$pkg" "$file"; then
sed -i "/^$(printf '%s' "$pkg" | sed 's/[]\/$*.^[]/\\&/g')\$/d" "$file"
echo "removed $pkg from {{ group }}.txt"
else
echo "$pkg not in {{ group }}.txt"
fi
done
# ═══════════════════════════════════════════════════════════════════
# Hidden helpers (run indirectly via the recipes above)
# ═══════════════════════════════════════════════════════════════════
_chezmoi-init:
chezmoi init -S .
_install-hooks:
git config core.hooksPath .githooks
# Print packages from groups that are ≥50% installed (adopted), one per line
_active-packages:
#!/bin/sh
for file in meta/*.txt; do
pkgs=$(grep -v '^\s*#' "$file" | grep -v '^\s*$')
total=$(echo "$pkgs" | wc -l)
installed=0
for pkg in $pkgs; do
pacman -Qi "$pkg" >/dev/null 2>&1 && installed=$((installed + 1))
done
if [ $((installed * 2)) -ge "$total" ]; then
echo "$pkgs"
fi
done | sort -u
|