1423 Commits
Author SHA1 Message Date
github-actions[bot] b4b178f363 flake: update inputs (#1314)
Automated changes by
[create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action
2026-11-30 08:18:09 +00:00
bors 9c06eff0a8 [create-pull-request] automated change 2026-11-30 07:27:22 +00:00
github-actions[bot] 44761d4f74 flake: update inputs (#1273)
Automated changes by
[create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action
2026-11-20 09:52:48 +00:00
lassulus 480756f887 tests/bcachefs: handle systemd initrd unlock prompts
nixpkgs dropped the scripted stage 1 for bcachefs (8cadc5ac03), so the
systemd initrd is always used. It starts one unlock-bcachefs-<mnt> unit
per mount point; /, /home and /nix share one encrypted filesystem, so the
units race on the device (EBUSY) and the number and order of passphrase
prompts varies (1-3, any order). The fixed OCR sequence then waited for
a /home prompt that never came.

Answer every password query on the serial console until the initrd
reaches initrd-fs.target, which pending queries block. OCR is no longer
needed.
2026-11-20 10:49:13 +01:00
lassulus f363468964 lib: reformat with nixfmt 1.5.0 2026-11-20 10:49:13 +01:00
bors afc942f709 [create-pull-request] automated change 2026-11-19 06:51:21 +00:00
lassulus 1dd30c29c8 fix systemd.initrd being default now breaking disko (#1311)
an alternative to https://github.com/nix-community/disko/pull/1304

This introduces a new globals argument which can be used to pass in
different global state into the disko type. Makes the fix a little bit
cleaner.
2026-11-10 16:35:22 +00:00
lassulus f15bcc27b4 luks: don't define boot.initrd.systemd.enable where the option was removed
NixOS 26.11 dropped scripted stage 1 (NixOS/nixpkgs#573038) and replaced
boot.initrd.systemd.enable with mkRemovedOptionModule, whose assertion
fails as soon as the option is defined. The luks type set it for
enrollFido2, so FIDO2 configs stopped evaluating (#1303). The old
mkIf would also break once the removal shim is dropped, because mkIf
cannot define an option that is not declared at all.

Emit the definition via lib.optional only when
diskoLib.systemdInitrdToggleable says the option still has its bool
type. The removed-option stub is untyped; renamed or hidden
declarations keep bool, so unlike checking `visible` this does not
misfire on aliases. Where the option is gone, stage 1 is always
systemd, so nothing needs to be set.

The flag reaches the types through globals.canToggleSystemdInitrd:
- module.nix derives it from the system's options;
- default.nix accepts canToggleSystemdInitrd (default true, the
  pre-26.11 behaviour) for direct callers of the legacy outputs;
- the test harness probes the nixpkgs under test for direct mode.

The test harness itself read config.boot.initrd.systemd.enable, which
throws on 26.11; guard it as done in lib/tests.nix of
https://github.com/nix-community/disko/pull/1304/changes#diff-605c7b66854ad3072529f715252655bb5b4e5e5b53a99edec9dc929fd85162cd
2026-11-10 13:14:11 +01:00
lassulus 1f2be5db26 types: pass rootMountPoint via a globals module arg 2026-11-10 13:03:15 +01:00
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
lassulus fb50c22daa swap: allow randomEncryption to take an attrset for extra config (#1285)
`randomEncryption` on the `swap` partition type was typed as a plain
`bool`, which only ever built `{ enable = ...; allowDiscards = ...; }`
for NixOS's `swapDevices.*.randomEncryption` submodule, so there was no
way to reach its other options (`cipher`, `sectorSize`, etc.), as noted
in the issue.

Per the maintainer's suggestion in the issue thread, this widens the
type to `lib.types.either lib.types.bool (lib.types.attrsOf
lib.types.anything)`:
- A plain `true`/`false` keeps the exact old behavior (backwards
compatible: verified both existing in-repo usages, `example/swap.nix`
and `tests/mdadm-btrfs-wipe.nix`, still use a bare bool and are
unaffected).
- An attrset enables encryption by default (`enable = true`, overridable
by setting `enable` in the attrset), and is merged over the
`enable`/`allowDiscards` defaults so any extra NixOS `randomEncryption`
options (cipher, sectorSize, ...) pass straight through.

Also introduced a `randomEncryptionEnabled` derived boolean
(`config.randomEncryption` when it's a bool, else `.enable or true`)
since the rest of the module (`_create`/`_mount`/`_unmount`) branches on
whether random encryption is active at all, and `!` doesn't work on an
attrset.

I don't have a local Nix environment to run `nix flake check` / the test
suite against this change, so flagging that so a maintainer/CI can
verify directly.

Fixes #438
2026-10-20 18:53:21 +00:00
yottanami 9d88a40600 swap: allow randomEncryption to take an attrset for extra config
randomEncryption was typed as a plain bool, which just passed
enable/allowDiscards down to NixOS's swapDevices.*.randomEncryption
submodule, with no way to reach its other options (cipher, sectorSize,
etc).

Widen the type to bool or an attrset. A bool keeps the old behavior
unchanged. An attrset enables encryption by default (overridable via
its own enable key) and is merged over the enable/allowDiscards
defaults, so extra NixOS randomEncryption options pass through.

Fixes #438
2026-10-20 20:36:20 +02:00
lassulus 7fdf779611 bcachefs format options need to go before device (#1270)
Move extraFormatArgs in front of device. Else format does fail.
2026-10-20 14:12:08 +00:00
lassulus 9e8f8438f1 docs: fix upgrade guide link pointing to a fork (#1275)
Fixes #1245

The "upgrade guide" link in `docs/HowTo.md` pointed to
`github.com/JillThornhill/disko/blob/master/docs/upgrade-guide.md` (a
fork) instead of the canonical `docs/upgrade-guide.md`, which already
exists in this repo. Changed it to a relative link.
2026-10-20 13:12:18 +00:00
lassulus 46aa0d5838 make-disk-image: add useVirtualDevices option (#1008)
I've been using Disko to both configure filesystems on my phone and
create the initial images that are flashed. The only problem was that
the installed config would have its device names overwritten. This PR
adds an option to chose if the virtual/cleaned device names should be
installed or not. They're still always used during partitioning.

For those curious, here's an example phone Disko config:
<details>
  <summary><i>expand me</i></summary>

```nix
# This config is NOT meant to be used with the Disko CLI. It should only be used with
# the Disko image builder. It represents the boot and root images that will be
# created with Disko image builder and flashed to the phone. NixOS is then able to find
# the partitions using /dev/disk/by-label based on this config.
{
  disko.devices.disk = {
    boot = let
      label = "nixos-boot";
    in {
      type = "disk";
      device = "/dev/disk/by-label/${label}";
      imageName = label;
      # vfat can't be auto-expanded by NixOS, so the initial image size must be
      # the final desired size.
      imageSize = "2G";
      content = {
        type = "filesystem";
        format = "vfat";
        mountpoint = "/boot";
        mountOptions = [
          # See https://github.com/nix-community/disko/issues/527
          "umask=0077"
          # Continuous Discard/trim For SSDs. This partition is small and not written
          # to a ton, so I doubt performance will be an issue.
          "discard"
        ];
        extraArgs = [
          "-n"
          label
          # Sector size.
          "-S"
          "4096"
        ];
      };
    };
    root = let
      label = "nixos-root";
    in {
      type = "disk";
      device = "/dev/disk/by-label/${label}";
      imageName = label;
      imageSize = "5G";
      content = {
        type = "luks";
        name = "crypt";
        settings = {
          # Enable discard/TRIM support. fstrim shouldn't be needed, b/c BTRFS
          # discard=async is default.
          # See https://wiki.archlinux.org/title/Dm-crypt/Specialties#Discard/TRIM_support_for_solid_state_drives_(SSD)
          allowDiscards = true;
          # Improve SSD performance.
          # See https://wiki.archlinux.org/title/Dm-crypt/Specialties#Disable_workqueue_for_increased_solid_state_drive_(SSD)_performance
          bypassWorkqueues = true;
        };
        extraFormatArgs = [
          "--label"
          label
          "--sector-size"
          "4096"
        ];
        # Just for initial encryption in the VM.
        passwordFile = "/tmp/nixos-root.key";
        content = {
          type = "btrfs";
          extraArgs = [
            "--sectorsize"
            "4096"
            "--force" # Force overrite existing partition
          ];
          subvolumes = {
            ...
          };
        };
      };
    };
  };
}
```
</details>
2026-10-20 13:11:42 +00:00
lassulus 7d4804ad8d luks: add test for multiple partitions and fix handling if on same disk (#1281)
This PR addresses the handling of multiple LUKS partitions on the same
disk and adds a corresponding test case.

- **Fix:** The core logic for handling multiple LUKS partitions on a
single disk was improved to ensure correct partition mapping and
unlocking. (Implemented using a custom pi agent and the **mimo-v2.5**
model).
- **Tests:** Added `luks-multiple` test to verify the behavior of
multiple LUKS partitions on the same disk. (Tests written by me).

Reproduces and fixes #1263
2026-10-20 13:11:14 +00:00
lassulus 33d5b13d6c bugfix: Detached headers idempotence check (#1286)
## Summary
Detached LUKS headers were not handled correctly by the `_create`
idempotence check in `lib/types/luks.nix`.

The old logic still probed `config.device`. For detached-header setups,
that meant rerun could mis-detect an already-initialized LUKS device and
fall back into luksFormat.

## Fix
Probe the actual LUKS header target instead of the payload device, and
make the create guard depend only on `cryptsetup isLuks` for that
target.

## Test
Add a detached-header regression test that exercises the direct-mode
idempotence path.
2026-10-20 12:51:32 +00:00
lassulus 348768c1b7 make-disk-image: support vmTools kernelModules with backward compatibility (#1301)
Closes #1298
Supersedes #1277
Supersedes #1299

### Problem
Following nixpkgs commit 68d32ed6cbd986a84582b88780168d22adebd6fc (PR
#530764), `pkgs.vmTools` split the boot kernel image (`kernel`) from the
initrd modules tree (`kernelModules`). When building disk images or
`vmWithDisko` against recent `nixpkgs-unstable`, `make-disk-image.nix`
fails during evaluation:

```
error: vmTools: the `kernel` argument (kernel-modules) has no
`target` attribute, so the kernel image filename cannot be determined.

If you are passing a module tree (e.g. from `pkgs.aggregateModules`) to
make extra modules available, pass it via `kernelModules` instead and
keep `kernel` pointing at a real kernel derivation.
```

Previous attempts (#1277, #1299) attempted an unconditional pass of
`kernelModules`, but this fails on older nixpkgs (including disko's
current locked nixpkgs) with `unexpected argument 'kernelModules'`.

### Fix
1. Added helper `diskoLib.vmToolsSupportsKernelModules`:
   ```nix
   vmToolsSupportsKernelModules =
     pkgs:
     (pkgs.vmTools.override.__functionArgs or (
if lib.isFunction pkgs.vmTools.override then builtins.functionArgs
pkgs.vmTools.override else { }
     )
     ) ? kernelModules;
   ```
2. In `lib/make-disk-image.nix`, conditionally pass `kernel` and
`kernelModules` if supported by `pkgs.vmTools`, else fall back to
`kernel = modulesTree`.

This ensures full backward compatibility across nixpkgs versions without
requiring a `flake.lock` bump.

### Verification
- **Modern nixpkgs**: Evaluated `nix eval --override-input nixpkgs
nixpkgs .#checks.x86_64-linux.make-disk-image.drvPath` — successfully
produces derivation (previously failed with the error above).
- **Locked nixpkgs**: Evaluated `nix eval
.#checks.x86_64-linux.make-disk-image.drvPath` — passes cleanly.
- **Checks & formatting**: `nix build .#checks.x86_64-linux.treefmt`,
`checkJqSyntax`, and `jsonTypes` all pass cleanly.
2026-10-20 12:51:08 +00:00
lassulus be50442cda Fix use of deprecated stdenv.isDarwin (#1288) 2026-10-20 12:35:48 +00:00
Luna Schwalbe 42afa78080 Fix use of deprecated stdenv.isDarwin 2026-10-20 14:34:28 +02:00
Ravi Arnan 61c844e2c0 fix(make-disk-image): support vmTools kernelModules with backward compatibility 2026-10-19 23:22:56 +08:00
Ravi Arnan 5c23390694 interactive-vm: disable disko.enableConfig to avoid duplicate swapDevices
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,
`interactive-vm.nix` contributes `cfg_.disko.devices._config.swapDevices`
via `diskoBasedConfiguration`.

Because `swapDevices` in NixOS is a `listOf submodule`, definitions are
merged by concatenation, causing every swap device from the disko config to
appear twice in the generated fstab. During boot, `systemd-fstab-generator`
then fails with exit status 1 due to conflicting generated swap units.

Setting `disko.enableConfig = false` in `interactive-vm.nix` prevents the outer
module from injecting unmapped host disko configurations, while allowing
`interactive-vm.nix` to supply the QEMU-mapped devices cleanly.

Closes #1283

Signed-off-by: Ravi Arnan <raviarnankeren@gmail.com>
2026-10-19 16:43:31 +08:00
Jörg Thalheim 725ea35e41 luks: retry the interactive password prompt on mismatch (#1297)
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.
2026-09-18 22:31:26 +00:00
Titouan Heyrendt 4084b6c7bd luks: retry the interactive password prompt on mismatch 2026-09-17 12:28:01 +02:00
Hussain Miyaziwala 93ec363394 luks: probe detached headers 2026-08-08 08:51:29 -04:00
Hussain Miyaziwala 2dfbf0dcb0 tests: cover detached LUKS headers 2026-08-08 08:51:29 -04:00
Maximilian Gaedig 70538c3324 fix: handling of multiple luks partitions on same disk
fixes #1263
2026-07-14 18:15:45 +02:00
Maximilian Gaedig b8955c9021 luks: add test for multiple partitions
reproduces #1263
already fails at verifying proper unmounting because the issue exists for both mounting and
unmounting
2026-07-14 18:15:45 +02:00
chrisdebian cadf6300e5 docs: fix upgrade guide link pointing to a fork
The 'upgrade guide' link in HowTo.md pointed to JillThornhill/disko
instead of the canonical docs/upgrade-guide.md in this repo.

Fixes #1245
2026-06-19 10:00:30 +01:00
June Stepp 10f31ba086 make-disk-image: add useVirtualDevices option 2026-06-14 15:03:34 -05:00
github-actions[bot] ff8702b4de flake: update inputs (#1271)
Automated changes by
[create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action
2026-06-11 04:37:56 +00:00
bors bb8b1838a7 [create-pull-request] automated change 2026-06-11 04:27:06 +00:00
noradtux 1ae020fe7c bcachefs format options need to go before device
Move extraFormatArgs in front of device. Else format does fail.
2026-06-10 11:43:33 +02:00
github-actions[bot] 24fed06cac flake: update inputs (#1268)
Automated changes by
[create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action
2026-06-08 04:56:02 +00:00
bors 85d7f921cd [create-pull-request] automated change 2026-06-08 04:41:54 +00:00
github-actions[bot] 115e521178 flake: update inputs (#1267)
Automated changes by
[create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action
2026-06-01 05:05:12 +00:00
bors 0a3481adf8 [create-pull-request] automated change 2026-06-01 04:50:56 +00:00
Michael Hoang caa775cf67 Activate unmount tests (#1150)
Adds missing testscript code to execute unmount scripts. With this
change all test derivations of the Disko examples verify proper
unmounting behaviour.

Part of stacked pull requests to enable unmount testing. This is PR 4
out of 4. Stacks on top of #1149.
Only the last commit applies to this PR.

See #1140 for ealier discussion.
2026-05-29 09:56:52 +00:00
Bert Proesmans 8ff2716d01 Fix(test); Add idempotent unmounting to tests of example configuration 2026-05-29 08:41:07 +02:00
Bert Proesmans 2c40806b93 feat(mdadm); start mdadm before mounting datasets 2026-05-29 08:41:07 +02:00
Bert Proesmans 5c7406ecc5 Fix(zfs_volume); Volume mount/unmount with encryption
- Fix consistent use of fully qualified dataset path
- Add idempotent unmounting with encryption keys
2026-05-29 08:41:07 +02:00
Bert Proesmans 03e19b4f67 Feature(zfs_volume); Add internal option for fully qualified zfs path 2026-05-29 08:41:07 +02:00
github-actions[bot] 36c1d04e85 flake: update inputs (#1239)
Automated changes by
[create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action
2026-05-28 04:21:46 +00:00
bors 85e79db1bd [create-pull-request] automated change 2026-05-28 04:08:17 +00:00
Michael Hoang 5ba0c9555c luks: add test for FIDO2 (#1264) 2026-05-25 09:00:11 +00:00
Michael Hoang a1b9822f03 luks: add test for FIDO2 2026-05-25 10:55:36 +02:00
Michael Hoang 640d1dd8e0 tests: fix enabling Canokey 2026-05-25 10:55:36 +02:00
Michael Hoang 7da3d737f7 luks: fix not asking for password in format script 2026-05-20 00:19:04 +02:00
Michael Hoang 0d15976fce luks: don't depend on autogenerated password 2026-05-20 00:14:40 +02:00
Michael Hoang d60b2b5e00 luks: improve idempotency for enrolling FIDO2
Using FIDO2 automatically generates a temporary password for setting up LUKS
which is not available on subsequent runs of the script causing the format
script to crash with `password: unbound variable`.
2026-05-20 00:07:06 +02:00