Storage Disko
Storage & Disko Partitioning
Disko is used for declarative, reproducible disk formatting, partitioning, and file systems.
Disko (nix-community/disko)
Disko is a Nix tool that defines disk partitioning schemas explicitly in Nix code. You can find schemas declared per host in hosts/<hostname>/modules/disko.nix and storage.nix.
Running Disko
To partition and format disks for a new installation, you can use the Disko CLI. Example for id3-eniac:
env ALL_PROXY=127.0.0.1:2080 \
nix \
--experimental-features "nix-command flakes" \
run github:nix-community/disko/latest -- \
--mode destroy,format,mount \
hosts/id3-eniac/modules/disko.nix
Note: --mode destroy,format,mount will wipe the target device, format it according to the schema, and mount the subvolumes to /mnt so that a subsequent nixos-install can be run.
Generating Raw/ISO Images
Disko is also used to build raw UEFI images and ISOs for single-board computers (SBCs) like the Orange Pi 5 Plus (sbc-opi5p) or VPS (vps-pacman).
nix build .#nixosConfigurations.vps-pacman.config.system.build.diskoImages
Btrfs & Subvolumes
The filesystem heavily leverages Btrfs.
- The root partition is encrypted (LUKS2) and inside it, a Btrfs filesystem is mapped.
- Core subvolumes are created, such as
/(root pool),@persist(for persistent data),@nix(for the Nix store),@tmp, and@snapshots. - The configuration relies on
impermanence. This means the OS root is often wiped and recreated at boot, relying on/persistto retain state. - Automated snapshots are handled using
btrbk.
Network Mounts
For external storage, systemd.mounts automatically maps NAS and network shares securely at boot:
- NFS:
/mnt/nfs1,/mnt/nfs2 - CIFS/SMB:
/mnt/archive_read,/mnt/labnas
Rescue & Mounting Encrypted Drives
If you need to rescue a system, you’ll need to manually decrypt and mount the Btrfs subvolumes:
# 1. Unlock the LUKS partition
sudo cryptsetup luksOpen /dev/nvme0n1p2 cryptroot
# 2. Mount the main Btrfs pool
sudo mount -o subvolid=5 /dev/mapper/cryptroot /mnt
# 3. Mount specific subvolumes if needed
sudo mount -o subvol=@persist /dev/mapper/cryptroot /mnt/persist
sudo mount -o subvol=@nix /dev/mapper/cryptroot /mnt/nix