From 09e8239ab3d86529a4f10a309f7a82225c7dbdd3 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Mon, 18 May 2026 03:56:39 +0200 Subject: [PATCH] lib/tests.nix: deep-strip _* attrs from list elements in prepareDiskoConfig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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..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. --- lib/tests.nix | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/tests.nix b/lib/tests.nix index 2c75699..9ec7bfd 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -10,10 +10,31 @@ let testLib = { # this takes a nixos config and changes the disk devices so we can run them inside the qemu test runner # basically changes all the disk.*.devices to something like /dev/vda or /dev/vdb etc. + # + # TODO: remove this once the rest of the test machinery moves to per-leaf + # `disko.devices.disk..device = lib.mkForce …;` overrides on the + # existing module-system value. Reassigning the whole `disko.devices` + # value here is what forces the `_*` stripping below — without that + # reassignment there'd be no readOnly conflicts to work around. prepareDiskoConfig = cfg: devices: let - cleanedTopLevel = lib.filterAttrsRecursive (n: _: !lib.hasPrefix "_" n) cfg; + # Strip every `_`-prefixed disko-internal attr (`_config`, `_meta`, + # `_create`, `_mount`, `_unmount`, `_pkgs`, …) — they're all + # readOnly+computed and the node eval recomputes them identically. + # `lib.filterAttrsRecursive` only descends into attrsets, not list + # elements, so the legacy `partitions = [ … ]` list otherwise keeps + # its `_config` per entry and collides with filesystem.nix's + # readOnly default at the node. + deepStripUnderscore = + v: + if lib.isAttrs v then + lib.mapAttrs (_: deepStripUnderscore) (lib.filterAttrs (n: _: !lib.hasPrefix "_" n) v) + else if lib.isList v then + map deepStripUnderscore v + else + v; + cleanedTopLevel = deepStripUnderscore cfg; preparedDisks = lib.foldlAttrs