NixOS Setup#
Automatically install and configure NixOS.
Usage#
Customize the configuration#
Review all files and adjust the configurations to suit your needs. At a minimum, you’ll need to change the following:
-
Users:
- Replace
khuedoanwith your username. - Replace my SSH public keys with yours.
- Replace
khuedoan/dotfileswith your dotfiles repository, or usehome-managerto manage all dotfiles.
- Replace
-
Hosts:
- Replace my hostnames with yours.
- Adjust hardware configurations to match your system.
Install with the NixOS Live CD#
- Download the latest NixOS live CD from here.
- Create a bootable USB drive:
sudo dd bs=4M if=/path/to/nixos.iso of=/dev/sda conv=fsync oflag=direct status=progress
- Boot from the USB drive.
- Install NixOS from the live CD:
nix-shell -p git gnumake neovim disko
git clone https://github.com/khuedoan/nixos-setup
cd nixos-setup
# Remember to replace the placeholders
make install host=HOSTNAME disk=/dev/DISK
Install on Apple Silicon MacBook Pro#
The macbookpro host uses nixos-apple-silicon
for Apple Silicon support. Partitioning is managed by the Asahi installer
(shared with macOS), not disko, so the installation process differs from x86 hosts.
- In macOS, run the Asahi installer to set up a UEFI boot environment:
curl https://alx.sh | sh
Choose "Resize an existing partition" to make room (at least 20GB), then "UEFI environment only". Name it NixOS. Follow the prompts to set permissive security and reboot.
- Download the latest installer ISO from the nixos-apple-silicon releases page and write it to a USB drive:
sudo dd bs=4M if=/path/to/nixos-apple-silicon.iso of=/dev/sdX conv=fsync oflag=direct status=progress
-
Shut down the Mac, insert the USB drive, and power on. U-Boot should boot from USB automatically. If it boots the internal disk instead, hit a key to stop autoboot, run
bootmenu, and select theusb 0entry. -
Partition and format the free space:
sudo -i
sgdisk /dev/nvme0n1 -n 0:0 -s
# Check the partition table to identify the new partition number (type 8300)
sgdisk /dev/nvme0n1 -p
mkfs.ext4 -L nixos /dev/nvme0n1pN # replace N with actual partition number
- Mount the partitions:
mount /dev/disk/by-label/nixos /mnt
mkdir -p /mnt/boot
mount /dev/disk/by-partuuid/$(cat /proc/device-tree/chosen/asahi,efi-system-partition) /mnt/boot
- Connect to Wi-Fi and install:
iwctl station wlan0 connect YOUR_SSID
systemctl restart systemd-timesyncd
nix-shell -p git gnumake
git clone https://github.com/khuedoan/nixos-setup
cd nixos-setup
nixos-install --flake '.#macbookpro' --impure
- After rebooting into the new system, update the
/bootPARTUUID inhosts/macbookpro/default.nixwith the actual value from step 5 and rebuild:
make build host=macbookpro flags=--impure
Apply changes#
After installation, clone your repository again and apply changes to the configuration by running:
make
Update hardware configuration#
If hardware changes occur, update the hardware configuration using the command
in the install target in ./Makefile.
Testing#
To test updated configurations without applying them to a running machine, create a VM using:
make test