]> Git — Sourcephile - sourcephile-nix.git/blob - servers/mermet/knot/sourcephile.fr.nix
nginx: use Let's Encrypt X.509 certificate
[sourcephile-nix.git] / servers / mermet / knot / sourcephile.fr.nix
1 { pkgs, lib, config, ... }:
2 let
3 inherit (builtins.extraBuiltins) pass git;
4 inherit (pkgs.lib) unlinesAttrs types;
5 inherit (config) networking;
6 inherit (config.services) knot;
7 inherit (config) users;
8 # Use the Git commit time of the ${domain}.nix file to set the serial number.
9 # WARNING: the ${domain}.nix must be committed into Git for this to work.
10 # WARNING: this does not take other .nix into account, though they may contribute to the zone's data.
11 serial = domain: toString (git ./. [ "log" "-1" "--format=%ct" "--" (domain + ".nix") ]);
12 mermetIPv4 = "80.67.180.129";
13 domain = "sourcephile.fr";
14 in
15 {
16 security.acme.certs."${domain}" = {
17 email = "root@${domain}";
18 extraDomains = {
19 "*.${domain}" = null;
20 };
21 group = users.groups.acme.name;
22 allowKeysForGroup = true;
23 keyType = "rsa4096";
24 dnsProvider = "rfc2136";
25 credentialsFile = pkgs.writeText "credentials" ''
26 RFC2136_NAMESERVER=127.0.0.1:5353
27 LEGO_EXPERIMENTAL_CNAME_SUPPORT=1
28 '';
29 };
30 services.knot.zones."${domain}" = {
31 conf = ''
32 zone:
33 - domain: ${domain}
34 file: ${domain}.zone
35 serial-policy: increment
36 semantic-checks: on
37 notify: secondary_gandi
38 acl: acl_gandi
39 acl: acl_lego
40 acl: acl_localhost
41 dnssec-signing: on
42 dnssec-policy: rsa
43 '';
44 # TODO: increase the TTL once things have settled down
45 data = ''
46 $ORIGIN ${domain}.
47 $TTL 500
48
49 ; SOA (Start Of Authority)
50 @ SOA ns admin (
51 ${serial domain} ; Serial number
52 24h ; Refresh
53 15m ; Retry
54 1000h ; Expire (1000h)
55 1d ; Negative caching
56 )
57
58 ; NS (Name Server)
59 @ NS ns
60 @ NS ns6.gandi.net.
61
62 ; A (DNS -> IPv4)
63 @ A ${mermetIPv4}
64 mermet A ${mermetIPv4}
65 autoconfig A ${mermetIPv4}
66 code A ${mermetIPv4}
67 git A ${mermetIPv4}
68 imap A ${mermetIPv4}
69 mail A ${mermetIPv4}
70 ns A ${mermetIPv4}
71 pop A ${mermetIPv4}
72 smtp A ${mermetIPv4}
73 submission A ${mermetIPv4}
74 www A ${mermetIPv4}
75
76 ; SPF (Sender Policy Framework)
77 @ 3600 IN SPF "v=spf1 mx ip4:${mermetIPv4} -all"
78 @ 3600 IN TXT "v=spf1 mx ip4:${mermetIPv4} -all"
79
80 ; MX (Mail eXchange)
81 @ 180 MX 5 mail
82
83 ; SRV (SeRVice)
84 _git._tcp.git 18000 IN SRV 0 0 9418 git
85
86 ; CAA (Certificate Authority Authorization)
87 ; DOC: https://blog.qualys.com/ssllabs/2017/03/13/caa-mandated-by-cabrowser-forum
88 @ CAA 128 issue "letsencrypt.org"
89 '';
90 };
91 }