aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorMark Nipper <nipsy@bitgnome.net>2024-04-11 01:37:43 -0700
committerMark Nipper <nipsy@bitgnome.net>2024-04-11 01:37:43 -0700
commit3a44b124561f544c229c0042cd0b91d055a33409 (patch)
treef466af390e895799192268a45f2516517487d672 /scripts
parent40d73be8797434f7a6e124ce64ae38cd28a06fd0 (diff)
downloadnix-3a44b124561f544c229c0042cd0b91d055a33409.tar
nix-3a44b124561f544c229c0042cd0b91d055a33409.tar.gz
nix-3a44b124561f544c229c0042cd0b91d055a33409.tar.bz2
nix-3a44b124561f544c229c0042cd0b91d055a33409.tar.lz
nix-3a44b124561f544c229c0042cd0b91d055a33409.tar.xz
nix-3a44b124561f544c229c0042cd0b91d055a33409.tar.zst
nix-3a44b124561f544c229c0042cd0b91d055a33409.zip
Add work VM and redo entire flake layout
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/install-with-disko68
1 files changed, 68 insertions, 0 deletions
diff --git a/scripts/install-with-disko b/scripts/install-with-disko
new file mode 100755
index 0000000..859a647
--- /dev/null
+++ b/scripts/install-with-disko
@@ -0,0 +1,68 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i zsh --packages rsync zsh
+
+setopt ERR_EXIT NO_UNSET PIPE_FAIL
+DIR="${0:h}"
+
+TARGET_HOST="${1:-}"
+TARGET_USER="${2:-nipsy}"
+
+if [[ "${USERNAME}" != "nixos" ]]; then
+ echo "ERROR! ${0:t} should be run as the nixos user from a NixOS installer." >&2
+ exit 1
+fi
+
+if [[ -z "$TARGET_HOST" ]]; then
+ echo "ERROR! ${0:t} requires a hostname as the first argument." >&2
+ exit 1
+fi
+
+if [[ ! -e "${DIR}/../hosts/${TARGET_HOST}/disks.nix" ]]; then
+ echo "ERROR! ${0:t} could not find the required ${DIR}/../hosts/${TARGET_HOST}/disks.nix." >&2
+ exit 1
+fi
+
+# Check if the machine we're provisioning is using an encrypted pool.
+# If it does, prompt for the passphrase, and write to a known location.
+if grep -q "data.keyfile" "${DIR}/../hosts/${TARGET_HOST}/disks.nix"; then
+ while true; do
+ echo -en "\n${TARGET_HOST} uses ZFS encryption. Enter a passphrase to encrypt your pool: "
+ read -s pass
+ echo -e '\n'
+
+ if [[ "${#pass}" -lt 8 ]]; then
+ echo 'ERROR! Passphrase must be at least 8 characters.' >&2
+ else
+ break
+ fi
+ done
+
+ echo -n "${pass}" > /tmp/data.keyfile && chmod 00600 /tmp/data.keyfile
+fi
+
+
+<<EOF
+++++++++ The disk(s) in ${TARGET_HOST} are about to get wiped!
+WARNING! NixOS will be re-installed on ${TARGET_HOST}.
+++++++++ This is a destructive operation!!!
+
+EOF
+
+read -q '?Are you sure? [y/N] '
+echo
+
+if [[ "${REPLY}" == "y" ]]; then
+ sudo true
+ sudo nix run github:nix-community/disko \
+ --extra-experimental-features "nix-command flakes" \
+ --no-write-lock-file \
+ -- \
+ --mode zap_create_mount \
+ "${DIR}/../hosts/${TARGET_HOST}/disks.nix"
+
+ # rsync NixOS configuration to target host file system and install the system
+ sudo mkdir -p /mnt/etc/nixos
+ sudo rsync -a --delete --exclude .git "${DIR}/.." /mnt/etc/nixos
+ cd /mnt/etc/nixos
+ sudo nixos-install --flake ".#${TARGET_HOST}"
+fi