bugfix: Detached headers idempotence check (#1286)

## Summary
Detached LUKS headers were not handled correctly by the `_create`
idempotence check in `lib/types/luks.nix`.

The old logic still probed `config.device`. For detached-header setups,
that meant rerun could mis-detect an already-initialized LUKS device and
fall back into luksFormat.

## Fix
Probe the actual LUKS header target instead of the payload device, and
make the create guard depend only on `cryptsetup isLuks` for that
target.

## Test
Add a detached-header regression test that exercises the direct-mode
idempotence path.
This commit is contained in:
lassulus authored and GitHub committed 2026-10-20 12:51:32 +00:00
commit 33d5b13d6c
3 files changed
+63 -1

No files matched your search

+6 -1
View File
@@ -10,6 +10,11 @@
let
# These options will automatically generate a temporary password and remove it later on.
autogeneratedPassword = config.enrollFido2;
luksProbeTarget =
if config.settings ? "header" && config.settings.header != null then
config.settings.header
else
config.device;
keyFile =
if config.settings ? "keyFile" then
@@ -199,7 +204,7 @@ in
_create = diskoLib.mkCreateOption {
inherit config options;
default = ''
if ! blkid "${config.device}" >/dev/null || ! cryptsetup isLuks "${config.device}"; then
if ! cryptsetup isLuks "${luksProbeTarget}"; then
${lib.optionalString config.askPassword ''
promptSecret() {
prompt=$1