Trigger suspend on low battery (causes bootloop)

I am trying to trigger suspend on low battery. In Arch I had roughly the following settings (confirmed to work) in /etc/udev/rules.d/99-lowbat.rules, which I added to configuration.nix:

services.udev.extraRules = ''
 RUN+="${pkgs.systemd}/bin/systemctl hibernate"

After building, switching, and disconnecting my machine from the power outlet (to trigger discharging), with the system at 80% bat, my machine went to immediate suspend. Subsequent attempts to boot would wake up the suspend image and suspend again. Attempts to select an older generation of the system would still only wake up the existing supend image and bootloop. I filed an issue here with more details.

Putting aside the bootloop, my question now is how to do this properly: to trigger suspend on low battery. Thank you for the help as always!

KDE (and presumably the other DEs) will do that for you, so is it safe to assume this is a non-GUI machine?