From 97187bbbfbdc74bcfa71d6a97f0dd2b875a32199 Mon Sep 17 00:00:00 2001 From: ska Date: Mon, 22 Dec 2025 15:48:14 +0000 Subject: [PATCH] Update configuration.nix --- configuration.nix | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/configuration.nix b/configuration.nix index 881b01b..92bdda7 100644 --- a/configuration.nix +++ b/configuration.nix @@ -135,13 +135,13 @@ ############################################################ systemd.services.shutdown-on-root-usb-loss = { - description = "Shutdown if USB device backing / disappears"; + description = "Shutdown if device backing / disappears"; wantedBy = [ "multi-user.target" ]; after = [ "local-fs.target" ]; serviceConfig = { Type = "simple"; - ExecStart = pkgs.writeShellScript "watch-root-usb" '' + ExecStart = pkgs.writeShellScript "watch-root-device" '' set -e FINDMNT=${pkgs.util-linux}/bin/findmnt @@ -150,23 +150,21 @@ SLEEP=${pkgs.coreutils}/bin/sleep SYSTEMCTL=${pkgs.systemd}/bin/systemctl + # Resolve root source ROOT_SRC="$($FINDMNT -n -o SOURCE / || true)" [ -z "$ROOT_SRC" ] && exit 0 - if [[ "$ROOT_SRC" == /dev/dm-* ]]; then - PARENT="$($LSBLK -no PKNAME "$ROOT_SRC")" - ROOT_DEV="/dev/$PARENT" - else - ROOT_DEV="$ROOT_SRC" - fi + # Walk up to the top-level block device + DEV="$ROOT_SRC" + while PARENT="$($LSBLK -no PKNAME "$DEV" 2>/dev/null)"; [ -n "$PARENT" ]; do + DEV="/dev/$PARENT" + done - TRAN="$($LSBLK -no TRAN "$ROOT_DEV" || true)" - [ "$TRAN" != "usb" ] && exec $SLEEP infinity - - DEV_NAME="$($BASENAME "$ROOT_DEV")" + DEV_NAME="$($BASENAME "$DEV")" + # Watch until the block device disappears while [ -e "/sys/class/block/$DEV_NAME" ]; do - $SLEEP 1 + $SLEEP 0.5 done $SYSTEMCTL poweroff