Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120#!/usr/bin/env bashset -euo pipefail
# Install script for box NAS# Run this from the NixOS installer after rsync'ing the helm repo## Prerequisites:# - Boot NixOS installer# - Enable SSH: passwd && sudo systemctl start sshd# - rsync helm repo: rsync -avz --exclude='.git' /path/to/helm nixos@<IP>:~/## Usage:# cd ~/helm# ./install-box.sh
# ConfigurationFLAKE="$HOME/helm#box"NVME="/dev/disk/by-id/nvme-CT500P310SSD8_2544543B87C2"
# ZFS drives - update these if drives changeZFS1="/dev/disk/by-id/ata-WDC_WD40EFPX-68C6CN0_WD-WX32D954A2J7"ZFS2="/dev/disk/by-id/ata-WDC_WD40EFPX-68C6CN0_WD-WX32D95FVZVL"ZFS3="/dev/disk/by-id/ata-WDC_WD40EFPX-68C6CN0_WD-WX42D95M807R"
echo "=== Box NAS Installation ==="echo ""echo "This will install NixOS with:"echo " - NVMe boot drive: $NVME"echo " - ZFS RAIDZ1 pool with 3x 4TB drives (~8TB usable)"echo ""
# Verify drives existecho "Verifying drives..."for disk in "$NVME" "$ZFS1" "$ZFS2" "$ZFS3"; do if [[ ! -e "$disk" ]]; then echo "ERROR: Disk not found: $disk" echo "Available disks:" ls -la /dev/disk/by-id/ | grep -E '(nvme|ata)' | grep -v part exit 1 fidoneecho "All drives found."echo ""
# Generate ZFS keyfileecho "Generating ZFS keyfile..."dd if=/dev/urandom of=/tmp/tank.key bs=32 count=1 2>/dev/nullecho "ZFS keyfile created at /tmp/tank.key"echo ""
# Get LUKS passwordecho "Enter LUKS password for boot drive encryption:"read -s LUKS_PASSWORDecho ""echo "Confirm LUKS password:"read -s LUKS_PASSWORD_CONFIRMecho ""
if [[ "$LUKS_PASSWORD" != "$LUKS_PASSWORD_CONFIRM" ]]; then echo "ERROR: Passwords do not match" exit 1fi
echo -n "$LUKS_PASSWORD" > /tmp/luks-passwordecho "LUKS password saved."echo ""
# Confirm before proceedingecho "WARNING: This will DESTROY all data on the following drives:"echo " - $NVME"echo " - $ZFS1"echo " - $ZFS2"echo " - $ZFS3"echo ""read -p "Type 'yes' to continue: " CONFIRMif [[ "$CONFIRM" != "yes" ]]; then echo "Aborted." exit 1fi
echo ""echo "Running disko-install..."sudo nix \ --extra-experimental-features nix-command \ --extra-experimental-features flakes \ run 'github:nix-community/disko/latest#disko-install' -- \ --flake "$FLAKE" \ --disk nvme "$NVME" \ --disk zfs1 "$ZFS1" \ --disk zfs2 "$ZFS2" \ --disk zfs3 "$ZFS3"
echo ""echo "Copying ZFS keyfile to installed system..."# disko-install mounts the root filesystem at /mntif [[ ! -d /mnt/etc ]]; then echo "ERROR: /mnt/etc does not exist. Is the root filesystem mounted?" exit 1fisudo mkdir -p /mnt/etc/zfssudo cp /tmp/tank.key /mnt/etc/zfs/tank.keysudo chmod 000 /mnt/etc/zfs/tank.key
echo "Updating ZFS keylocation to permanent path..."# Update keylocation so ZFS looks for the key in the installed systemsudo zfs set keylocation=file:///etc/zfs/tank.key tank
echo ""echo "Cleaning up..."rm -f /tmp/luks-password /tmp/tank.key
echo ""echo "=== Installation complete! ==="echo ""echo "Next steps:"echo " 1. Reboot: sudo reboot"echo " 2. Enter LUKS password at boot prompt"echo " 3. SSH to box at 192.168.1.240"echo ""