- Create the GPT partition table
$ parted /dev/sdX mklabel gpt
- Create the UEFI FAT32 partition (which will be
/dev/sdXY
)$ parted /dev/sdX mkpart esp fat32 1MiB 512MiB
$ parted /dev/sdX set 1 esp on
$ parted /dev/sdX set 1 boot on
$ mkfs.fat -F 32 -n UEFI /dev/sdXY
- Create the SWAP partition (which will be
/dev/sdXW
) (optional)$ parted /dev/sdX mkpart swap linux-swap 512MiB 4.5GiB
$ mkswap -L SWAP /dev/sdXW
- Create the NIXOS BTRFS partition (which will be
/dev/sdXZ
)$ parted /dev/sdX mkpart nixos btrfs 4.5GiB 100%
$ mkfs.btrfs -L NIXOS /dev/sdXZ
P.S. The created partitions can be viewed using
$ fdisk -l /dev/sdX
.
- Mount the NIXOS partition
$ mount -t btrfs /dev/sdXZ /mnt
- Create the NIX partition subvolume
$ btrfs subvolume create /mnt/@home
- Create the HOME partition subvolume
$ btrfs subvolume create /mnt/@nix
- Unmount the NIXOS partition
$ umount /mnt
- Mount the in-ram ROOT partition
$ mount -t tmpfs -o noatime,mode=755 none /mnt
- Create persistent directories on which to mount partitions
$ mkdir /mnt/{boot,nix,home}
- Mount the UEFI partition
$ mount -t vfat -o defaults,noatime /dev/sdXY /mnt/boot
- Mount the NIX partition subvolume
$ mount -t btrfs -o noatime,compress=zstd,subvol=@nix /dev/sdXZ /mnt/nix
- Mount the HOME partition subvolume
$ mount -t btrfs -o noatime,compress=zstd,subvol=@home /dev/sdXZ /mnt/home
- Create directories that will contain persistent system files
$ mkdir -p /mnt/{,nix/persist/}{etc/nixos,var/log}
- Bind system directories to their NIX persistent counterparts
$ mount --bind /mnt/nix/persist/etc/nixos /mnt/etc/nixos
$ mount --bind /mnt/nix/persist/var/log /mnt/var/log
- Mount the SWAP partition (optional)
$ swapon /dev/sdXW
- Let NixOS generate template configurations
$ nixos-generate-config --root /mnt
- Make sure all mount points in
hardware-configuration.nix
are identical to the previous section$ vim /mnt/etc/nixos/hardware-configuration.nix
- Edit the
configuration.nix
file as needed$ vim /mnt/etc/nixos/configuration.nix
- Add
machine-id
file source link:
environment.etc."machine-id".source = "/nix/persist/etc/machine-id";
- Disable users mutability:
users.mutableUsers = false;
- Add user (hashed) password:
(In another console:$ nix-shell --run 'mkpasswd -m SHA-512 -s' -p mkpasswd
)
users.users.*USERNAME*.initialHashedPassword = "*HASHED_PASSWORD*";
- Add
- Start the installer
$ nixos-install --no-root-passwd
$ reboot
This file is my personal summary based on these articles: