I’m not sure whether this is a NixOS or a systemd problem, but I’m running into an issue where a systemd timer gets accidentally triggered when I do a nixos-rebuild. To reproduce it, do the following:
- Set up a timer in nixos config, deploy it
systemd.timers."timer-test" = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "*-*-* *:14:00";
};
};
systemd.services."timer-test" = {
serviceConfig.Type = "oneshot";
unitConfig."X-OnlyManualStart" = true;
};
- Let the timer pass once, triggering the service (important!)
- Change the timer definition e.g. add Persistent = true
systemd.timers."timer-test" = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "*-*-* *:14:00";
Persistent = true;
};
};
- Rebuild to config. In the logs you’ll now see ‘restarting the following units: timer-test.timer’, but somehow the service also gets started
I can also see this happen if I just do systemctl restart timer-test.timer
. This seems like a systemd issue? Anyone else have seen something like this?
Filed a bug with systemd here: Restarting timer triggers service start off-schedule · Issue #31231 · systemd/systemd · GitHub