From 5a9f2498fbe02c51fb1359240f53966fb3534905 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sun, 21 Jul 2024 22:45:00 +0200 Subject: [PATCH] luks: add testmode password "disko" --- lib/types/luks.nix | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/lib/types/luks.nix b/lib/types/luks.nix index b75cb9a..dd89f37 100644 --- a/lib/types/luks.nix +++ b/lib/types/luks.nix @@ -114,19 +114,23 @@ in default = '' if ! blkid "${config.device}" >/dev/null || ! (blkid "${config.device}" -o export | grep -q '^TYPE='); then ${lib.optionalString config.askPassword '' - set +x askPassword() { - echo "Enter password for ${config.device}: " - IFS= read -r -s password - echo "Enter password for ${config.device} again to be safe: " - IFS= read -r -s password_check - export password - [ "$password" = "$password_check" ] + if [ -z ''${IN_DISKO_TEST+x} ]; then + set +x + echo "Enter password for ${config.device}: " + IFS= read -r -s password + echo "Enter password for ${config.device} again to be safe: " + IFS= read -r -s password_check + export password + [ "$password" = "$password_check" ] + set -x + else + export password=disko + fi } until askPassword; do echo "Passwords did not match, please try again." done - set -x ''} cryptsetup -q luksFormat ${config.device} ${toString config.extraFormatArgs} ${keyFileArgs} ${cryptsetupOpen} --persistent @@ -147,11 +151,15 @@ in dev = '' if ! cryptsetup status ${config.name} >/dev/null 2>/dev/null; then ${lib.optionalString config.askPassword '' - set +x - echo "Enter password for ${config.device}" - IFS= read -r -s password - export password - set -x + 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