Skip to content

Commit 018734a

Browse files
fix: delay in entering pin or accepting tpm2
Fixes: SSRCSP-8004 Signed-off-by: Brian McGillion <bmg.avoin@gmail.com>
1 parent 1c7393c commit 018734a

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

modules/partitioning/deferred-disk-encryption.nix

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,40 @@ let
570570
systemctl reboot
571571
'';
572572
};
573+
574+
cryptsetupPreCheckScript = pkgs.writeShellApplication {
575+
name = "cryptsetup-pre-check";
576+
runtimeInputs = [
577+
pkgs.cryptsetup
578+
pkgs.systemd
579+
pkgs.util-linux
580+
];
581+
text = ''
582+
DEVICE="${lvmPartition}"
583+
584+
# Wait for device to appear
585+
for _ in {1..30}; do
586+
if [ -e "$DEVICE" ]; then
587+
break
588+
fi
589+
sleep 1
590+
done
591+
592+
udevadm settle || true
593+
594+
# Check if the device is LUKS — retry a few times for transient read errors
595+
for _ in {1..3}; do
596+
if cryptsetup isLuks "$DEVICE"; then
597+
mkdir -p /run
598+
touch /run/cryptsetup-pre-checked
599+
exit 0
600+
fi
601+
sleep 1
602+
done
603+
604+
# Device is not encrypted; do NOT create marker so cryptsetup is skipped
605+
'';
606+
};
573607
in
574608
{
575609
_file = ./deferred-disk-encryption.nix;
@@ -616,6 +650,7 @@ in
616650
pkgs.kmod
617651
pkgs.pcsclite.lib
618652
firstBootEncryptScript
653+
cryptsetupPreCheckScript
619654
];
620655

621656
services = {
@@ -708,6 +743,27 @@ in
708743
};
709744
};
710745

746+
# Lightweight pre-check service that runs before cryptsetup-pre.target.
747+
# Creates the /run/cryptsetup-pre-checked marker if the device is LUKS,
748+
# allowing systemd-cryptsetup@crypted to start through the normal systemd
749+
# path without first-boot-encrypt having to mediate (which causes a TTY
750+
# ownership conflict and ~2min input delay).
751+
cryptsetup-pre-check = {
752+
description = "Check if device is LUKS before cryptsetup";
753+
unitConfig.DefaultDependencies = false;
754+
before = [
755+
"cryptsetup-pre.target"
756+
"systemd-cryptsetup@crypted.service"
757+
];
758+
wantedBy = [ "cryptsetup-pre.target" ];
759+
after = [ "${utils.escapeSystemdPath lvmPartition}.device" ];
760+
serviceConfig = {
761+
Type = "oneshot";
762+
RemainAfterExit = true;
763+
ExecStart = getExe cryptsetupPreCheckScript;
764+
};
765+
};
766+
711767
};
712768
};
713769

0 commit comments

Comments
 (0)