From b0ff40cf138063825582f218aab00a34b42ec037 Mon Sep 17 00:00:00 2001 From: ska Date: Mon, 22 Dec 2025 16:12:00 +0000 Subject: [PATCH] Update configuration.nix --- configuration.nix | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/configuration.nix b/configuration.nix index c4dc575..3587307 100644 --- a/configuration.nix +++ b/configuration.nix @@ -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"; }; };