disko

This configuration uses disko extensively for creating them filesystem configurations and automating them filesystem partitioning. Take note this should be only declared for hosts with the format iso (or without the format) as mentioned from Declarative host management.

They are declared in the disko.nix at the host root which they are then imported into disko.devices attribute. Here’s an example configuration for my desktop workstation.

./hosts/ni/disko.nix
{ disk ? "/dev/nvme0n1", config, lib, ... }:

{
  disko.devices = {
    disk.primary = {
      device = disk;
      type = "disk";
      content = {
        type = "gpt";
        partitions = {
          # You can't really have a btrfs-layered boot so this'll have to do.
          ESP = {
            priority = 1;
            start = "0";
            end = "512MiB";
            type = "EF00";
            content = {
              type = "filesystem";
              mountpoint = "/boot";
              format = "vfat";
            };
          };

          swap = {
            start = "-8GiB";
            end = "-0";
            type = "8200";
            content = {
              type = "swap";
              randomEncryption = true;
            };
          };

          root = {
            size = "100%";
            type = "8300";
            content = {
              type = "btrfs";
              extraArgs = [ "-f" ];

              subvolumes = lib.mkMerge [
                {
                  "/root" = {
                    mountOptions = [ "compress=zstd" ];
                    mountpoint = "/";
                  };
                  "/home" = {
                    mountOptions = [ "compress=zstd" ];
                    mountpoint = "/home";
                  };
                  "/nix" = {
                    mountOptions = [ "compress=zstd" "noatime" "noacl" ];
                    mountpoint = "/nix";
                  };
                }

                (lib.mkIf config.services.guix.enable {
                  "/gnu" = {
                    mountOptions = [ "compress=zstd" "noatime" "noacl" ];
                    mountpoint = "/gnu";
                  };
                })
              ];
            };
          };
        };
      };
    };
  };
}

Take note the disko NixOS module already handles NixOS filesystem configuration (i.e., fileSystems.<name>) so if you have already have an existing hardware configuration, you have to delete it to prevent conflicting fstab configuration.

Another thing to take notice is disko is mostly intended for fresh systems. Migrating your already existing systems with disko can be problematic. In the previous config, the order of the declared partitions should match with the initial order when you manually partitioned the system. If you cannot deal with it, reinstalling the system will help you there.