aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorMark Nipper <nipsy@bitgnome.net>2024-11-11 23:43:16 -0800
committerMark Nipper <nipsy@bitgnome.net>2024-11-11 23:43:16 -0800
commit6f24102376a398057cf4acce1ea4069d88ce7cae (patch)
tree475907e8ba22bb0d295ac06a631c14624c054537 /scripts
parent4de233a16b1d08c747a6a4754ca10e9a1ec0fd9c (diff)
downloadnix-6f24102376a398057cf4acce1ea4069d88ce7cae.tar
nix-6f24102376a398057cf4acce1ea4069d88ce7cae.tar.gz
nix-6f24102376a398057cf4acce1ea4069d88ce7cae.tar.bz2
nix-6f24102376a398057cf4acce1ea4069d88ce7cae.tar.lz
nix-6f24102376a398057cf4acce1ea4069d88ce7cae.tar.xz
nix-6f24102376a398057cf4acce1ea4069d88ce7cae.tar.zst
nix-6f24102376a398057cf4acce1ea4069d88ce7cae.zip
Add remote install with disko script
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/remote-install-with-disko67
1 files changed, 67 insertions, 0 deletions
diff --git a/scripts/remote-install-with-disko b/scripts/remote-install-with-disko
new file mode 100755
index 0000000..c86f005
--- /dev/null
+++ b/scripts/remote-install-with-disko
@@ -0,0 +1,67 @@
+#!/usr/bin/env nix
+#!nix shell nixpkgs#rsync nixpkgs#zsh --command zsh
+
+setopt ERR_EXIT PIPE_FAIL
+
+# load module to parse command line arguments
+zmodload zsh/zutil
+
+# parse any possible additional drive declarations
+zparseopts -D -E -A opts -- h x
+
+# enable XTRACE shell option for full debugging output of scripts
+if (( ${+opts[-x]} )); then
+ set -x
+fi
+
+DIR="${0:h}"
+FLAKE="https://arrakis.bitgnome.net/nipsy/git/nix/"
+HOSTNAME="${1}"
+TARGET="${2}"
+
+if [[ -z "${TARGET}" ]] || (( ${+opts[-h]} )); then
+ <<EOF >&2
+usage: ${0:t} [ -h ] [ -x ] hostname target
+
+ -h this message
+ -x enable shell debug
+ hostname hostname of nixosConfigurations defined host in our flake
+ target PXE booted, SSH root accessible, installation target
+EOF
+ exit 1
+fi
+
+<<EOF
+
+++++++++ The disk(s) on ${TARGET} are about to get wiped!
+WARNING! NixOS will be re-installed as ${HOSTNAME}.
+++++++++ This is a destructive operation!!!
+
+EOF
+
+read -q '?Are you sure? [y/N] '
+echo
+
+if [[ "${REPLY}" == "y" ]]; then
+
+ ssh root@${TARGET} rm -rf /etc/nixos
+ ssh root@${TARGET} git clone ${FLAKE} /etc/nixos
+
+ ssh root@${TARGET} nix run github:nix-community/disko -- \
+ --mode destroy,format,mount \
+ --yes-wipe-all-disks \
+ /etc/nixos/hosts/${HOSTNAME}/disks.nix
+
+ ssh root@${TARGET} nixos-install --flake /etc/nixos#${HOSTNAME}
+
+ if [[ "${?}" -eq 0 ]]; then
+ echo 'Unmounting file systems...' >&2
+ ssh root@${TARGET} mount | grep -v zfs | awk '$3 ~ /^\/mnt\// {print $3}' | xargs -i{} ssh root@${TARGET} umount -lf {}
+ echo 'Unmounting ZFS file systems...' >&2
+ while ! ssh root@${TARGET} umount -t zfs -a; do echo 'attempting to umount all ZFS file systems' >&2; sleep 1; done
+ echo 'Exporting zpool...' >&2
+ while ! ssh root@${TARGET} zpool export -a; do echo 'attempting to export all zpools' >&2; sleep 1; done
+ echo 'Rebooting!' >&2
+ ssh root@${TARGET} reboot
+ fi
+fi