aboutsummaryrefslogtreecommitdiff
path: root/modules/acme.nix
blob: 23c995fede04136124003eeaab35c8e08f7f3c98 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{ ... }:

# Shared ACME (Let's Encrypt) infrastructure for services that need their own
# certificate rather than being fronted by Caddy - currently just AdGuard
# Home's DNS-over-HTTPS/DNS-over-TLS listener (modules/adguard.nix), which
# terminates TLS itself on its own ports rather than through Caddy.
#
# Challenge type: HTTP-01 via a shared webroot that Caddy serves on port 80
# for dns.karanj.com (see modules/caddy.nix) - no DNS provider API
# credentials needed. This is a separate Let's Encrypt certificate from the
# one Caddy obtains for its own reverse-proxied HTTPS on the same domain;
# issuing two independent certs for one domain is fine and well within
# Let's Encrypt's rate limits.
{
  security.acme = {
    acceptTerms = true;
    defaults.email = "me@karanj.com";

    certs."dns.karanj.com" = {
      webroot = "/var/lib/acme/acme-challenge";
      # Owns the issued cert/key files by the adguardhome group so the
      # service can read them without running as root.
      group = "adguardhome";
      # Restart (not just reload) so AdGuard re-reads the cert on renewal.
      reloadServices = [ "adguardhome.service" ];
    };
  };

  # Make sure Caddy (which serves the HTTP-01 webroot) is already up before
  # the first issuance attempt.
  systemd.services."acme-dns.karanj.com".after = [ "caddy.service" ];
}