-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjustfile
More file actions
152 lines (128 loc) · 3.68 KB
/
justfile
File metadata and controls
152 lines (128 loc) · 3.68 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
set allow-duplicate-recipes
import 'migadux/justfile'
import 'dns/config/justfile'
[private]
default:
@just --list
hostname := `hostname`
# {{{ Nixos rebuilds
[doc("Wrapper around `nixos-rebuild`")]
[group("nix")]
nixos-rebuild action="switch" host=hostname:
#!/usr/bin/env python3
import subprocess
host = "{{host}}"
users = {
'tethys': 'adrielus',
'lapetus': 'root',
'calypso': 'moon',
}
hosts = {
'tethys': 'tethys',
'lapetus': '192.168.10.1',
'calypso': 'calypso',
}
args = [
"nixos-rebuild",
"{{action}}",
"--show-trace",
"--accept-flake-config",
"--flake",
".#{{host}}",
"--no-reexec"
]
if host == "{{hostname}}":
print("🧬 Switching nixos configuration (locally) for '{{BLUE + host + NORMAL}}'")
args = [ "sudo", *args ]
else:
print("🧬 Switching nixos configuration (remotely) for '{{BLUE + host + NORMAL}}'")
args += [
"--target-host",
f"{users[host]}@{hosts[host]}",
"--sudo",
"--ask-sudo-password"
]
try:
subprocess.run(args, check=True)
print("🚀 All done!")
except KeyboardInterrupt:
print("🪓 Command cancelled")
# }}}
# {{{ Miscellaneous nix commands
[doc("Build the custom ISO provided by the flake")]
[group("nix")]
build-iso:
nix build .#nixosConfigurations.iso.config.system.build.isoImage
[doc("Bumps most flake inputs (not including things that are meant to be somewhat \"pinned\")")]
[group("nix")]
bump-common:
nix flake update --accept-flake-config \
nixpkgs \
nixpkgs-unstable \
nix-index-database \
neovim-nightly-overlay \
firefox-addons \
base16-schemes \
rose-pine-hyprcursor \
darkmatter-grub-theme \
home-manager \
stylix
# }}}
# {{{ Age / sops related thingies
[doc("Save the user's SSH key as a key usable by sops")]
[group("secrets")]
ssh-to-age:
@echo "📁 Creating sops directory" >&2
mkdir -p ~/.config/sops/age
@echo "🔑 Converting ssh key to age" >&2
ssh-to-age -private-key -i ~/.ssh/id_ed25519 > ~/.config/sops/age/keys.txt
[doc("Print the public age key used by sops on this machine")]
[group("secrets")]
age-public-key: ssh-to-age
@echo "🔑 Printing public age key" >&2
age-keygen -y ~/.config/sops/age/keys.txt
[doc("Rekey every secrets file in the repository")]
[group("secrets")]
sops-rekey:
#!/usr/bin/env python3
import glob
import subprocess
paths = glob.glob("./**/secrets.yaml", recursive=True)
for file in paths:
print(f"🔑 Rekeying {file}")
subprocess.run(["sops", "updatekeys", "--yes", file], check=True)
print(f"🚀 Successfully rekeyed {len(paths)} files!")
[doc("Export keys to the hermes USB device")]
[group("secrets")]
export-keys:
#!/usr/bin/env bash
set -euo pipefail # Fail on errors and whatnot
dir=/hermes/secrets/{{hostname}}/
mkdir -p $dir
cp /persist/state/etc/ssh/ssh* $dir
cp /home/*/.ssh/id* $dir
# Perhaps I should ask this as a prompt instead?
touch $dir/disk.key
echo "💫 Don't forget to provide a disk encryption key!"
# }}}
# {{{ Rsync
# TODO: move this to some sort of oneshot service
[doc("Give every machine access to the restic backups")]
[group("secrets")]
update-rsync-keys:
#!/usr/bin/env bash
set -euo pipefail # Fail on errors and whatnot
shopt -s nullglob # Make globs expand to [] if no match
keys=(hosts/nixos/*/keys/*.pub)
if [ "${#keys[@]}" -eq 0 ]; then
echo "❌ No SSH public keys found. Exiting." >&2
exit 1
fi
tmpfile=$(mktemp)
url=$(cat hosts/nixos/common/services/restic/url.txt)
echo "🔑 Copying ${#keys[@]} keys to $url"
cat ${keys[@]} > $tmpfile
scp $tmpfile $url:.ssh/authorized_keys
rm -f $tmpfile
echo "🚀 Successfully updated rsync.net SSH keys!"
# }}}