I did that once, and it did exactly what I needed, but it invalidated the binary cache and I couldn’t afford rebuilding the world all the time back in the days.
Can’t you just write a systemd unit and hook it up with systemd.services.<name>.wantedBy = "systemd-suspend.target"; or something?
Thanks, that’s a good suggestion, and one that I didn’t give enough thought to, it is however not entirely entirely straightforward as there is no wakeup.target.
The next question is how to abort sleep (for example if an rmmod is unsuccesful – else my laptop won’t wake from sleep). I think the exit code from scripts in lib/systemd/system-sleep is able to do this… otherwise I’m not sure, perhaps I’d need to look at systemd-inhibit.
Ultimately though, the idea of placing “local use only” scripts in /usr/lib/systemd/system-sleep is a bit daft, and is perhaps more problematic on NixOS then elsewhere.
We could patch systemd.pc.in? If you trace it through, the only place that systemdsleepdir is used is here. Patching systemd.pc.in is not without precedent as NixOS/systemd has a patched systemd.pc.in for similar reasons.
We could then add suitable options to the systemd module to allow setting your own sleep scripts.