mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 13:03:28 +01:00
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.<name>.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.
82 lines
2.9 KiB
Nix
82 lines
2.9 KiB
Nix
{ pkgs, lib, ... }:
|
|
{
|
|
disko.devices = {
|
|
disk = {
|
|
main = {
|
|
type = "disk";
|
|
device = "/dev/vdb";
|
|
content = {
|
|
type = "gpt";
|
|
partitions = {
|
|
ESP = {
|
|
size = "500M";
|
|
type = "EF00";
|
|
content = {
|
|
type = "filesystem";
|
|
format = "vfat";
|
|
mountpoint = "/boot";
|
|
mountOptions = [ "umask=0077" ];
|
|
};
|
|
};
|
|
luks = {
|
|
size = "100%";
|
|
content = {
|
|
type = "luks";
|
|
name = "crypted";
|
|
settings.allowDiscards = true;
|
|
passwordFile = "/tmp/secret.key";
|
|
content = {
|
|
type = "filesystem";
|
|
format = "ext4";
|
|
mountpoint = "/";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
disko.test = {
|
|
name = "luks-interactive-login";
|
|
enableOCR = true;
|
|
bootCommands = ''
|
|
machine.wait_for_text("[Pp]assphrase for")
|
|
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")
|
|
);
|
|
};
|
|
};
|
|
}
|