From 8555a7fdbfdf7d27096de9b23b650244d842780c Mon Sep 17 00:00:00 2001 From: Will Fancher Date: Thu, 14 Apr 2022 17:21:10 -0400 Subject: [PATCH] zfs: Allow three tries to decrypt datasets --- nixos/modules/tasks/filesystems/zfs.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nixos/modules/tasks/filesystems/zfs.nix b/nixos/modules/tasks/filesystems/zfs.nix index 5890fe89cf4..306bd255217 100644 --- a/nixos/modules/tasks/filesystems/zfs.nix +++ b/nixos/modules/tasks/filesystems/zfs.nix @@ -146,7 +146,14 @@ let none ) ;; prompt ) - ${systemd}/bin/systemd-ask-password "Enter key for $ds:" | ${cfgZfs.package}/sbin/zfs load-key "$ds" + tries=3 + success=false + while [[ $success != true ]] && [[ $tries -gt 0 ]]; do + ${systemd}/bin/systemd-ask-password "Enter key for $ds:" | ${cfgZfs.package}/sbin/zfs load-key "$ds" \ + && success=true \ + || tries=$((tries - 1)) + done + [[ $success = true ]] ;; * ) ${cfgZfs.package}/sbin/zfs load-key "$ds"