Disk Partitioning
When reinstalling NixOS from an existing configuration, the only manual step is often disk partitioning. But even this step can be automated using disko.
Setup
To create a new disko configuration, copy one of the existing disko configurations into configs/nixos/$(hostname)/disko.nix
.
Copy an existing disko configuration into the host’s configuration directory.
Terminal window cp configs/nixos/desktop/disko.nix configs/nixos/$(hostname)Edit the disk layout according to your needs. Replace
disko.devices.disk.main.device
with the name listed bylsblk
for your main drive.Terminal window sudo lsblkApply the disko configuration.
Terminal window sudo nix run github:nix-community/disko/latest -- --mode destroy,format,mount configs/nixos/$(hostname)/disko.nixGenerate a new hardware configuration excluding the filesystem configurations provided by disko.
Terminal window sudo nixos-generate-config --no-filesystems --root /mnt --dir configs/nixos/$(hostname)rm configs/nixos/$(hostname)/{configuration,hardware}.nixcp configs/nixos/$(hostname)/hardware-configuration.nix configs/nixos/$(hostname)/hardware.nix