Declarative disk partitioning and formatting using nix [maintainer=@Lassulus]
Go to file
2023-02-02 14:42:05 +01:00
.github Revert "don't use bot token for flake updates" 2023-01-23 09:29:14 +01:00
disk-deactivate disk-deactivate: follow by-id/by-uuid links to real device 2023-01-28 18:08:31 +01:00
example examples: add hybrid.nix 2023-02-02 14:42:05 +01:00
tests vendorize bcachefs kernel 2023-01-23 10:56:51 +01:00
types split disko type into multiple files 2023-01-29 08:10:33 +01:00
.gitignore add gitignore 2022-08-17 14:53:43 +02:00
bors.toml update bors toml 2023-01-23 15:35:25 +01:00
ci.nix run all tests on ci 2022-08-25 23:31:05 +02:00
cli.nix cli: fix zap_create_mount mode 2023-02-02 12:44:57 +01:00
default.nix split disko type into multiple files 2023-01-29 08:10:33 +01:00
disko add support for another mountpoint than /mnt 2023-01-28 18:08:31 +01:00
doc.nix split disko type into multiple files 2023-01-29 08:10:33 +01:00
flake.lock flake.lock: Update 2023-02-02 01:39:43 +00:00
flake.nix move linuxPackages_bcachefs to legacyPackages 2023-01-23 15:34:35 +01:00
LICENSE Create LICENSE 2022-10-02 22:31:39 +02:00
linux-testing-bcachefs.nix bcachefs: 2022-12-29 -> 2023-02-01 2023-02-01 22:56:32 +01:00
module.nix split disko type into multiple files 2023-01-29 08:10:33 +01:00
package.nix use stdenvNoCC instead of barebone derivation 2022-12-09 14:34:12 +01:00
README.md README: Advertise correct branch name in channel url 2023-01-11 16:31:21 +01:00
types.nix types.table: get device mountOptions the correct way 2023-01-28 18:08:31 +01:00

disko - declarative disk partitioning

Disko takes the NixOS module system and makes it work for disk partitioning as well.

I wanted to write a curses NixOS installer, and that was the first step that I hit; the disk formatting is a manual process. Once that's done, the NixOS system itself is declarative, but the actual formatting of disks is manual.

Features

  • supports LVM, ZFS, btrfs, GPT, mdadm, ext4, ...
  • supports recursive layouts
  • outputs a NixOS-compatible module
  • CLI

How-to guides

NixOS installation

During the NixOS installation process, replace the Partitioning and formatting steps with the following:

  1. Find a disk layout in ./examples that you like.
  2. Write the config based on the example and your disk layout.
  3. Run the CLI (nix run github:nix-community/disko) to apply the changes.
  4. FIXME: Copy the disko module and disk layout around.
  5. Continue the NixOS installation.

Using without NixOS

Reference

Module options

TODO: link to generated module options

Examples

./examples

CLI

TODO: output of the cli --help

Installing NixOS module

You can use the NixOS module in one of the following ways:

Flakes (Current recommendation)

If you use nix flakes support:

{
  inputs.disko.url = "github:nix-community/disko";
  inputs.disko.inputs.nixpkgs.follows = "nixpkgs";

  outputs = { self, nixpkgs, disko }: {
    # change `yourhostname` to your actual hostname
    nixosConfigurations.yourhostname = nixpkgs.lib.nixosSystem {
      # change to your system:
      system = "x86_64-linux";
      modules = [
        ./configuration.nix
        disko.nixosModules.disko
      ];
    };
  };
}
niv

First add it to niv:

$ niv add nix-community/disko

Then add the following to your configuration.nix in the imports list:

{
  imports = [ "${(import ./nix/sources.nix).disko}/modules/disko.nix" ];
}
nix-channel

As root run:

$ nix-channel --add https://github.com/nix-community/disko/archive/master.tar.gz disko
$ nix-channel --update

Then add the following to your configuration.nix in the imports list:

{
  imports = [ <disko/modules/disko.nix> ];
}
fetchTarball

Add the following to your configuration.nix:

{
  imports = [ "${builtins.fetchTarball "https://github.com/nix-community/disko/archive/master.tar.gz"}/module.nix" ];
}

or with pinning:

{
  imports = let
    # replace this with an actual commit id or tag
    commit = "f2783a8ef91624b375a3cf665c3af4ac60b7c278";
  in [ 
    "${builtins.fetchTarball {
      url = "https://github.com/nix-community/disko/archive/${commit}.tar.gz";
      # replace this with an actual hash
      sha256 = "0000000000000000000000000000000000000000000000000000";
    }}/module.nix"
  ];
}

Using the NixOS module

{
  # checkout the example folder for how to configure different disko layouts
  disko.devices = {
    disk.sda = {
      device = "/dev/sda";
      type = "disk";
      content = {
        type = "table";
        format = "gpt";
        partitions = [
          {
            type = "partition";
            name = "ESP";
            start = "1MiB";
            end = "100MiB";
            bootable = true;
            content = {
              type = "filesystem";
              format = "vfat";
              mountpoint = "/boot";
            };
          }
          {
            name = "root";
            type = "partition";
            start = "100MiB";
            end = "100%";
            part-type = "primary";
            bootable = true;
            content = {
              type = "filesystem";
              format = "ext4";
              mountpoint = "/";
            };
          }
        ];
      };
    };
  };
}

this will configure fileSystems and other required NixOS options to boot the specified configuration.

If you are on an installer, you probably want to disable enableConfig.

disko will create the scripts disko-create and disko-mount which can be used to create/mount the configured disk layout.