From e18021d3554e6aac4b0eb568bc24aaf3552d8f5b Mon Sep 17 00:00:00 2001 From: ska Date: Mon, 22 Dec 2025 15:20:03 +0000 Subject: [PATCH] Update configuration.nix --- configuration.nix | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/configuration.nix b/configuration.nix index 10938ad..c655839 100644 --- a/configuration.nix +++ b/configuration.nix @@ -217,27 +217,14 @@ # USB ROOT DEVICE MONITOR (SHUTDOWN ON DISCONNECT) ############################################################ - systemd.services.usb-root-monitor = { - description = "Monitor USB LUKS container and shut down if removed"; - script = '' - LUksDevice="/dev/disk/by-partlabel/nixos-crypt" - while true; do - if ! test -e "$LUksDevice"; then - /run/current-system/sw/bin/logger -t usb-root-monitor "LUKS container missing – shutting down immediately" - /run/current-system/sw/bin/systemctl --force poweroff - exit 0 - fi - sleep 3 - done - ''; - serviceConfig = { - Type = "simple"; - Restart = "always"; - RestartSec = 5; - User = "root"; - }; - wantedBy = [ "multi-user.target" ]; - }; + # Monitor root device removal and shut down + services.udev.extraRules = '' + # Match the root filesystem device by label (or use PARTLABEL/UUID if preferred) + KERNEL=="sd*", ENV{ID_FS_LABEL}=="nixos-root", SYMLINK+="nixos-root-device" + + # Trigger when the root device is removed + ACTION=="remove", KERNEL=="sd*", ENV{ID_FS_LABEL}=="nixos-root", RUN+="/run/current-system/sw/bin/systemctl poweroff" + ''; ############################################################ # NIXOS VERSION