How to prevent timer from triggering on deployment

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:

  1. 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;
};
  1. Let the timer pass once, triggering the service (important!)
  2. Change the timer definition e.g. add Persistent = true

systemd.timers."timer-test" = {
  wantedBy = [ "timers.target" ];
  timerConfig = {
    OnCalendar = "*-*-* *:14:00";
    Persistent = true;
  };
};
  1. 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

Might the key change here be the Persistent = true in that when you reconfigure the timer, systemd can’t tell if it was run last time, and by design runs the service, just in case it had not been run?

Does this also happen if you rebuild and have not changed the service definition?

It also happens without Persistent = true I’m afraid