summary refs log tree commit diff stats
path: root/system/services/acme/default.nix
blob: 0a0c4ce87bbcf0b0afa5a26431fd23bd9a09c739 (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
33
34
35
36
37
38
{lib, ...}: let
  domains = import ./domains.nix {};

  virtualHosts = builtins.listToAttrs (
    builtins.map (domain_name: {
      name = "acmechallenge.${domain_name}";
      value = {
        serverAliases = ["*.${domain_name}"];
        locations."/.well-known/acme-challenge" = {
          root = "/var/lib/acme/.challenges";
        };
        locations."/" = {
          return = "301 https://$host$request_uri";
        };
      };
    })
    domains
  );
  certs = lib.attrsets.genAttrs domains (
    domain_name: {
      webroot = "/var/lib/acme/.challenges";
      group = "nginx";
    }
  );
in {
  users.users.nginx.extraGroups = ["acme"];

  services.nginx = {
    enable = true;
    inherit virtualHosts;
  };

  security.acme = {
    acceptTerms = true;
    defaults.email = "admin@vhack.eu";
    inherit certs;
  };
}