nanuqsaurus/scripts/install-btrfs.sh

61 lines
1.4 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
# Non-interactive Btrfs installer using disko-install.
# Defaults: DISK=/dev/vda TARGET_HOST=nanuqsaurus
# If FLAKE is unset and /etc/nixos/flake.nix exists, it uses /etc/nixos.
# Otherwise, set FLAKE to a flake URI like:
# - git+https://codeberg.org/<owner>/<repo>.git
# - github:<owner>/<repo>
DISK="${DISK:-/dev/vda}"
TARGET_HOST="${TARGET_HOST:-nanuqsaurus-btrfs}"
FLAKE="${FLAKE:-}"
MNT=/mnt
have() { command -v "$1" >/dev/null 2>&1; }
die() {
echo "ERROR: $*" >&2
exit 1
}
confirm_disk() {
echo "About to DESTROY ALL DATA on ${DISK}"
lsblk "$DISK" || die "Disk not found: $DISK"
echo "Continuing in 5 seconds… (Ctrl+C to abort)"
sleep 5
}
resolve_flake() {
if [[ -n "$FLAKE" ]]; then
return 0
fi
if [[ -e /etc/nixos/flake.nix ]]; then
FLAKE=/etc/nixos
return 0
fi
die "FLAKE is unset. Set FLAKE to a flake URI (or run from an ISO that provides /etc/nixos)."
}
clear
confirm_disk
resolve_flake
echo "[1/1] Installing ${TARGET_HOST} via disko-install"
LOG=/tmp/nixos-install.log
nix \
--experimental-features "nix-command flakes" \
run "github:nix-community/disko/latest#disko-install" -- \
--mode format \
--flake "${FLAKE}#${TARGET_HOST}" \
--disk main "${DISK}" \
--mount-point "$MNT" \
--system-config '{"users":{"users":{"root":{"hashedPassword":"!"}}}}' |& tee "$LOG"
echo "Install log saved to $LOG"
echo "Install complete. You can reboot now."