Skip to content

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.

  1. Copy an existing disko configuration into the host’s configuration directory.

    Terminal window
    cp configs/nixos/desktop/disko.nix configs/nixos/$(hostname)
  2. Edit the disk layout according to your needs. Replace disko.devices.disk.main.device with the name listed by lsblk for your main drive.

    Terminal window
    sudo lsblk
  3. Apply the disko configuration.

    Terminal window
    sudo nix run github:nix-community/disko/latest -- --mode destroy,format,mount configs/nixos/$(hostname)/disko.nix
  4. Generate 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}.nix
    cp configs/nixos/$(hostname)/hardware-configuration.nix configs/nixos/$(hostname)/hardware.nix

Further reading