Update configuration.nix

This commit is contained in:
ska
2025-12-22 16:12:00 +00:00
parent 7762d471db
commit b0ff40cf13

View File

@@ -218,6 +218,9 @@
serviceConfig = {
Type = "simple";
Restart = "always";
RestartSec = "1";
ExecStart = pkgs.writeShellScript "watch-root-device" ''
set -e
@@ -227,10 +230,14 @@
SLEEP=${pkgs.coreutils}/bin/sleep
SYSTEMCTL=${pkgs.systemd}/bin/systemctl
ROOT_SRC="$($FINDMNT -n -o SOURCE / || true)"
[ -z "$ROOT_SRC" ] && exit 0
# Wait until root is visible
while true; do
ROOT_SRC="$($FINDMNT -n -o SOURCE / 2>/dev/null || true)"
[ -n "$ROOT_SRC" ] && break
$SLEEP 1
done
# Resolve to top-level disk exactly once
# Resolve to top-level block device
PARENT="$($LSBLK -ndo PKNAME "$ROOT_SRC" 2>/dev/null || true)"
if [ -n "$PARENT" ]; then
ROOT_DEV="/dev/$PARENT"
@@ -240,16 +247,18 @@
DEV_NAME="$($BASENAME "$ROOT_DEV")"
# Sanity check: ensure device exists before watching
[ ! -e "/sys/class/block/$DEV_NAME" ] && exit 0
while [ -e "/sys/class/block/$DEV_NAME" ]; do
# Wait until sysfs entry exists
while [ ! -e "/sys/class/block/$DEV_NAME" ]; do
$SLEEP 1
done
# Watch until device disappears
while [ -e "/sys/class/block/$DEV_NAME" ]; do
$SLEEP 0.5
done
$SYSTEMCTL poweroff
'';
Restart = "no";
};
};