How to prevent custom systemd service from restarting on nixos-rebuild switch?

There’s an option specifically for this: systemd.services.<name>.restartIfChanged which can be set to false if you want to prevent it being automatically restarted.

EDIT: Oh, but for oneshot services, this won’t help. It won’t need to be restarted because it’s not even running. So nixos will just start it. You can avoid this by also setting serviceConfig.RemainAfterExit = true;

1 Like