From cbc1f418d0cd79bf84aae3490ba8bb6222d8e81d Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Sun, 13 Apr 2025 10:59:04 +0200 Subject: [PATCH] Improve luks device detection --- lib/types/luks.nix | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/types/luks.nix b/lib/types/luks.nix index 409f62a..b3a3590 100644 --- a/lib/types/luks.nix +++ b/lib/types/luks.nix @@ -130,7 +130,7 @@ in _create = diskoLib.mkCreateOption { inherit config options; default = '' - if ! blkid "${config.device}" >/dev/null || ! (blkid "${config.device}" -o export | grep -q '^TYPE='); then + if ! blkid "${config.device}" >/dev/null || ! (cryptsetup isLuks "${config.device}"); then ${lib.optionalString config.askPassword '' promptSecret() { prompt=$1 @@ -158,13 +158,15 @@ in done ''} cryptsetup -q luksFormat "${config.device}" ${toString config.extraFormatArgs} ${keyFileArgs} - ${cryptsetupOpen} --persistent - ${toString ( - lib.forEach config.additionalKeyFiles (keyFile: '' - cryptsetup luksAddKey "${config.device}" ${keyFile} ${keyFileArgs} - '') - )} fi + + ${cryptsetupOpen} --persistent + ${toString ( + lib.forEach config.additionalKeyFiles (keyFile: '' + cryptsetup luksAddKey "${config.device}" ${keyFile} ${keyFileArgs} + '') + )} + ${lib.optionalString (config.content != null) config.content._create} ''; };