This is a way to configure encrypted partitions for NixOS:
# Partitioning
Making partitions for Root and Boot
- Working device for this tutorial is /dev/nvme0n1
- Replace 513GB with specific drive size
Bash
sudo parted /dev/nvme0n1 --script mklabel gpt
sudo parted /dev/nvme0n1 --script mkpart ESP fat32 1MiB 513MiB
sudo parted /dev/nvme0n1 --script set 1 esp on
sudo parted /dev/nvme0n1 --script mkpart primary ext4 513MiB 376GiB
sudo parted /dev/nvme0n1 --script name 2 nixos-luks
sudo mkfs.fat -F 32 -n boot /dev/nvme0n1p1# Mounting partitions
Bash
sudo mkfs.ext4 -L nixos /dev/mapper/nixos-enc
sudo mount /dev/disk/by-label/nixos /mnt
sudo mkdir -p /mnt/boot
sudo mount /dev/disk/by-label/boot /mnt/boot# Encryption
Encrypting the Root partition mounted on nixos-luks
Bash
sudo cryptsetup luksFormat --label nixos-luks /dev/disk/by-partlabel/nixos-luks
sudo cryptsetup open /dev/disk/by-partlabel/nixos-luks nixos-enc# Installation
Installing an existing flake Probably safer to clone an existing repo before installing in case the mountpoints need to be renamed
Also set password for root and for the user in the configuration
Bash
sudo nixos-install --flake github:njegossh/nixos#intel
sudo nixos-enter
passwd root# Cleanup
Disposal of mounted partitions and luks
Bash
sudo umount /mnt/boot
sudo umount /mnt
sudo cryptsetup close nixos-enc