Watch
1
0
Fork
You've already forked disko
0
mirror of https://github.com/nix-community/disko.git synced 2026-11-04 04:10:58 +00:00
Declarative disk partitioning and formatting using nix [maintainers=@Lassulus @Enzime @iFreilicht @Mic92 @phaer]
  • Nix 95.4%
  • Shell 3.8%
  • jq 0.8%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
lassulus cedd626e11
interactive-vm: disable disko.enableConfig to avoid duplicate swapDevices (#1300)
Closes #1283

When building `vmWithDisko` via `extendModules`, the outer `module.nix`
is evaluated with `disko.enableConfig = true` (default), contributing
`swapDevices = cfg.devices._config.swapDevices or [ ]`. At the same
time, `lib/interactive-vm.nix` contributes `swapDevices =
cfg_.disko.devices._config.swapDevices or [ ]` via
`diskoBasedConfiguration`.

Because `swapDevices` in NixOS is a `listOf submodule`, definitions are
merged by concatenation. As a result, every swap partition in the disko
config appears twice in the VM's generated `/etc/fstab`:

```
# Swap devices.
/dev/mapper/dev-disk-byx2dpartlabel-diskx2dmainx2dencryptedSwap none swap defaults,pri=100
/dev/disk/by-partlabel/disk-main-plainSwap none swap defaults,discard
/dev/mapper/dev-disk-byx2dpartlabel-diskx2dmainx2dencryptedSwap none swap defaults,pri=100
/dev/disk/by-partlabel/disk-main-plainSwap none swap defaults,discard
```

During boot, `systemd-fstab-generator` fails with exit status 1 because
duplicate `.swap` unit files cannot be created.

### Fix

Setting `disko.enableConfig = false;` in `lib/interactive-vm.nix`
prevents `module.nix` from injecting the unmapped host disk
configurations into the VM variant. `interactive-vm.nix`'s
`diskoBasedConfiguration` already supplies the properly QEMU-mapped
filesystem, boot, and swap configurations.

### Verification

Evaluated on `example/swap.nix`:

- **Before**:
  `vmSwapDevices` has 4 entries (2 pairs of identical devices).
- **After**:
  `vmSwapDevices` has 2 unique entries.
  `fileSystems` and `vmWithDisko` script remain intact and functional.

Added `tests/vm-with-disko-swap.nix` ensuring that
`vmVariantWithDisko.swapDevices` has no duplicate devices. Checked with
`nix build .#checks.x86_64-linux.vm-with-disko-swap` and verified
`treefmt` formatting.
2026-10-20 20:02:00 +00:00
.github build(deps): bump peter-evans/create-pull-request from 7 to 8 2026-02-23 21:10:10 +00:00
disk-deactivate disk-deactivate: wipe raid arrays before stopping them 2026-04-08 09:40:37 +02:00
docs docs: fix upgrade guide link pointing to a fork 2026-06-19 10:00:30 +01:00
example luks: add test for multiple partitions and fix handling if on same disk (#1281) 2026-10-20 13:11:14 +00:00
lib interactive-vm: disable disko.enableConfig to avoid duplicate swapDevices (#1300) 2026-10-20 20:02:00 +00:00
scripts fix: correct uncommitted spelling in release script 2026-03-05 12:13:10 +08:00
tests interactive-vm: disable disko.enableConfig to avoid duplicate swapDevices (#1300) 2026-10-20 20:02:00 +00:00
.envrc setup treefmt 2025-02-15 10:08:56 +00:00
.git-blame-ignore-revs add .git-blame-ignore-revs 2025-02-15 10:08:56 +00:00
.gitignore Make bcachefs subvolumes boot-time mount tests pass + more tests 2025-05-04 20:24:55 +00:00
cli.nix fix: flakes support on disko standalone cli 2025-07-04 05:43:36 +00:00
CONTRIBUTING.md CONTRIBUTING.md: add documentation on how to run tests 2025-06-06 09:05:14 +00:00
default.nix treewide: format all files 2025-02-15 10:08:56 +00:00
disko only use nom if we write to a terminal 2025-05-20 12:07:15 +00:00
disko-install disko-install: resolve symlinks in mount point path 2025-12-19 13:25:02 +00:00
doc.nix treewide: format all files 2025-02-15 10:08:56 +00:00
flake-module.nix feat: add flake-parts module 2025-09-10 12:44:52 +00:00
flake.lock [create-pull-request] automated change 2026-06-11 04:27:06 +00:00
flake.nix devShells: expose disko CLI 2026-05-17 10:44:15 +02:00
install-cli.nix treewide: format all files 2025-02-15 10:08:56 +00:00
LICENSE List all copyright years 2024-02-15 20:31:41 +00:00
module.nix make-disk-image: add useVirtualDevices option 2026-06-14 15:03:34 -05:00
package.nix Fix use of deprecated stdenv.isDarwin 2026-10-20 14:34:28 +02:00
README.md fix: Apply umask=0077 to /boot partition in all examples 2025-01-06 20:23:33 +01:00
statix.toml style: Disable inherit pattern check in statix 2023-02-07 15:37:12 +00:00
treefmt.toml setup treefmt 2025-02-15 10:08:56 +00:00
version.nix release: reset released flag 2026-01-20 15:05:16 +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 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";
                mountOptions = [ "umask=0077" ];
              };
            };
            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/latest -- --mode destroy,format,mount /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.

If you want to contribute, check out CONTRIBUTING.md.

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.