Building ISOs for NixOS Hosts
This flake supports building bootable ISOs that embed the flake source, so nixos-install --flake works against /etc/nixos/flake without network access to the flake repo.
ISOs are generated from a single generic module (systems/iso/installer.nix) parameterized by hostname.
Quick start
# Build ISO + .sha256 checksum sidecar (Ventoy-ready)
nix build .#iso-<hostname>
# Copy to USB (ISO + sidecar file)
cp -r result/iso/* /mnt/ventoy/
# Or write directly with dd
sudo dd if=result/iso/*.iso of=/dev/sdX bs=4M status=progress conv=fsync
## Adding a new ISO target
Append the hostname to the `hosts` list in `systems/iso/default.nix`:
```nix
hosts = [ "shinji" "kenpachi" "yhwach" ];
The generic installer.nix module:
- Sets
isoImage.edition= hostname (distinguishable filenames likenixos-shinji-25.11-x86_64-linux.iso) - Embeds the flake source at
/nixos-flake→ copied to/etc/nixos/flakeat boot - Includes
diskoandnixos-facterin the live Nix store - Regenerates the host’s
facter.jsonin the embedded flake at boot (facter-report.service) — a stale report force-loads drivers for hardware that is gone and fails the initrd build. It only refreshes a report the host already carries; hosts without one keep theirhardware-configuration.nix - Prints MOTD instructions referencing the hostname
- Provides an
autoinstallsystemd oneshot (triggers whenautoinstallis in/proc/cmdline); it runs only afterfacter-reportsucceeded - For lanzaboote hosts (
boot.lanzaboote.enable): shipssbctlplus acreate-sb-keyshelper, and the install steps grow a secure-boot-keys step — restore the previous machine’s PKI bundle to/mnt/etc/secureboot, or create fresh keys (which the firmware only accepts after re-enrollment: setup mode, thensbctl enroll-keyson the installed system). Autoinstall creates fresh keys automatically when none are present.
Install workflow
Manual (default)
- Boot from USB
- Login (root, no password)
- Follow the on-screen instructions:
sudo disko --mode disko --flake /etc/nixos/flake#<hostname>
sudo nixos-install --flake /etc/nixos/flake#<hostname> --root /mnt
sudo install -Dm644 /etc/nixos/flake/systems/x86_64-linux/<hostname>/facter.json /mnt/etc/nixos/facter.json
sudo reboot
Getting the hardware report back into the repo
The regenerated report lives in the live system’s copy of the flake, which is
gone after the reboot — so it is saved to /etc/nixos/facter.json on the
installed system (the MOTD’s “Save” step; autoinstall does it on its own).
Pull it back and commit it, or the next rebuild uses the old report again:
scp <hostname>:/etc/nixos/facter.json systems/x86_64-linux/<hostname>/
Autoinstall
Add autoinstall to the kernel command line at boot:
- In the GRUB menu, highlight the entry and press
e - Append
autoinstallto thelinuxline - Press
Ctrl+xorF10to boot
The system will automatically partition the disk (via disko), install NixOS, and reboot.
Example: shinji ISO
# Build ISO only
nix build .#nixosConfigurations.iso-shinji.config.system.build.isoImage
# Build ISO + checksums (recommended)
nix build .#nixosConfigurations.iso-shinji.config.system.build.isoChecksums
# Write to USB
sudo dd if=result/iso/*.iso of=/dev/sdX bs=4M status=progress conv=fsync
For Ventoy, copy result/iso/* directly — the .sha256 file will be auto-detected.
Prerequisites for a host to be ISO-installable
The target host must:
- Use disko for disk partitioning (
disk.niximportinginputs.disko.nixosModules.disko) - Have
fileSystemsinhardware-configuration.nixcommented out — disko generates them declaratively - Either carry a
facter.json(initrd modules come from the report; it may start as a copy from identical hardware, the installer regenerates it — see mayuri, which has nohardware-configuration.nixat all), or include the block device kernel module inboot.initrd.availableKernelModules(e.g."nvme","ahci","sd_mod")
How it works
systems/iso/installer.nix receives hostname via specialArgs and uses it to:
- Set the ISO edition/volume label
- Populate MOTD instructions and autoinstall commands dynamically
- The flake source (
self) is embedded as a raw copy on the ISO at/nixos-flake - At boot,
postBootCommandscopies it to/etc/nixos/flakewherenixos-install --flakecan find it
Verification
Build the ISO with an accompanying .sha256 checksum file for verification:
nix build .#nixosConfigurations.iso-<hostname>.config.system.build.isoChecksums
Output:
result/
├── iso/
│ ├── nixos-<hostname>-...iso
│ └── nixos-<hostname>-...iso.sha256
└── SHA256SUMS
The .sha256 file uses sha256sum format (hash filename). Copy result/iso/* to your USB stick.
Ventoy
Ventoy auto-detects .sha256 files placed next to the ISO. Select the ISO in the Ventoy boot menu, press m, choose SHA256 — it calculates and compares against the file, confirming the copy was not corrupted.
Manual verification
cd result/
sha256sum -c SHA256SUMS
Size considerations
- The ISO includes the flake source closure, the live Nix store (squashfs), and disko
- Typical size: ~1.4 GB depending on extra
storeContents - Use
isoImage.squashfsCompression = "zstd -Xcompression-level 19"(default) for best compression - Add
isoImage.compressImage = truefor an extra.zstlayer (slower build, smaller file)
Remote install with nixos-anywhere (iso-anywhere)
The per-host ISOs above install the system fine, but the host’s sops identity
(its SSH host key, see modules/nixos/security/secrets.nix) is only created
on first boot, so it cannot decrypt passwords/<user> until it has been added
to secrets/.sops.yaml and the secrets rekeyed. just install closes that gap
by handing the host its key before nixos-install:
just iso anywhere # once: one generic ISO for every host
# boot the target from it, then from a machine that can decrypt the secrets:
just install <hostname> root@installer.local
iso-anywhere(systems/iso/anywhere.nix) is the stock minimal installer plus root’s SSH keys (homes/{mar,mirza}/keys), mDNS asinstaller.localandnixos-facter. It embeds no flake and no closure, so it never goes stale. Any other NixOS installer works too (log in,passwd, pass its IP).just installtakes the host key fromsecrets/host-keys.yaml(encrypted to the user keys only; no host can read another host’s key), or mints and stores one on the first install. It registers the key as a recipient insecrets/.sops.yaml(replacing a stale one), rekeyssecrets.yaml, then runs nixos-anywhere with the key in--extra-files. Reinstalls keep the same SSH fingerprint and sops identity.- nixos-anywhere builds the closure locally, runs disko (wipes the disks),
regenerates
facter.jsonfrom the target into the repo (hosts that carry one), installs and reboots. The first boot decrypts the user password; no post-install step. - Extra SSH arguments go into
addr, e.g.just install <host> "-p 2222 root@10.0.0.5". - Commit the changed
secrets/.sops.yaml,secrets/secrets.yaml,secrets/host-keys.yamlandfacter.jsonafterwards. - lanzaboote hosts (yhwach) still need the per-host ISO’s secure-boot step: nixos-anywhere does not create the PKI bundle.