Update configuration.nix
This commit is contained in:
@@ -217,27 +217,14 @@
|
|||||||
# USB ROOT DEVICE MONITOR (SHUTDOWN ON DISCONNECT)
|
# USB ROOT DEVICE MONITOR (SHUTDOWN ON DISCONNECT)
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
systemd.services.usb-root-monitor = {
|
# Monitor root device removal and shut down
|
||||||
description = "Monitor USB LUKS container and shut down if removed";
|
services.udev.extraRules = ''
|
||||||
script = ''
|
# Match the root filesystem device by label (or use PARTLABEL/UUID if preferred)
|
||||||
LUksDevice="/dev/disk/by-partlabel/nixos-crypt"
|
KERNEL=="sd*", ENV{ID_FS_LABEL}=="nixos-root", SYMLINK+="nixos-root-device"
|
||||||
while true; do
|
|
||||||
if ! test -e "$LUksDevice"; then
|
# Trigger when the root device is removed
|
||||||
/run/current-system/sw/bin/logger -t usb-root-monitor "LUKS container missing – shutting down immediately"
|
ACTION=="remove", KERNEL=="sd*", ENV{ID_FS_LABEL}=="nixos-root", RUN+="/run/current-system/sw/bin/systemctl poweroff"
|
||||||
/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" ];
|
|
||||||
};
|
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# NIXOS VERSION
|
# NIXOS VERSION
|
||||||
|
|||||||
Reference in New Issue
Block a user