all repos — nixfiles @ 42b51878c262425ed425d6522ad5c658fd75b24d

System and user configuration, managed by nix and home-manager

system/roles/local-ca.nix (view raw)

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{
  config,
  ...
}:
let
  inherit (config.networking) hostName domain;
in
{
  services.caddy = {
    enable = true;
    globalConfig = ''
      pki {
        ca home {
          name "Home CA"
        }
      }
    '';
    virtualHosts = {
      "${hostName}.${domain}" = {
        extraConfig = ''
          tls {
            issuer internal {
              ca home
            }
          }
        '';
      };
      "ca.${domain}" = {
        # cd /var/lib/caddy && install -D -m 444 .local/share/caddy/pki/authorities/home/root.crt ca/root.crt
        serverAliases = [ "http://ca.${domain}" ];
        extraConfig = ''
          tls {
            issuer internal {
              ca home
            }
          }
          acme_server {
            allow {
              domains *.test *.${domain}
            }
          }
          root /var/lib/caddy/ca
          file_server browse
        '';
      };
    };
  };

  services.dnsmasq.settings.cname = [
    "ca.${domain},${hostName}.${domain}"
  ];
}