main
 1#!/usr/bin/env bash
 2# Install a NixOS system using disko-install.
 3#
 4# This script partitions the target disk (via disko) and installs the specified
 5# NixOS configuration from this flake. It is meant to be run from the NixOS
 6# live USB installer.
 7#
 8# Prerequisites:
 9#   - Boot from a NixOS live USB
10#   - Clone or copy this repository onto the live system
11#   - Identify the target disk device (e.g., /dev/nvme0n1)
12#
13# The --disk flag maps the disko disk name (defined in systems/<host>/disks.nix)
14# to the actual block device. Most hosts use "root" as the disk name.
15#
16# Examples:
17#   # Install okinawa onto /dev/nvme0n1
18#   ./install.sh okinawa --disk root /dev/nvme0n1
19#
20#   # Install with EFI boot entries written to NVRAM (use when installing on
21#   # the machine you'll boot from, not when preparing a disk for another machine)
22#   ./install.sh okinawa --disk root /dev/nvme0n1 --write-efi-boot-entries
23#
24#   # Dry run (show commands without executing)
25#   ./install.sh okinawa --disk root /dev/nvme0n1 --dry-run
26#
27#   # Update an existing system without reformatting (mount-only mode)
28#   ./install.sh okinawa --disk root /dev/nvme0n1 --mode mount
29#
30# Tips:
31#   If you run out of space on the live USB, you can either:
32#   - Resize the tmpfs:  mount -o remount,size=28G /nix/.rw-store
33#   - Build remotely using ./remote-install.sh (builds on workstation, copies over SSH)
34#
35# All extra arguments are forwarded to disko-install. Run with --help to see
36# the full list of disko-install options:
37#
38# disko-install options:
39#   --mode MODE              format (default) or mount (skip formatting)
40#   --disk NAME DEVICE       Map disko disk name to a block device (required)
41#   --dry-run                Print commands without running them
42#   --show-trace             Show Nix stack trace on error
43#   --extra-files SRC DEST   Copy extra files into the installed system
44#   --write-efi-boot-entries Write EFI entries to NVRAM for this machine
45#   --system-config JSON     Merge extra JSON config into the NixOS configuration
46#   --mount-point PATH       Custom mount point (default: /mnt/disko-install-root)
47#   --option NAME VALUE      Pass extra options to Nix
48#   -h, --help               Show disko-install help
49
50set -euo pipefail
51
52usage() {
53    sed -n '/^# Install a NixOS/,/^[^#]/{ /^#/s/^# \{0,1\}//p }' "$0"
54    echo ""
55    echo "Usage: $0 <hostname> [disko-install options...]"
56    echo ""
57    echo "Arguments:"
58    echo "  hostname    NixOS host configuration to install (from flake)"
59    echo ""
60    echo "Common usage:"
61    echo "  $0 okinawa --disk root /dev/nvme0n1"
62}
63
64if [[ $# -eq 0 ]] || [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
65    usage
66    exit 0
67fi
68
69SYSTEM=$1
70shift
71
72nix --extra-experimental-features "nix-command flakes" run \
73    'github:nix-community/disko/latest#disko-install' -- --flake ".#${SYSTEM}" "$@"