74 lines
2.2 KiB
Bash
Executable file
74 lines
2.2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Non-interactive Btrfs installer using the flake in this repo.
|
|
# Defaults: DISK=/dev/vda TARGET_HOST=nanuqsaurus
|
|
|
|
DISK=${DISK:-/dev/vda}
|
|
TARGET_HOST=${TARGET_HOST:-nanuqsaurus}
|
|
|
|
SCRIPT_DIR=$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
REPO_ROOT=$(cd -- "${SCRIPT_DIR}/.." && pwd)
|
|
|
|
clear
|
|
|
|
echo "[1/7] Partitioning ${DISK}"
|
|
printf "label: gpt\n,550M,U\n,,L\n" | sfdisk "${DISK}"
|
|
|
|
echo "[2/7] Formatting"
|
|
mkfs.fat -F 32 "${DISK}1"
|
|
mkfs.btrfs -f "${DISK}2"
|
|
|
|
echo "[3/7] Creating Btrfs subvolumes"
|
|
mkdir -p /mnt
|
|
mount "${DISK}2" /mnt
|
|
btrfs subvolume create /mnt/root
|
|
btrfs subvolume create /mnt/home
|
|
btrfs subvolume create /mnt/nix
|
|
umount /mnt
|
|
|
|
echo "[4/7] Mounting subvolumes"
|
|
mount -o compress=zstd,subvol=root "${DISK}2" /mnt
|
|
mkdir -p /mnt/{home,nix,boot}
|
|
mount -o compress=zstd,subvol=home "${DISK}2" /mnt/home
|
|
mount -o compress=zstd,subvol=nix "${DISK}2" /mnt/nix
|
|
mount "${DISK}1" /mnt/boot
|
|
|
|
echo "[5/7] Copying flake to /etc/nixos"
|
|
mkdir -p /mnt/etc/nixos
|
|
if command -v rsync >/dev/null 2>&1; then
|
|
rsync -a --exclude '.git' --exclude 'result' --exclude 'node_modules' "${REPO_ROOT}/" /mnt/etc/nixos/
|
|
else
|
|
(cd "${REPO_ROOT}" && tar -cf - --exclude=.git --exclude=result --exclude=node_modules .) | (cd /mnt/etc/nixos && tar -xf -)
|
|
fi
|
|
|
|
echo "[6/7] Generating hardware config"
|
|
mkdir -p /mnt/etc/nixos/hosts
|
|
nixos-generate-config --root /mnt --show-hardware-config > "/mnt/etc/nixos/hosts/local-${TARGET_HOST}-hardware.nix"
|
|
|
|
host_file="/mnt/etc/nixos/hosts/local-${TARGET_HOST}.nix"
|
|
if [ ! -e "${host_file}" ]; then
|
|
cat > "${host_file}" <<EOF
|
|
{ inputs, ... }:
|
|
|
|
{
|
|
imports = [
|
|
inputs.lix-module.nixosModules.lixFromNixpkgs
|
|
../modules/system/base.nix
|
|
../modules/system/packages.nix
|
|
../modules/system/home-manager-skel.nix
|
|
../modules/desktop/gnome-minimal.nix
|
|
../modules/users/admin.nix
|
|
./local-${TARGET_HOST}-hardware.nix
|
|
];
|
|
|
|
networking.hostName = "${TARGET_HOST}";
|
|
}
|
|
EOF
|
|
fi
|
|
|
|
echo "[7/7] Installing ${TARGET_HOST} via flake (local-${TARGET_HOST})"
|
|
nixos-install --root /mnt --flake "/mnt/etc/nixos#local-${TARGET_HOST}" --no-root-passwd |& tee /tmp/nixos-install.log
|
|
echo "Install log saved to /tmp/nixos-install.log"
|
|
|
|
echo "Install complete. You can reboot now."
|