Update configuration.nix
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user