Repository navigation
Expand file tree
/
Copy pathquickstart.bash
More file actions
executable file
·70 lines (57 loc) · 2.23 KB
/
Copy pathquickstart.bash
File metadata and controls
executable file
·70 lines (57 loc) · 2.23 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
#!/usr/bin/env bash
set -euo pipefail
printf "Before running this script, make sure you have your age key accessible somewhere.\n"
printf "It must not be anywhere under /mnt, since that will be mounted over.\n"
read -p "Continue? (yes/no) " -r
if [[ "${REPLY}" != "yes" ]]; then
printf "Aborting...\n"
exit 1
fi
printf "Also this script formats your disks according to your configuration.\n"
read -p "Are you really sure? (yes/no) " -r
if [[ "${REPLY}" != "yes" ]]; then
printf "Aborting...\n"
exit 1
fi
printf "What host are you setting up?\n"
read -r hostname
printf "Where is your age key?\n"
read -r ageKeyFile
# 1. Create encryption key
printf "Creating encryption key file...\n"
sudo mkdir -p /persist/luks
secretFile=$(mktemp)
cat <<EOF > "${secretFile}"
# Replace this line with the encryption key for your disks
EOF
vim "${secretFile}"
sudo chown root:root "${secretFile}"
sudo mv "${secretFile}" /persist/luks/secret.key
# 2. Format disks
printf "Destructively formatting disks...\n"
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode destroy,format,mount --yes-wipe-all-disks --flake ".#${hostname}"
# 3. Create workspace and move nix-config
printf "Creating workspace and moving nix-config...\n"
sudo mkdir -p /mnt/persist/home/yeldir/querbeet/workspace
sudo chown -R 1000:100 /mnt/persist/home/yeldir
sudo mv ~/nix-config /mnt/persist/home/yeldir/querbeet/workspace/
cd /mnt/persist/home/yeldir/querbeet/workspace/nix-config
# 4. Create hostkey for initrd
printf "Creating hostkey for initrd...\n"
sudo mkdir -p /mnt/etc/ssh
sudo ssh-keygen -t ed25519 -N "" -f /mnt/etc/ssh/initrd
sudo chmod 600 /mnt/etc/ssh/initrd
# 5. Put age key in /mnt/persist/sops/age/keys.txt
printf "Bringing age key in position...\n"
sudo mkdir -p /mnt/persist/sops/age
sudo cp "${ageKeyFile}" /mnt/persist/sops/age/keys.txt
# 6. Move disk encryption key
printf "Moving disk encryption key...\n"
sudo mkdir -p /mnt/persist/luks
sudo cp /persist/luks/secret.key /mnt/persist/luks/secret.key
# 8. Install nixos
printf "Installing nixos...\n"
sudo nixos-install --flake ".#${hostname}"
printf "Now reboot.\n"
printf "After reboot, unlock luks manually once and regenerate initrd host key.\n"
printf "See step 4 in QUICKSTART.md\n"