From 1be12abec39e77cbc43fe56ff83047eb8f945bd1 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Mon, 18 May 2026 15:49:02 +0200 Subject: [PATCH] example/luks-interactive-login: cover the install-test override mechanism MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extend the example so it doubles as a test that asserts `disko.test.defaults` propagates to both install-test nodes: - A test-only LUKS password (`pkgs.writeText "luks-test-password" "custompassword"`) is set via `disko.test.defaults` — the test framework's "imported into every node" hook. The example's user-facing default (`passwordFile = "/tmp/secret.key";`) is preserved for anyone importing this file into their own NixOS config; the override fires only inside `system.build.diskoTest`. - `bootCommands` types `custompassword\n` at the LUKS prompt. For the unlock to succeed, format must have encrypted with the same password — i.e. `defaults` must propagate to `nodes.formatter` (which runs `disko format`) as well as `nodes.machine` (whose initrd prompts at boot). - `extraChecks` asserts the LUKS volume exists at the expected device path and `/` is mounted. If `defaults` ever stops propagating to the formatter, format would encrypt with the example's `/tmp/secret.key` default (`secretsecret`, written by the test framework's testScript) while `bootCommands` types `custompassword` — the initrd's LUKS unlock fails and the test catches the regression at the boot phase. KNOWN ISSUE: `defaults` does NOT currently propagate to `disko.devices.*` paths under the existing `install-test.nix` shape. `install-test.nix` sets `disko.devices = testConfigBooted.disko.devices` on each node as a whole-attrset definition; the user's leaf override from `defaults` is buried inside its outer-attrset wrapper and discarded by the priority filter at the `disko.devices` option, regardless of `lib.mkForce` on the leaf. As a result this test currently FAILS at the boot phase — by design, since that failure is the assertion. Future work: narrow `install-test.nix`'s per-node `disko.devices` setter to leaf-level `disk..device = lib.mkForce …` overrides so the surrounding content tree (including user `defaults` overrides) flows through the existing host-eval value. When that lands, this test starts passing. --- example/luks-interactive-login.nix | 33 +++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/example/luks-interactive-login.nix b/example/luks-interactive-login.nix index 077546a..2171ef9 100644 --- a/example/luks-interactive-login.nix +++ b/example/luks-interactive-login.nix @@ -1,3 +1,4 @@ +{ pkgs, lib, ... }: { disko.devices = { disk = { @@ -36,15 +37,45 @@ }; }; }; + disko.test = { name = "luks-interactive-login"; enableOCR = true; bootCommands = '' machine.wait_for_text("[Pp]assphrase for") - machine.send_chars("secretsecret\n") + machine.send_chars("custompassword\n") ''; extraChecks = '' machine.succeed("cryptsetup isLuks /dev/vda2"); + machine.succeed("mountpoint /") ''; + + # FIXME: this override currently does NOT propagate to the install-test + # nodes. `install-test.nix` sets `disko.devices = testConfigBooted.disko.devices` + # on each node as a whole-attrset definition. The user's leaf-level + # override from `defaults` is buried inside its outer-attrset wrapper + # and discarded by the priority filter at the `disko.devices` option, + # regardless of `lib.mkForce` on the leaf. + # + # Until `install-test.nix` is refactored to set just per-disk leaf + # paths (rather than the whole `disko.devices` attrset), this test + # fails at the boot phase: format encrypts with `/tmp/secret.key`'s + # contents (the test framework writes `secretsecret` there), + # `bootCommands` types `custompassword`, and the initrd's LUKS unlock + # mismatches. That failure mode is exactly the assertion the test is + # designed to make — `defaults` MUST propagate to both `nodes.formatter` + # (which runs disko's format) and `nodes.machine` (whose initrd reads + # passwordFile at the prompt). When the structural fix lands, this + # test starts passing automatically and the demo becomes load-bearing + # regression coverage for `defaults` propagation. + defaults = { + # Test-only LUKS password: overrides the example's `/tmp/secret.key` + # default. The override fires only inside `system.build.diskoTest` — + # a user importing this example into their own NixOS config keeps + # `passwordFile = "/tmp/secret.key"` as the user-facing default. + disko.devices.disk.main.content.partitions.luks.content.passwordFile = lib.mkForce ( + toString (pkgs.writeText "luks-test-password" "custompassword") + ); + }; }; }