Skip to content

Commit

Permalink
nixos/acme: add option to delay renewal untill after other units
Browse files Browse the repository at this point in the history
- allow adding additional units to the `after` section
- add documentation for delaying renewal untill after timesync is done
  • Loading branch information
icewind1991 committed Apr 9, 2024
1 parent 1dd3793 commit c95e1ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
16 changes: 16 additions & 0 deletions nixos/modules/security/acme/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,19 @@ systemd-tmpfiles --create
# Note: Do this for all certs that share the same account email address
systemctl start acme-example.com.service
```


## Delay renewing certificates until time synchronization is finished {#module-security-acme-timesync}

If your machine doesn't have a correct date set at boot, the certificate renewal
might fail.
You can fix this issue by configuring the acme services to wait until systemd-timesyncd
finishes synchronizing the time.

```
# install and enable systemd-time-wait-sync.service
systemd.additionalUpstreamSystemUnits = ["systemd-time-wait-sync.service"];
systemd.services.systemd-time-wait-sync.wantedBy = ["multi-user.target"];
# configure the acme services to wait for systemd-time-wait-sync.service
security.acme.defaults.after = ["time-sync.target"]
```
10 changes: 9 additions & 1 deletion nixos/modules/security/acme/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ let

renewService = lockfileName: {
description = "Renew ACME certificate for ${cert}";
after = [ "network.target" "network-online.target" "acme-fixperms.service" "nss-lookup.target" ] ++ selfsignedDeps ++ optional (cfg.maxConcurrentRenewals > 0) "acme-lockfiles.service";
after = [ "network.target" "network-online.target" "acme-fixperms.service" "nss-lookup.target" ] ++ selfsignedDeps ++ data.after ++ optional (cfg.maxConcurrentRenewals > 0) "acme-lockfiles.service";
wants = [ "network-online.target" "acme-fixperms.service" ] ++ selfsignedDeps ++ optional (cfg.maxConcurrentRenewals > 0) "acme-lockfiles.service";

# https://github.com/NixOS/nixpkgs/pull/81371#issuecomment-605526099
Expand Down Expand Up @@ -572,6 +572,14 @@ let
description = lib.mdDoc "Group running the ACME client.";
};

after = mkOption {
type = types.listOf types.str;
inherit (defaultAndText "after" []) default defaultText;
description = lib.mdDoc ''
List of systemd units to wait for before starting certificate renewal.
'';
};

reloadServices = mkOption {
type = types.listOf types.str;
inherit (defaultAndText "reloadServices" []) default defaultText;
Expand Down

0 comments on commit c95e1ee

Please sign in to comment.