Declarative disk partitioning and formatting using nix [maintainer=@Lassulus]
Go to file
github-actions[bot] 55e874b9c1 flake.lock: Update
Flake lock file updates:

• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/c19d62ad2265b16e2199c5feb4650fe459ca1c46?narHash=sha256-cFgdjyK/VBM3hB1RfFHXcI/VOCBVAv813s1upHKX7bI%3D' (2024-07-21)
  → 'github:NixOS/nixpkgs/4f02464258baaf54992debfd010a7a3662a25536?narHash=sha256-UNDpwjYxNXQet/g3mgRLsQ9zxrbm9j2JEvP4ijF3AWs%3D' (2024-07-24)
2024-07-25 01:32:08 +00:00
.github build(deps): bump DeterminateSystems/update-flake-lock from 22 to 23 2024-07-01 19:18:07 +00:00
disk-deactivate Allow more ways to detect disk to deactivate 2024-04-25 11:17:07 +00:00
docs update quickstart to use templates from disko-templates 2024-06-09 06:40:59 +00:00
example examples: rename vdb -> main 2024-07-19 19:33:40 +00:00
lib gpt: move boot partitions to the front of disko 2024-06-30 07:50:33 +00:00
tests lvm_vg: add lvm thinpool/thinlv support 2024-06-26 11:36:52 +00:00
.gitignore add gitignore 2022-08-17 14:53:43 +02:00
.mergify.yml fix mergify configuration 2024-04-23 11:19:26 +02:00
cli.nix cli/default: refactor to use more code from lib 2023-07-19 19:07:40 +00:00
default.nix flake: deprecate .lib.lib 2023-09-26 14:00:14 +00:00
disko use nom-build if available 2024-03-11 16:10:06 +01:00
disko-install disko-install: don't copy channel 2024-06-29 05:47:47 +00:00
doc.nix lib: refactor outputs into toplevel 2023-07-19 19:07:40 +00:00
flake.lock flake.lock: Update 2024-07-25 01:32:08 +00:00
flake.nix disko: allow importing disko twice 2024-05-11 16:29:00 +00:00
install-cli.nix treewide: reformat with nix fmt 2024-06-09 06:40:59 +00:00
LICENSE List all copyright years 2024-02-15 20:31:41 +00:00
module.nix document extraRootModules better 2024-06-24 13:36:20 +00:00
package.nix disko: add nixos-install-tools to PATH 2024-07-23 11:53:45 +00:00
README.md Merge branch 'master' into patch-1 2024-06-10 10:14:22 +02:00
statix.toml style: Disable inherit pattern check in statix 2023-02-07 15:37:12 +00:00

disko - Declarative disk partitioning

Project logo

Documentation Index

NixOS is a Linux distribution where everything is described as code, with one exception: during installation, the disk partitioning and formatting are manual steps. disko aims to correct this sad 🤡 omission.

This is especially useful for unattended installations, re-installation after a system crash or for setting up more than one identical server.

Overview

disko can either be used after booting from a NixOS installer, or in conjunction with nixos-anywhere if you're installing remotely.

Before using disko, the specifications of the disks, partitions, type of formatting and the mount points must be defined in a Nix configuration. You can find examples of typical configurations in the Nix community repository, and use one of these as the basis of your own configuration.

You can keep your configuration and re-use it for other installations, or for a system rebuild.

disko is flexible, in that it supports most of the common formatting and partitioning options, including:

  • Disk layouts: GPT, MBR, and mixed.
  • Partition tools: LVM, mdadm, LUKS, and more.
  • Filesystems: ext4, btrfs, ZFS, bcachefs, tmpfs, and others.

It can work with these in various configurations and orders, and supports recursive layouts.

How to use disko

Disko doesn't require installation: it can be run directly from nix-community repository. The Quickstart Guide documents how to run Disko in its simplest form when installing NixOS. Alternatively, you can also use the new disko-install tool, which combines the disko and nixos-install into one step.

For information on other use cases, including upgrading from an older version of disko, using disko without NixOS and downloading the module, see the How To Guide

For more detailed options, such as command line switches, see the Reference Guide

To access sample configurations for commonly-used disk layouts, refer to the examples provided.

Disko can be also used to create disk images.

Sample Configuration and CLI command

A simple disko configuration may look like this:

{
  disko.devices = {
    disk = {
      my-disk = {
        device = "/dev/sda";
        type = "disk";
        content = {
          type = "gpt";
          partitions = {
            ESP = {
              type = "EF00";
              size = "500M";
              content = {
                type = "filesystem";
                format = "vfat";
                mountpoint = "/boot";
              };
            };
            root = {
              size = "100%";
              content = {
                type = "filesystem";
                format = "ext4";
                mountpoint = "/";
              };
            };
          };
        };
      };
    };
  };
}

If you'd saved this configuration in /tmp/disk-config.nix, and wanted to create a disk named /dev/sda, you would run the following command to partition, format and mount the disk.

sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko /tmp/disk-config.nix

This tool is used by nixos-anywhere, which carries out a fully-automated remote install of NixOS.

We also acknowledge https://github.com/NixOS/nixpart, the conceptual ancestor of this project.

Licensing and Contribution details

This software is provided free under the MIT Licence.

Get in touch

We have a public matrix channel at disko.


This project is supported by Numtide. Untitledpng

We are a team of independent freelancers that love open source.  We help our customers make their project lifecycles more efficient by:

  • Providing and supporting useful tools such as this one
  • Building and deploying infrastructure, and offering dedicated DevOps support
  • Building their in-house Nix skills, and integrating Nix with their workflows
  • Developing additional features and tools
  • Carrying out custom research and development.

Contact us if you have a project in mind, or if you need help with any of our supported tools, including this one. We'd love to hear from you.