]> Git — Sourcephile - sourcephile-nix.git/blob - hosts/mermet/knot/sourcephile.fr.nix
nix: use an absolute path for GNUPGHOME
[sourcephile-nix.git] / hosts / mermet / knot / sourcephile.fr.nix
1 { pkgs, lib, config, inputs, hosts, info, ... }:
2 let
3 domain = "sourcephile.fr";
4 domainID = lib.replaceStrings [ "." ] [ "_" ] domain;
5 inherit (config) networking;
6 inherit (config.services) knot;
7 inherit (config.users) users groups;
8 zoneData =
9 # TODO: increase the TTL once things have settled down
10 ''
11 $ORIGIN ${domain}.
12 $TTL 500
13
14 ; SOA (Start Of Authority)
15 @ SOA ns root (
16 ${toString inputs.self.lastModified} ; Serial number
17 24h ; Refresh
18 15m ; Retry
19 1000h ; Expire (1000h)
20 1d ; Negative caching
21 )
22
23 ; NS (Name Server)
24 @ NS ns
25 @ NS ${info.gandi.dns.secondary.ns.name}.
26 i NS ns
27 whoami4 NS ns.whoami4
28 ns.whoami4 A ${hosts.mermet._module.args.ipv4}
29
30 ; A (DNS -> IPv4)
31 @ A ${hosts.mermet._module.args.ipv4}
32 mermet A ${hosts.mermet._module.args.ipv4}
33 autoconfig A ${hosts.mermet._module.args.ipv4}
34 calibre A ${hosts.mermet._module.args.ipv4}
35 doc A ${hosts.mermet._module.args.ipv4}
36 git A ${hosts.mermet._module.args.ipv4}
37 imap A ${hosts.mermet._module.args.ipv4}
38 mail A ${hosts.mermet._module.args.ipv4}
39 mails A ${hosts.mermet._module.args.ipv4}
40 news A ${hosts.mermet._module.args.ipv4}
41 public-inbox A ${hosts.mermet._module.args.ipv4}
42 ns A ${hosts.mermet._module.args.ipv4}
43 pop A ${hosts.mermet._module.args.ipv4}
44 smtp A ${hosts.mermet._module.args.ipv4}
45 submission A ${hosts.mermet._module.args.ipv4}
46 www A ${hosts.mermet._module.args.ipv4}
47 lemoutona5pattes A ${hosts.mermet._module.args.ipv4}
48 croc A ${hosts.mermet._module.args.ipv4}
49 stun A ${hosts.mermet._module.args.ipv4}
50 turn A ${hosts.mermet._module.args.ipv4}
51 whoami A ${hosts.mermet._module.args.ipv4}
52 code A ${hosts.mermet._module.args.ipv4}
53 miniflux A ${hosts.mermet._module.args.ipv4}
54
55 ; CNAME (Canonical Name)
56 openconcerto CNAME losurdo
57 xmpp CNAME mermet
58 salons CNAME mermet
59 tmp CNAME mermet
60 proxy65 CNAME mermet
61 cryptpad CNAME losurdo
62 cryptpad-api CNAME losurdo
63 cryptpad-files CNAME losurdo
64 cryptpad-sandbox CNAME losurdo
65 mumble CNAME mermet
66 freeciv CNAME losurdo
67 nix-serve CNAME losurdo
68 nix-extracache CNAME losurdo
69 nix-localcache CNAME lan.losurdo
70 sftp CNAME losurdo
71
72 ; DMARC (Domain-based Message Authentication, Reporting and Conformance)
73 _dmarc 3600 IN TXT "v=DMARC1; p=none; pct=100; rua=mailto:root+dmarc+aggregate@sourcephile.fr; ruf=mailto:root+dmarc+forensic@sourcephile.fr"
74
75 ; SPF (Sender Policy Framework)
76 @ 3600 IN TXT "v=spf1 mx ip4:${hosts.mermet._module.args.ipv4} -all"
77
78 ; SRV (SeRVice)
79 _git._tcp.git 18000 IN SRV 0 0 9418 git
80 _stun._udp 18000 IN SRV 0 5 3478 stun
81 _xmpp-client._tcp 18000 IN SRV 0 5 5222 xmpp
82 _xmpp-server._tcp 18000 IN SRV 0 5 5269 xmpp
83 _xmpp-server._tcp.salons 18000 IN SRV 0 5 5269 xmpp
84 _xmpps-client._tcp 18000 IN SRV 0 5 5223 xmpp
85 _xmpps-server._tcp 18000 IN SRV 0 5 5270 xmpp
86 _xmpps-server._tcp.salons 18000 IN SRV 0 5 5270 xmpp
87
88 ; CAA (Certificate Authority Authorization)
89 ; DOC: https://blog.qualys.com/ssllabs/2017/03/13/caa-mandated-by-cabrowser-forum
90 @ CAA 128 issue "letsencrypt.org; validationmethods=dns-01; accounturi=https://acme-v02.api.letsencrypt.org/acme/acct/78014180"
91 '';
92 in
93 {
94 services.knot.settingsFreeform = {
95 remote.ns_iodine.address = "127.0.0.1@1053";
96 acl."acl_localhost_acme_${domainID}" = {
97 address = "127.0.0.1";
98 action = "update";
99 update-owner = "name";
100 update-owner-match = "equal";
101 update-owner-name = [ "_acme-challenge" ];
102 update-type = [ "TXT" ];
103 };
104 acl."acl_tsig_acme_${domainID}" = {
105 key = "acme_${domainID}";
106 action = "update";
107 update-owner = "name";
108 update-owner-match = "equal";
109 update-owner-name = [ "_acme-challenge" ];
110 update-type = [ "TXT" ];
111 };
112 acl."acl_tsig_losurdo_${domainID}" = {
113 key = "losurdo_${domainID}";
114 action = "update";
115 update-owner = "name";
116 update-owner-match = "equal";
117 update-owner-name = [ "losurdo" "lan.losurdo" ];
118 update-type = [ "A" "AAAA" ];
119 };
120 mod-dnsproxy.proxy_iodine = {
121 remote = "ns_iodine";
122 fallback = "off";
123 };
124 zone."${domain}" = {
125 file = "${domain}.zone";
126 serial-policy = "increment";
127 semantic-checks = true;
128 notify = [
129 "secondary_gandi"
130 ];
131 acl = [
132 "acl_gandi"
133 "acl_localhost_acme_${domainID}"
134 "acl_tsig_acme_${domainID}"
135 "acl_tsig_losurdo_${domainID}"
136 ];
137 dnssec-signing = true;
138 dnssec-policy = "rsa";
139 };
140 #zone."i.${domain}" = {
141 # module = "mod-dnsproxy/proxy_iodine";
142 #};
143 zone."whoami4.${domain}" = {
144 module = "mod-whoami";
145 file = pkgs.writeText "whoami4.zone" ''
146 $TTL 1
147 @ SOA ns root.${domain}. (
148 0 ; SERIAL
149 86400 ; REFRESH
150 86400 ; RETRY
151 86400 ; EXPIRE
152 1 ; MINIMUM
153 )
154 $TTL 86400
155 @ NS ns
156 ns A ${hosts.mermet._module.args.ipv4}
157 '';
158 };
159 };
160 services.knot = {
161 keyFiles = [
162 "/run/credentials/knot.service/${domain}.acme.conf"
163 # Generated with: keymgr -t losurdo_${domainID}
164 "/run/credentials/knot.service/losurdo.conf"
165 ];
166 };
167 systemd.services.knot = {
168 serviceConfig = {
169 ExecStartPre = [
170 ''
171 +${pkgs.coreutils}/bin/install -D -o ${users.knot.name} -g ${groups."knot".name} -m 700 \
172 ${pkgs.writeText "${domain}.zone" zoneData} \
173 /var/lib/knot/zones/${domain}.zone
174 ''
175 ];
176 LoadCredentialEncrypted = [
177 "${domain}.acme.conf:${./. + "/${domain}/acme.conf.cred"}"
178 "losurdo.conf:${./. + "/${domain}/losurdo.conf.cred"}"
179 ];
180 };
181 };
182 networking.nftables.ruleset = ''
183 table inet filter {
184 set output-net-knot-ipv4 { type ipv4_addr; elements = { ${info.gandi.dns.secondary.axfr.ipv4} }; }
185 set output-net-knot-ipv6 { type ipv6_addr; elements = { ${info.gandi.dns.secondary.axfr.ipv6} }; }
186 }
187 '';
188 /* Useless since the zone is public
189 services.unbound.settings = {
190 stub-zone = {
191 name = domain;
192 stub-addr = "127.0.0.1@5353";
193 };
194 };
195 '';
196 */
197 }