-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhetzner.sh
55 lines (48 loc) · 1.4 KB
/
hetzner.sh
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
#!/usr/bin/env bash
set -xeEuo pipefail
trap 'echo "Error when executing $BASH_COMMAND at line $LINENO!" >&2' ERR
# Mount & boot from NixOS ISO before running this
# WARNING: this will erase your /dev/sda drive!
# can be started with: APPLY=1 HOST="<HOST>" bash <(curl -L 'https://raw.githubusercontent.com/nazarewk-iac/nix-configs/main/hetzner.sh')
if [ "${APPLY:-}" = 1 ] ; then
cmd () { "$@"; }
else
cmd () { echo "$@"; }
set +x
fi
to_file() {
if [ "${APPLY:-}" = 1 ] ; then
tee "$@"
else
tee
fi
}
installer_update() {
if [ ! -e /etc/nixos/configuration.bkp.nix ] ; then
bash <(curl -L 'https://raw.githubusercontent.com/nazarewk-iac/nix-configs/main/installer-update.sh')
fi
}
script=(
mklabel msdos
mkpart primary ext4 1MiB -1Mib
)
cmd installer_update
if mountpoint /mnt ; then
cmd umount /mnt
fi
cmd parted -s /dev/sda -- "${script[@]}"
cmd partprobe
cmd mkfs.ext4 /dev/sda1
cmd mount /dev/sda1 /mnt
checkout_dir=/mnt/home/kdn/dev/github.com/nazarewk-iac
repo_dir="${checkout_dir}/nix-configs"
cmd mkdir -p "${checkout_dir}"
if [ -d "${repo_dir}" ] ; then
cmd git pull "${repo_dir}"
else
cmd git clone https://github.com/nazarewk-iac/nix-configs.git "${repo_dir}"
fi
cmd chown -R 1000:100 /mnt/home/kdn
cmd mkdir -p /mnt/etc/nixos
cmd ln -s "${repo_dir/"/mnt"/"../.."}/flake.nix" /mnt/etc/nixos/flake.nix
cmd nixos-install --impure --show-trace --root /mnt --flake "${repo_dir}#${HOST}"