NixOS can be bootstrapped onto new machines from a live disk. This method requires minimal user input, and allows NixOS to be installed from existing configuration.
- Download the (minimal) Nix ISO, see Download.
- Plugin the flash drive and unmount if needed.
- Write the ISO to the flash drive.
sudo dd if=<path to .iso> of=/dev/sd<drive letter> bs=4M status=progress oflag=sync
- Boot into the flash drive and select NixOS ... Installer.
The minimal Nix ISO does not have network manager, so WIFI is configured manually.
- Configure the WIFI credentials.xsel
wpa_passphrase <WIFI SSID> > wifi.conf
- Get the name of the WIFI interface.
ls /sys/class/net | grep w
- Connect to the WIFI endpoint.
sudo wpa_supplicant -i <WIFI interface> -c wifi.conf -B
-
Clone the Nix configuration.
git clone https://github.com/eric-carlsson/nixfiles.git cd nixfiles
-
Before proceeding, the NixOS configuration should contain hardware and disk configuration files. Hardware configuration can be generated (without filesystem config since this is managed by disko).
sudo nixos-generate-config --no-filesystems --show-hardware-config
-
Format disk(s).
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko/latest -- --mode destroy,format,mount --flake .#<hostname>
-
Install NixOS.
sudo nixos-install --no-root-passwd --flake .#<hostname>
-
Set the user login password.
sudo nixos-enter --root /mnt -c 'passwd <username>'
-
Reboot.
WIP: Single cmd install with disko-install
The minimal Nix installer uses an in-memory file system for the Nix store. This tends cause OOM issues. Solve this by creating a swap partition.
- Create a new partition.
Enter
sudo fdisk /dev/sd<drive letter>
n
and press enter until asked to enter the last sector. Enter a size that will fit on the flash drive, for example+16000M
. Once created, assign a type by enteringt
and entering82
. Enterw
to write changes to disk. - Format the swap partition.
sudo mkswap /dev/sd<drive letter><partition number>
- Activate the swap partition.
sudo swapon /dev/sd<drive letter><partition number>
- Remount the Nix store to use the swap space.
sudo mount -o remount,size=15G,noatime /nix/.rw-store
Generate a hardware configuration file for the machine.
sudo nixos-generate-config --no-filesystems --show-hardware-config
Add the output to host/<hostname>/hardware-configuration.nix
and push to remote.
sudo nix \
--extra-experimental-features 'flakes nix-command' \
run github:nix-community/disko#disko-install -- \
--flake "github:eric-carlsson/nixfiles#<hostname>" \
--write-efi-boot-entries \
--disk main "<disk device>"