Trigger oneshot systemd service after certain service start

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