From 7da3d737f71783d224c94096d517d51632002c93 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Tue, 19 May 2026 16:40:14 +0200 Subject: [PATCH] luks: fix not asking for password in format script --- lib/types/luks.nix | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/types/luks.nix b/lib/types/luks.nix index cf9e631..9fc0b02 100644 --- a/lib/types/luks.nix +++ b/lib/types/luks.nix @@ -62,10 +62,25 @@ let ''; # Use this open command when you want to open it after full enrollment, e.g. at mount time or in standard enrollments. - cryptsetupOpen = createOpenCommand { - inherit keyFileArgs; - tokenType = if config.enrollFido2 then "systemd-fido2" else null; - }; + cryptsetupOpen = '' + ${lib.optionalString config.askPassword '' + if [ -z "''${password:-}" ]; then + if [ -z ''${IN_DISKO_TEST+x} ]; then + set +x + echo "Enter password for ${config.device}" + IFS= read -r -s password + export password + set -x + else + export password=disko + fi + fi + ''} + ${createOpenCommand { + inherit keyFileArgs; + tokenType = if config.enrollFido2 then "systemd-fido2" else null; + }} + ''; # Use this open command when you want to open it immediately after the formatting and before the stage 2 process is finished (i.e. the wipe slot). formatCryptsetupOpen = createOpenCommand { @@ -297,17 +312,6 @@ in { dev = '' if ! cryptsetup status "${config.name}" >/dev/null 2>/dev/null; then - ${lib.optionalString config.askPassword '' - if [ -z ''${IN_DISKO_TEST+x} ]; then - set +x - echo "Enter password for ${config.device}" - IFS= read -r -s password - export password - set -x - else - export password=disko - fi - ''} ${cryptsetupOpen} fi ${lib.optionalString (config.content != null) contentMount.dev or ""}