Update configuration.nix
This commit is contained in:
@@ -218,6 +218,9 @@
|
|||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "simple";
|
Type = "simple";
|
||||||
|
Restart = "always";
|
||||||
|
RestartSec = "1";
|
||||||
|
|
||||||
ExecStart = pkgs.writeShellScript "watch-root-device" ''
|
ExecStart = pkgs.writeShellScript "watch-root-device" ''
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
@@ -227,10 +230,14 @@
|
|||||||
SLEEP=${pkgs.coreutils}/bin/sleep
|
SLEEP=${pkgs.coreutils}/bin/sleep
|
||||||
SYSTEMCTL=${pkgs.systemd}/bin/systemctl
|
SYSTEMCTL=${pkgs.systemd}/bin/systemctl
|
||||||
|
|
||||||
ROOT_SRC="$($FINDMNT -n -o SOURCE / || true)"
|
# Wait until root is visible
|
||||||
[ -z "$ROOT_SRC" ] && exit 0
|
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)"
|
PARENT="$($LSBLK -ndo PKNAME "$ROOT_SRC" 2>/dev/null || true)"
|
||||||
if [ -n "$PARENT" ]; then
|
if [ -n "$PARENT" ]; then
|
||||||
ROOT_DEV="/dev/$PARENT"
|
ROOT_DEV="/dev/$PARENT"
|
||||||
@@ -240,16 +247,18 @@
|
|||||||
|
|
||||||
DEV_NAME="$($BASENAME "$ROOT_DEV")"
|
DEV_NAME="$($BASENAME "$ROOT_DEV")"
|
||||||
|
|
||||||
# Sanity check: ensure device exists before watching
|
# Wait until sysfs entry exists
|
||||||
[ ! -e "/sys/class/block/$DEV_NAME" ] && exit 0
|
while [ ! -e "/sys/class/block/$DEV_NAME" ]; do
|
||||||
|
|
||||||
while [ -e "/sys/class/block/$DEV_NAME" ]; do
|
|
||||||
$SLEEP 1
|
$SLEEP 1
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Watch until device disappears
|
||||||
|
while [ -e "/sys/class/block/$DEV_NAME" ]; do
|
||||||
|
$SLEEP 0.5
|
||||||
|
done
|
||||||
|
|
||||||
$SYSTEMCTL poweroff
|
$SYSTEMCTL poweroff
|
||||||
'';
|
'';
|
||||||
Restart = "no";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user