- Nix 95.3%
- Shell 3.9%
- jq 0.8%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
askPassword's mismatch branch does exit 1, which kills the whole format script instead of just returning from the function. The per-device _create block runs in a subshell, and the top-level script has set -efux, so a subshell that exits nonzero takes the whole thing down with it. The retry loop this was supposed to feed into never gets a chance to run: ``` until askPassword; do echo "Passwords did not match, please try again." done ``` `askPassword` never returns from the mismatch branch, so until never sees a nonzero return, it just watches the whole script die. Type your password wrong once during formatting and disko doesn't ask again, it aborts. Same bug and same fix as #1206 (exit 1 -> return 1), which has been sitting unreviewed for a while. Credit to @Cyclic4179 for finding it first. While in there, I also capped the retry loop at 3 attempts. As written it would otherwise retry forever, and a script that just hangs asking for input with no way out isn't much better than one that silently dies. 3 also isn't arbitrary: it's what tries= defaults to in crypttab(5) for unlocking this same kind of volume at boot, so the format-time prompt now matches that. Added tests/luks-password-mismatch.nix covering both paths: **a mismatched pair followed by a matching one:** format should succeed, and the retry message should actually show up in the output. **three mismatched pairs in a row:** format should fail, the disk should not end up as valid LUKS, and the "too many attempts" message should be there instead of a silent exit code 1. Both fail on current master and pass with this change. |
||
| .github | ||
| disk-deactivate | ||
| docs | ||
| example | ||
| lib | ||
| scripts | ||
| tests | ||
| .envrc | ||
| .git-blame-ignore-revs | ||
| .gitignore | ||
| cli.nix | ||
| CONTRIBUTING.md | ||
| default.nix | ||
| disko | ||
| disko-install | ||
| doc.nix | ||
| flake-module.nix | ||
| flake.lock | ||
| flake.nix | ||
| install-cli.nix | ||
| LICENSE | ||
| module.nix | ||
| package.nix | ||
| README.md | ||
| statix.toml | ||
| treefmt.toml | ||
| version.nix | ||
disko - Declarative disk partitioning
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
Related Tools
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.
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.