Trigger oneshot systemd service after certain service start

Hello everyone,

I’m trying to configure manually written systemd service to start after the opendkim.service starts. In systemd service syntax, there’s After directive for such purposes, so I configured my systemd service the following way:

systemd.services = {
    "init-dkim" = {
      serviceConfig = {
        Type = "oneshot";
        After = "opendkim.service";
        ExecStart = "${pkgs.strip-dkim}/bin/strip-dkim";
      };

But it seems that there’s no After option in the systemd NixOS module.

Could you please advise, how to configure my service to start after opendkim.service?

Thanks.

systemd.services = {
  "init-dkim" = {
     wantedBy = [ "opendkim.service" ];
     after = [ "opendkim.service" ];
     serviceConfig = {
       ExecStart = "${pkgs.strip-dkim}/bin/strip-dkim";
     };
  };
}

If strip-dkim finishes very quickly, you could also do

systemd.services.opendkim.postStart = ''
  ${pkgs.strip-dkim}/bin/strip-dkim
'';

In this case the opendkim service will be marked as running only when strip-dkim has finished successfully.

1 Like