From b8955c90218eca1db56bc6d951266f2932044540 Mon Sep 17 00:00:00 2001 From: Maximilian Gaedig Date: Tue, 14 Jul 2026 17:22:37 +0200 Subject: [PATCH 1/2] luks: add test for multiple partitions reproduces #1263 already fails at verifying proper unmounting because the issue exists for both mounting and unmounting --- example/luks-multiple.nix | 65 +++++++++++++++++++++++++++++++++++++++ lib/tests.nix | 6 ++++ tests/luks-multiple.nix | 22 +++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 example/luks-multiple.nix create mode 100644 tests/luks-multiple.nix diff --git a/example/luks-multiple.nix b/example/luks-multiple.nix new file mode 100644 index 0000000..88775d2 --- /dev/null +++ b/example/luks-multiple.nix @@ -0,0 +1,65 @@ +{ + 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" ]; + }; + }; + root = { + size = "100%"; + content = { + type = "luks"; + name = "root"; + extraOpenArgs = [ ]; + settings = { + # if you want to use the key for interactive login be sure there is no trailing newline + # for example use `echo -n "password" > /tmp/secret.key` + keyFile = "/tmp/secret.key"; + allowDiscards = true; + }; + additionalKeyFiles = [ "/tmp/additionalSecret.key" ]; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; + }; + home = { + size = "100M"; + content = { + type = "luks"; + name = "home"; + extraOpenArgs = [ ]; + settings = { + # if you want to use the key for interactive login be sure there is no trailing newline + # for example use `echo -n "password" > /tmp/secret.key` + keyFile = "/tmp/secret.key"; + allowDiscards = true; + }; + additionalKeyFiles = [ "/tmp/additionalSecret.key" ]; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/home"; + }; + }; + }; + }; + }; + }; + }; + }; +} diff --git a/lib/tests.nix b/lib/tests.nix index 4b8b95a..eef986d 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -82,6 +82,8 @@ let efi ? !pkgs.stdenv.hostPlatform.isRiscV64, enableCanokey ? false, postDisko ? "", + postUnmountPreMount ? "", + postMount ? "", testMode ? "module", # can be one of direct module cli testBoot ? true, # if we actually want to test booting or just create/mount enableOCR ? false, @@ -369,7 +371,9 @@ let machine.succeed("${lib.getExe tsp-mount}") # verify that mount is idempotent machine.succeed("${lib.getExe tsp-unmount}") machine.succeed("${lib.getExe tsp-unmount}") # verify that umount is idempotent + ${postUnmountPreMount} machine.succeed("${lib.getExe tsp-mount}") # verify that mount is idempotent + ${postMount} machine.succeed("${lib.getExe tsp-disko} --yes-wipe-all-disks") # verify that we can destroy and recreate machine.succeed("mkdir -p /mnt/home") machine.succeed("touch /mnt/home/testfile") @@ -383,7 +387,9 @@ let machine.succeed("${lib.getExe nodes.machine.system.build.mount}") # verify that mount is idempotent machine.succeed("${lib.getExe nodes.machine.system.build.unmount}") machine.succeed("${lib.getExe nodes.machine.system.build.unmount}") # verify that unmount is idempotent + ${postUnmountPreMount} machine.succeed("${lib.getExe nodes.machine.system.build.mount}") # verify that mount is idempotent + ${postMount} machine.succeed("${lib.getExe nodes.machine.system.build.destroyFormatMount} --yes-wipe-all-disks") # verify that we can destroy and recreate again machine.succeed("mkdir -p /mnt/home") machine.succeed("touch /mnt/home/testfile") diff --git a/tests/luks-multiple.nix b/tests/luks-multiple.nix new file mode 100644 index 0000000..bb0bb95 --- /dev/null +++ b/tests/luks-multiple.nix @@ -0,0 +1,22 @@ +{ + pkgs ? import { }, + diskoLib ? pkgs.callPackage ../lib { }, +}: +diskoLib.testLib.makeDiskoTest { + inherit pkgs; + name = "luks-multiple"; + disko-config = ../example/luks-multiple.nix; + testBoot = false; + postUnmountPreMount = '' + machine.fail("mountpoint /mnt/"); + machine.fail("mountpoint /mnt/home"); + machine.fail("${pkgs.cryptsetup}/bin/cryptsetup status root") + machine.fail("${pkgs.cryptsetup}/bin/cryptsetup status home") + ''; + postMount = '' + machine.succeed("mountpoint /mnt/"); + machine.succeed("mountpoint /mnt/home"); + machine.succeed("${pkgs.cryptsetup}/bin/cryptsetup status root") + machine.succeed("${pkgs.cryptsetup}/bin/cryptsetup status home") + ''; +} From 70538c3324ad7b8a51a18ec9cc44b113c2d2b905 Mon Sep 17 00:00:00 2001 From: Maximilian Gaedig Date: Tue, 14 Jul 2026 17:42:00 +0200 Subject: [PATCH 2/2] fix: handling of multiple luks partitions on same disk fixes #1263 --- lib/types/gpt.nix | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/types/gpt.nix b/lib/types/gpt.nix index 5f7b26d..a1597b3 100644 --- a/lib/types/gpt.nix +++ b/lib/types/gpt.nix @@ -342,30 +342,24 @@ in inherit config options; default = let - partMounts = lib.foldr lib.recursiveUpdate { } ( - map (partition: lib.optionalAttrs (partition.content != null) partition.content._mount) ( - lib.attrValues config.partitions - ) - ); + activePartitions = lib.filter (p: p.content != null) (lib.attrValues config.partitions); + mounts = map (p: p.content._mount) activePartitions; in { - dev = partMounts.dev or ""; - fs = partMounts.fs or { }; + dev = lib.concatStringsSep "\n" (map (m: m.dev or "") mounts); + fs = lib.foldr lib.recursiveUpdate { } (map (m: m.fs or { }) mounts); }; }; _unmount = diskoLib.mkUnmountOption { inherit config options; default = let - partMounts = lib.foldr lib.recursiveUpdate { } ( - map (partition: lib.optionalAttrs (partition.content != null) partition.content._unmount) ( - lib.attrValues config.partitions - ) - ); + activePartitions = lib.filter (p: p.content != null) (lib.attrValues config.partitions); + unmounts = map (p: p.content._unmount) activePartitions; in { - dev = partMounts.dev or ""; - fs = partMounts.fs or { }; + dev = lib.concatStringsSep "\n" (map (m: m.dev or "") unmounts); + fs = lib.foldr lib.recursiveUpdate { } (map (m: m.fs or { }) unmounts); }; }; _config = lib.mkOption {