Commit Graph
355 Commits
Author SHA1 Message Date
Michael Hoang c431a60b34 flake + lib + module: drop unused makeTest/eval-config/qemu-common arg threading
After the makeDiskoTest rewrite (commit 4) and the tests/ modulification
(commit 5), the `makeTest`, `eval-config`, and `qemu-common` args
threaded through

  flake.nix         -> diskoLib = import ./lib { … }
                   -> import ./tests { … }
  lib/default.nix   -> testLib = import ./tests.nix { … }
  module.nix        -> _module.args.diskoLib = import ./lib { … }

are dead — every callsite now imports
`nixos/lib/eval-config.nix` and `nixos/lib/qemu-common.nix` directly
from `pkgs.path` (see `lib/tests.nix`, `lib/install-test.nix`,
`tests/default.nix`). `makeTest` is replaced by the
`nixos-lib.evalTest` call in `module.nix`'s `installTestEval` block.

Strip the dead threading:
  - `flake.nix`: drop the three args from the `diskoLib = import ./lib`
    call and the `import ./tests` call.
  - `lib/default.nix`: drop them from the function signature and from
    the `testLib = import ./tests.nix { … }` call; drop the
    `qemu-common-lib` derivation that wrapped `qemu-common`.
  - `lib/tests.nix`: drop them from the function signature.
  - `module.nix`: drop them from the inner `_module.args.diskoLib =
    import ./lib { … }` call; drop the now-unused `modulesPath` arg
    destructure (its only consumers were the three
    `import "${modulesPath}/..."` lines just removed).
2026-05-18 14:21:23 +02:00
Michael Hoang 6e082c9e74 lib/tests.nix: rewrite makeDiskoTest body to use NixOS eval-config
Internal-only refactor. The function's argument shape is unchanged so
the 45 in-repo `tests/*.nix` callers don't need to be touched (yet) —
they keep calling `makeDiskoTest { name = …; disko-config = …; … }`
and get equivalent derivations back.

The new body is a thin wrapper around nixpkgs's
`nixos/lib/eval-config.nix`. `module.nix` is a NixOS module — it
writes to `system.build`, `fileSystems`, `boot`, `swapDevices`,
`networking.hostId`, `assertions`, `warnings` — so the host eval has
to be a NixOS eval. The result is identical to what
`nixosConfigurations.X.config.system.build.diskoTest` would have
produced; we just construct that NixOS eval inline rather than
requiring callers to wire it themselves.

Arg-to-option mapping:
  - `extraSystemConfig`    → `disko.test.nodes.machine`
  - `extraInstallerConfig` → `disko.test.nodes.formatter`
  - `bootCommands`, `efi`, `enableOCR`, `postDisko`, `enableCanokey`,
    `name` → `disko.test.<same>`
  - `extraTestScript` → `disko.test.extraChecks`
  - `testBoot` → `disko.test.boot`
  - `testMode` → `disko.test.mode` (enum `[ "module" "direct" ]`; the
    `"cli"` enum value mentioned in the old doc comment was a synonym
    for `"direct"` that hasn't been branched on in years — dropped.)

The manual-merging machinery (`installed-system`, `installedTopLevel`,
in-body `prepareDiskoConfig` calls, the entire raw `testScript` Python
block) is gone — that logic now lives in `lib/install-test.nix` and
runs as part of the test eval inside `module.nix`'s `installTestEval`.

`diskoLib.testLib.prepareDiskoConfig` and `diskoLib.testLib.devices`
stay exported — still used by `lib/interactive-vm.nix` and the new
`lib/install-test.nix`.

`extendModules` is kept in the signature (with default null) but
unused — the legacy callsite in `module.nix` already stopped passing
it in the previous commit, but external callers might still.
2026-05-18 14:21:23 +02:00
Michael Hoang 9f4cb09648 module.nix: wire disko.test as the test eval
Five coupled changes that must land together because they form one
atomic refactor of disko's test-option surface:

  - Define `installTestEval` in the let-block via
    `nixos-lib.evalTest`, importing `./lib/install-test.nix` and
    threading `diskoLib`, `diskoDevices` (and indirectly `pkgs` via
    `hostPkgs`) into the test eval's module args. Propagate the
    host-level `networking.hostId` to every node via the framework's
    native `defaults` hook — single source of truth, so
    `lib/install-test.nix` drops its per-node hostId setter on
    `nodes.formatter` (the host eval's hostId now flows to formatter
    and machine identically).

  - Declare `options.disko.test` as a submodule whose type is borrowed
    from `installTestEval.type` — i.e. the full NixOS-test option tree
    (`nodes`, `testScript`, `defaults`, `globalTimeout`, …) plus the
    seven disko knobs declared in `./lib/install-test.nix`. Add
    `diskoTest = lib.mkDefault config.disko.test.test;` to the
    `system.build` attrset next to the existing
    `installTest = makeDiskoTest { … };` (the legacy definition stays
    for this commit).

  - Delete the flat `disko.tests.{bootCommands,efi,enableOCR,extraChecks,extraConfig}`
    declarations from the `options.disko` block. Drop the now-deleted
    `config.disko.tests.extraConfig` import from `vmVariantWithDisko`'s
    `extendModules` call.

  - Add migration modules to the imports list:
      - `mkRemovedOptionModule` for `disko.tests.extraConfig` with a
        message pointing users at `disko.test.defaults` /
        `virtualisation.vmVariantWithDisko = { imports = [ … ]; };`.
      - 8 × `mkRenamedOptionModule` redirecting flat knobs into the
        `disko.test` submodule. Existing user configs keep working with
        one deprecation warning per renamed setter.

  - Update `lib/interactive-vm.nix:66`: `config.disko.tests.efi` →
    `config.disko.test.efi`. The legacy path would still resolve via
    the rename but emit a deprecation warning on every interactive-VM
    eval — update the callsite to be quiet.

The legacy `installTest = makeDiskoTest { … };` in the `system.build`
attrset is left in place but its read of `cfg.tests.extraConfig` is
dropped (the option no longer exists; the other reads forward through
`mkRenamedOptionModule`). The next commit replaces its RHS with
`lib.mkDefault config.disko.test.test` so both attrset entries point at
the same drv.
2026-05-18 14:21:23 +02:00
Michael Hoang 7a420ab8b0 lib: add install-test machinery (inert)
Three new files that will replace the manual-merging body of
`makeDiskoTest` in lib/tests.nix:

  - lib/install-test.nix:           pure NixOS test module declaring
                                    the 7 disko convenience knobs
                                    (extraChecks, bootCommands, boot,
                                    efi, postDisko, enableCanokey, mode)
                                    alongside the config that consumes
                                    them. Owns the nodes.{formatter,
                                    machine} blocks and the testScript.
                                    The formatter's `../module.nix`
                                    import is gated on
                                    `config.mode == "module"` —
                                    `direct` mode uses pre-built
                                    standalone CLI scripts and doesn't
                                    need the module's
                                    `system.build.{format,mount,…}`
                                    derivations.
  - lib/install-test-formatter.nix: per-node base for the formatter VM
                                    (test-instrumentation + qemu-guest +
                                    swraid + nix.settings tweaks).
                                    Disko module + `disko.enableConfig =
                                    false`/`checkScripts = true` /
                                    forced `disko.devices` are set by
                                    `install-test.nix` only in
                                    `mode = "module"`.
  - lib/install-test-machine.nix:   per-node base for the booted system
                                    being tested. Imports the disko
                                    module unconditionally (the booted
                                    system always needs disko's
                                    generated fileSystems/boot/swapDevices).

Nothing imports these yet; the files are inert until the next commit
wires `disko.test` as the host eval's submodule pointing at them.

Part of the makeDiskoTest -> evalModules refactor outlined in
`~/.claude/plans/disko-test-refactor.md`.
2026-05-18 14:21:23 +02:00
Michael Hoang 09e8239ab3 lib/tests.nix: deep-strip _* attrs from list elements in prepareDiskoConfig
`prepareDiskoConfig` strips disko's `_`-prefixed internal attrs
(`_config`, `_meta`, `_create`, `_mount`, `_unmount`, `_pkgs`) —
every disko submodule declares these as `internal = true; readOnly =
true` with computed defaults. The function then reassigns the cleaned
value to `disko.devices` on a fresh module eval; if any `_*` attrs
leak through, the node eval's readOnly defaults collide with the
carried-through values and the merge errors.

The original implementation used `lib.filterAttrsRecursive` which
only descends into attrsets, not list elements. The legacy
`partitions = [ … ]` list (the disko `table` content type) therefore
kept its `_config` per entry — the well-known "set multiple times"
error called out in `lib/types/table.nix`'s deprecation warning.

Replace it with a small `deepStripUnderscore` helper that descends
into both attrsets and lists. Adds a TODO: this whole-tree rewrite
becomes unnecessary once test-time substitution moves to per-leaf
`disko.devices.disk.<name>.device = lib.mkForce …;` overrides on the
existing module-system value (rather than reassigning the whole
`disko.devices` value), which is the natural evolution of the
disko.test refactor.
2026-05-18 14:21:23 +02:00
June Stepp 4c81091646 make-disk-image: don't build native /etc.
Grab just the udev part.
2026-05-16 09:07:05 -05:00
Sandro 1be7610ee9 Remove alias usage 2026-05-02 01:02:39 +02:00
lassulus ce160f5185 Fix failing ShellCheck for LUKS partitions (#1250)
Trivial fix
2026-04-19 15:42:53 +00:00
Raito Bezarius b02541f2d0 feat: add FIDO2 & recovery support for LUKS
This introduces what has been described in
https://0pointer.net/blog/unlocking-luks2-volumes-with-tpm2-fido2-pkcs11-security-hardware-on-systemd-248.html.

That is: support for FIDO2 and recovery passphrases and their boot
mechanism.

Testing is hard right now because of canokey-qemu being broken and U2F
is not a valid replacement for FIDO2…

I tried to keep as much as possible the previous behavior and make it
possible to mix FIDO2 and normal passphrases or key files without any
problem.

PIV support is out of scope for this change but can easily be added.

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2026-04-19 15:26:35 +02:00
magic_rb 47deadb7c1 Fix failing ShellCheck for LUKS partitions
Signed-off-by: magic_rb <magic_rb@redalder.org>
2026-04-13 14:23:41 +02:00
Jörg Thalheim 878ec37d6a Escape ZFS args (#1222)
Args to ZFS (like mountpoints) might have spaces or other
shell-unfriendly characters in them. This escapes those so they get
passed to zfs correctly.
2026-03-14 16:38:37 +00:00
Jörg Thalheim c4d34f2031 fix: correct typos across docs and messages (#1229)
## Summary

This PR fixes typos in docs and user-facing messages.

## Detailed Changes

| File | Fixed |
|---|---|
| `scripts/create-release.nix` | `uncommited` -> `uncommitted` (4x) |
| `lib/default.nix:906` | `Depracated` -> `Deprecated` |
| `lib/tests.nix:195` | `mkOveride` -> `mkOverride` |
| `docs/interactive-vm.md:3` | `similiar` -> `similar` |
| `docs/disko-images.md:82` | `involed` -> `involved` |
| `docs/disko-images.md:110` | `scirpt` -> `script` |
| `docs/table-to-gpt.md:62` | `partiton` -> `partition` |
| `lib/make-disk-image.nix:212` | `involed` -> `involved` |
| `docs/disko-images.md:11` | `In the this example` -> `In this example`
|

No intended behavior change.

Closes #1228
2026-03-14 16:34:36 +00:00
lassulus eaafb89b56 Mount file-systems in the correct order (#1057)
Use the `fsBefore` function from NixOS to sort the file-systems.
The function originates from `nixpkgs/nixos/lib/utils.nix`, but the file
is a lambda that requires more arguments than we have available.
2026-03-07 07:05:52 +00:00
Francesco Zanini 0597c9262e Mount file-systems in the correct order
Use the `fsBefore` function from NixOS to sort the file-systems.
The function originates from `nixpkgs/nixos/lib/utils.nix`, but the file
is a lambda that requires more arguments than we have available.
2026-03-05 09:33:32 +01:00
lassulus 42affa9d33 Better handling of bind mounts in make-disk-image (#1056)
The device of the bind mounts is incorrectly taken verbatim while making
the image. The root hierarchy is mounted at `config.rootMountDir`
(`/mnt` by default) during the process, and this commit prepends that
path to the `device` in these cases.
2026-03-05 08:25:10 +00:00
luojiyin 29d01f4245 test: fix typo in mkOverride comment 2026-03-05 12:13:09 +08:00
luojiyin 6be2229087 fix: correct typo in disk image help text 2026-03-05 12:13:08 +08:00
luojiyin 8b94abcd23 fix: correct deprecation typo in lib default 2026-03-05 12:13:08 +08:00
Josh Gustafson dff80bbcd9 Escape ZFS args 2026-03-02 09:31:30 -07:00
Michael Hoang ec90d55ff3 lib: pass stdenv to qemu-common not pkgs 2026-01-20 12:57:44 +00:00
Michael Hoang 5ae05d98d2 treewide: reformat 2026-01-20 12:57:44 +00:00
Jörg Thalheim 916506443e make-disk-image: quote $rootMountPoint for consistency
All other usages of $rootMountPoint in this file are quoted, so apply
the same style here for readability.
2025-12-19 13:25:02 +00:00
Jörg Thalheim 6b172212b6 disko-install: resolve symlinks in mount point path
Nix refuses to operate when the store path or its parent directories
contain symlinks. On some systems /mnt can be a symlink, causing
disko-install to fail with:

  error: the path '"/mnt"' is a symlink; this is not allowed for the
  Nix store and its parent directories

Use realpath to resolve symlinks before passing the mount point to
nix-store and nixos-install commands.
2025-12-19 13:25:02 +00:00
qbisi 7194cfe5b7 downgrade the priority of kernelPackages set from imageBuilder 2025-12-15 10:34:05 +00:00
nothingnesses be1a6b8a05 bcachefs: fix subvolume mounting 2025-12-14 04:58:58 +00:00
Michael Hoang f2bba803a7 treewide: reformat 2025-12-14 04:58:58 +00:00
fidgetingbits e65362ceef feat(mdadm): add extraArgs option 2025-12-10 00:31:19 +00:00
Jörg Thalheim 8e68aa819d disko-images: add copyNixStoreThreads option for configurable parallelism
Allow users to override the automatic thread count detection for nix
store copying. The default "auto" behavior remains unchanged (min of
nproc and 8), but users can now specify a fixed thread count for
environments where the automatic detection isn't optimal.
2025-12-09 08:59:57 +00:00
Jörg Thalheim 10cdd63203 disko-images: switch back from xcp to cp for improved stability 2025-12-09 08:59:57 +00:00
Bert Proesmans a799338d17 fix(luks); Passthrough filesystems of content for unmounting 2025-11-20 14:10:46 +00:00
Bert Proesmans fa7a23d0ef fix(nodev); Set device default to fstype config
The value for device is copied into the SOURCE column of findmnt.
By default this is "none". The mount and unmount scripts
branch on SOURCE=fsType specifically, and the existence of "none"
in the SOURCE column causes wrong branches to be executed.
For a list of special filesystems, the default value "none"
is replaced by the value for fsType.
2025-11-20 14:10:46 +00:00
Bert Proesmans d9e12a2c7f fix(zpool); Ignore shadow-mount error during recreate of zpool at existing non-empty path 2025-11-20 14:10:46 +00:00
Bert Proesmans d8a3e367bd Fix(mdadm); unmount not passing through filesystems set from content 2025-11-20 14:10:46 +00:00
Bert Proesmans 436fd911cf Fix(zfs_fs); Mount/Unmount with encryption
- Fix typo against full dataset path argument
- Make unmount with encryption keys idempotent
2025-11-20 14:10:46 +00:00
Jörg Thalheim a19c2b6d3a tests: use nixpkgs qemu-common for proper machine type configuration
QEMU on aarch64 requires an explicit machine type (e.g., '-machine virt'),
unlike x86_64 which has a default. Previously, the test script hardcoded
'qemu-kvm' without machine type arguments, causing aarch64 tests to fail
with "No machine specified, and there is no default".

By importing and using nixpkgs' qemu-common.nix library, we reuse the
existing platform-specific QEMU configuration logic.
2025-11-20 13:42:11 +00:00
Jörg Thalheim af087d076d disko: drop more eval warnings 2025-11-04 17:23:16 +00:00
Jörg Thalheim 3f65d72ca6 disko/tests: silence mdadm tests 2025-11-04 17:23:16 +00:00
Francesco Zanini 6f4cf5abbe Set kernelPackages in native builder
In some cases, the kernel is not defined for cross-arch builds.
2025-10-31 08:29:56 +00:00
Edwin Mackenzie-Owen fec5efebfc gpt: trigger udev after marking hybrid mbr partitions as bootable
Even though we don't depend on the MBR bootable flag in the following
steps, not running udevadm trigger and waiting for settle can cause
/dev/disk/by-partlabel entries to be absent when formatting filesystems
immediately after modifying the partition table.
2025-10-31 08:24:29 +00:00
Gabriel Nützi 3a9450b26e fix: forward arguments to vmWithDisko 2025-10-17 11:39:50 +00:00
Michael Hoang 67ff9807dd lib: fix mdadm warning when using config.system.build.installTest 2025-09-19 13:18:24 +00:00
Sergey Kazenyuk 31fe7eda26 gpt: add partition attributes 2025-09-07 14:37:19 +00:00
Jörg Thalheim a5c4f2ab72 make-disk-image: use modules output of a kernel if present
This is a hotfix that could be reverted if we get:

https://github.com/NixOS/nixpkgs/pull/439178

in.
2025-09-01 13:33:49 +00:00
Jörg Thalheim bafad29f89 make-disk-image: also use xcp 2025-08-25 09:53:42 +00:00
lassulus 4073ff2f48 types.luks: fix password check 2025-08-18 12:26:12 +00:00
Glen Huang 3db2f04765 allow subtype definitions to be broken up 2025-07-21 12:13:55 +00:00
Scott Edlund 8fd2d6c750 make-disk-image: QEUM_OPTS -> QEMU_OPTS 2025-06-23 12:03:50 +00:00
Francesco Zanini 590de6c248 Better handling of bind mounts in make-disk-image
The device of the bind mounts is incorrectly taken verbatim while making the image.
The root hierarchy is mounted at `config.rootMountDir` (`/mnt` by default) during the process,
and this commit prepends that path to the `device` in these cases.
2025-06-06 17:37:45 +02:00
Mitch Fossen d74db625a5 remove quotes from --label creation for bcachefs
fixes device groups, for example where the disko config given looks like:

label = "fast.dev1";

after formatting, the device has a literal label of "fast.dev1" which
breaks bcachefs device groups:

echo fast > /sys/fs/bcachefs/<id>/options/foreground_target

gives the error Invalid argument, echo fast.dev1 fails as well

echo "\"fast\"" fails the same, however echo "\"fast.dev1\"" succeeds

after this, device labels and groups work as expected and any component
of the label can be used for a *_target
2025-06-05 18:16:20 +00:00
Jörg Thalheim 6bb82b77ce luks: drop unnecessary subshell 2025-05-08 09:13:14 +00:00