No description
Find a file
Lassulus 6b0eebc6b6
Merge pull request #204 from nomeata/patch-1
Improve example code in README
2023-04-16 15:17:36 +02:00
.github build(deps): bump DeterminateSystems/update-flake-lock from 18 to 19 2023-04-10 20:03:37 +00:00
disk-deactivate jq: filter null values from mountpoints from lsblk output 2023-02-03 14:57:55 +01:00
docs upgrade-guide: fix markdown syntax 2023-04-15 17:18:50 +02:00
example Merge pull request #196 from nix-community/types-compact 2023-04-15 15:44:33 +02:00
tests zfs: add tests for hooks 2023-04-10 22:52:52 +02:00
types types: split zfs_dataset into zfs_fs & zfs_volume 2023-04-14 17:27:04 +02:00
.gitignore add gitignore 2022-08-17 14:53:43 +02:00
bors.toml update bors.toml 2023-04-15 16:12:56 +02:00
ci.nix style: Apply nixpkgs-fmt and fix 2023-02-06 14:24:34 +00:00
cli.nix style: Apply nixpkgs-fmt and fix 2023-02-06 14:24:34 +00:00
default.nix turn disk configs into valid nixos configuration 2023-04-06 08:56:55 +02:00
disko fix(cli): pass --root-mountpoint value as string 2023-03-17 16:45:07 -07:00
doc.nix style: Disable inherit pattern check in statix 2023-02-07 15:37:12 +00:00
flake.lock flake.lock: Update 2023-04-13 01:20:26 +00:00
flake.nix style: Define formatter in flake to allow nix fmt 2023-02-07 15:51:33 +00:00
LICENSE Create LICENSE 2022-10-02 22:31:39 +02:00
linux-testing-bcachefs.nix linux-bcachefs-testing: 6.2.0-2023-03-22 -> 6.2.0-2023-04-15 2023-04-15 23:16:44 +02:00
module.nix types,module,tests: run shellcheck on scripts before running them in NixOS tests 2023-02-14 09:07:13 +01:00
package.nix delete obsolete types.nix 2023-02-02 14:42:09 +01:00
README.md Improve example code in README 2023-04-16 14:51:08 +02:00
statix.toml style: Disable inherit pattern check in statix 2023-02-07 15:37:12 +00: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

For a NixOS installation follow this quickstart guide.

Using without NixOS

Upgrading from older disko versions

Read our upgrade guide when updating from older versions.

Reference

Module options

TODO: link to generated module options

Examples

./examples

CLI

$ nix run github:nix-community/disko --

disko [options] disk-config.nix
or disko [options] --flake github:somebody/somewhere

Options:

* -m, --mode mode
  set the mode, either create or mount
* -f, --flake uri
  fetch the disko config relative to this flake's root
* --arg name value
  pass value to nix-build. can be used to set disk-names for example
* --argstr name value
  pass value to nix-build as string
* --root-mountpoint /mnt
  where to mount the device tree
* --dry-run
  just show the path to the script instead of running it
* --debug
  run with set -x

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 = [
          {
            name = "ESP";
            start = "1MiB";
            end = "100MiB";
            bootable = true;
            content = {
              type = "filesystem";
              format = "vfat";
              mountpoint = "/boot";
            };
          }
          {
            name = "root";
            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.