Declarative disk partitioning and formatting using nix [maintainer=@Lassulus]
Go to file
2023-07-04 16:02:25 +00:00
.github update-flake-lock: add permission to create pr 2023-06-12 06:49:44 +02:00
disk-deactivate jq: filter null values from mountpoints from lsblk output 2023-02-03 14:57:55 +01:00
docs docs: minor fixups 2023-06-05 10:23:08 +02:00
example example gpt-bios-compat: use new gpt type 2023-07-04 16:02:25 +00:00
lib lib: better formatting of generated shell output 2023-07-04 16:02:25 +00:00
tests tests: use diskoScript output 2023-06-16 21:11:44 +02:00
.gitignore add gitignore 2022-08-17 14:53:43 +02:00
.mergify.yml mergify: switch to rebase 2023-06-16 13:40:42 +02:00
ci.nix style: Apply nixpkgs-fmt and fix 2023-02-06 14:24:34 +00:00
cli.nix diskoNoDeps -> diskoScriptNoDeps 2023-06-24 09:19:17 +00:00
default.nix diskoScript: add bash to PATH 2023-06-24 09:19:17 +00:00
disko disko cli: fix error about impurity with nix 2023-06-28 17:35:27 +02:00
doc.nix apply deadnix 2023-06-06 13:32:47 +02:00
flake.lock flake.lock: Update 2023-06-26 02:46:54 +00:00
flake.nix flake: expose the module as nixosModules.default 2023-06-22 12:59:11 +02:00
LICENSE Create LICENSE 2022-10-02 22:31:39 +02:00
linux-testing-bcachefs.nix linux-testing-bcachefs: 6.3.0-2023-05-02 -> 6.3.0-2023-05-21 2023-06-08 11:19:38 +02:00
module.nix diskoScript: add bash to PATH 2023-06-24 09:19:17 +00:00
package.nix types: refactor into diskoLib 2023-05-20 13:56:42 +02:00
README.md docs: minor fixups 2023-06-05 10:23:08 +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.

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.

Sample Configuration and CLI command

A simple disko configuration may look like this:

{ disks ? [ "/dev/vdb" ], ... }: {  
 disk = {  
  vdb = {  
   device = builtins.elemAt disks 0;  
   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 = "/";  
      };  
     }  
    ];  
   };  
  };  
 };  
}

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

$ sudo nix run github:nix-community/disko -- --mode zap_create_mount /tmp/disko-config.nix --arg disks '[ "/dev/nvme0n1" ]'

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.

If you would like to become a contributor, please see our contribution guidelines.


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.