Update configuration.nix

This commit is contained in:
ska
2025-12-22 16:17:27 +00:00
parent b0ff40cf13
commit 41661ebd81

View File

@@ -207,70 +207,6 @@
}; };
}; };
############################################################
# USB ROOT LOSS → SHUTDOWN (CORRECTED)
############################################################
systemd.services.shutdown-on-root-usb-loss = {
description = "Shutdown if device backing / disappears";
wantedBy = [ "multi-user.target" ];
after = [ "local-fs.target" ];
serviceConfig = {
Type = "simple";
Restart = "always";
RestartSec = "1";
ExecStart = pkgs.writeShellScript "watch-root-device" ''
set -e
FINDMNT=${pkgs.util-linux}/bin/findmnt
LSBLK=${pkgs.util-linux}/bin/lsblk
BASENAME=${pkgs.coreutils}/bin/basename
SLEEP=${pkgs.coreutils}/bin/sleep
SYSTEMCTL=${pkgs.systemd}/bin/systemctl
# 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 block device
PARENT="$($LSBLK -ndo PKNAME "$ROOT_SRC" 2>/dev/null || true)"
if [ -n "$PARENT" ]; then
ROOT_DEV="/dev/$PARENT"
else
ROOT_DEV="$ROOT_SRC"
fi
DEV_NAME="$($BASENAME "$ROOT_DEV")"
# 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
'';
};
};
############################################################
# KERNEL FAILSAFE
############################################################
boot.kernel.sysctl = {
"kernel.panic" = 5;
"kernel.panic_on_oops" = 1;
};
############################################################ ############################################################
# USB OPTIMIZATIONS # USB OPTIMIZATIONS
############################################################ ############################################################