Jump to content

Disko: Difference between revisions

From Official NixOS Wiki
m Minor formatting, in-link.
Reference the `latest` tag of the disko GitHub repo instead of the master branch, as shown in Disko's documentation: https://github.com/nix-community/disko/blob/master/docs/HowTo.md. This has been recommended in the documentation since 2024: https://github.com/nix-community/disko/commit/c7ef3964b6befa877e76316ae88f3ef251cae573.
 
Line 62: Line 62:
<!--T:6-->
<!--T:6-->
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
# sudo nix run github:nix-community/disko -- --mode disko ./disko-config.nix
# sudo nix run github:nix-community/disko/latest -- --mode disko ./disko-config.nix
</syntaxhighlight>
</syntaxhighlight>


Line 70: Line 70:
<!--T:8-->
<!--T:8-->
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
# sudo nix run github:nix-community/disko -- --mode disko --flake github:Lassulus/flakes-testing#fnord
# sudo nix run github:nix-community/disko/latest -- --mode disko --flake github:Lassulus/flakes-testing#fnord
</syntaxhighlight>
</syntaxhighlight>


Line 102: Line 102:
   inputs = {
   inputs = {
     nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
     nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
     disko.url = "github:nix-community/disko";
     disko.url = "github:nix-community/disko/latest";
     disko.inputs.nixpkgs.follows = "nixpkgs";
     disko.inputs.nixpkgs.follows = "nixpkgs";
   };
   };
Line 122: Line 122:
   };
   };
}
}
</nowiki>}}
</nowiki>|name=|lang=}}
<translate>
<translate>



Latest revision as of 18:55, 8 June 2026

Disko is a utility and NixOS module for declarative disk partitioning.

Disko Documentation Index

Usage

The following example creates a new GPT partition table for the disk /dev/vda including two partitions for EFI boot and a bcachefs root filesystem.

❄︎ disko-config.nix
{
  disko.devices = {
    disk = {
      main = {
        device = "/dev/vda";
        type = "disk";
        content = {
          type = "gpt";
          partitions = {
            ESP = {
              end = "500M";
              type = "EF00";
              content = {
                type = "filesystem";
                format = "vfat";
                mountpoint = "/boot";
              };
            };
            root = {
              name = "root";
              end = "-0";
              content = {
                type = "filesystem";
                format = "bcachefs";
                mountpoint = "/";
              };
            };
          };
        };
      };
    };
  };
}

The following command will apply the disk layout specified in the configuration and mount them afterwards. Warning: This will erase all data on the disk.

⚠︎
Warning: The disko commands will erase all existing data on your disk and repartition it according to the given configuration.
# sudo nix run github:nix-community/disko/latest -- --mode disko ./disko-config.nix

Alternativley use a disk layout configuration of a remote repository containing a flake.nix file as an entry point.

# sudo nix run github:nix-community/disko/latest -- --mode disko --flake github:Lassulus/flakes-testing#fnord

The commands above requires Flake features available on your system.

To verify both partitions got mounted correctly, run

# mount | grep /mnt

Configuration

In case the NixOS base system was installed on a partition layout bootstrapped with Disko, the disk config itself can be integrated into the system. First copy the file, for example disko-config.nix into your system configuration directory

# cp disko-config.nix /etc/nixos/

Add the Disko module on a flake-enabled system. Insert the required input and reference it and your disko-config.nix in the modules section. For alternative installation methods consult the Disko quickstart guide.

≡︎ 
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
    disko.url = "github:nix-community/disko/latest";
    disko.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = {self, nixpkgs, disko, ...}@inputs: {

    nixosConfigurations.mysystem = inputs.nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      specialArgs.inputs = inputs;
      modules = [
        disko.nixosModules.disko
        ./disko-config.nix
        {
          disko.devices.main.device = nixpkgs.lib.mkForce "/dev/vda";
        }
        ./configuration.nix
      ];
    };
  };
}

Ensure that there are no automatically generated entries of fileSystems options in /etc/nixos/hardware-configuration.nix. Disko will automatically generate them for you. Rebuild your system to apply the Disko configuration.