Systemd wait for timesync?

I’ve got a raspberry pi flake which runs a systemd service which needs correct time before starting. Adding after = [ "time-sync.target" ]; isn’t sufficient to wait until time is actually synchronized, as that just waits until the time sync starts. This blog post mentions that the best solution is to enable systemd-time-wait-sync.service in order to make time-sync.target block until the clock is actually synchronized, but systemd-time-wait-sync.service doesn’t seem to be used in nixpkgs.

This has led me to RFC: Accurate time synchronization dependencies via time-sync.target - #2 by Mic92 with the latest comment that states this functionality is not implemented and the PR appears to be not merged (nixos: make time-sync.target block until initial adjustment with all NTP daemons by thoughtpolice · Pull Request #51338 · NixOS/nixpkgs · GitHub)

What’s the easiest path forward for me to enable "systemd-time-wait-sync.service" to my configuration?

This nixos configuration might work:

{
  systemd.additionalUpstreamSystemUnits = [ "systemd-time-wait-sync.service" ];
}
2 Likes

Thanks! Got it working after also needing to do systemd.services.systemd-time-wait-sync.wantedBy = [ "multi-user.target" ];