]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/websites/tools/mail/mta-sts.nix
Fix Backup mailboxes expunging
[perso/Immae/Config/Nix.git] / modules / private / websites / tools / mail / mta-sts.nix
CommitLineData
ab8f306d 1{ lib, pkgs, config, ... }:
afcc5de0
IB
2let
3 domains = (lib.remove null (lib.flatten (map
4 (zone: map
5 (e: if e.receive
6 then {
7 domain = "${e.domain}${lib.optionalString (e.domain != "") "."}${zone.name}";
8 mail = zone.name;
9 }
10 else null
11 )
12 (zone.withEmail or [])
13 )
ab8f306d 14 config.myEnv.dns.masterZones
afcc5de0 15 )));
619e4f46
IB
16 mxes = lib.mapAttrsToList
17 (n: v: v.mx.subdomain)
18 (lib.attrsets.filterAttrs (n: v: v.mx.enable) config.myEnv.servers);
afcc5de0
IB
19 # FIXME: increase the id number in modules/private/dns.nix when this
20 # file change (date -u +'%Y%m%d%H%M%S'Z)
21 file = domain: pkgs.writeText "mta-sts-${domain.domain}.txt" ''
22 version: STSv1
23 mode: testing
619e4f46 24 ${builtins.concatStringsSep "\n" (map (v: "mx: ${v}.${domain.mail}") mxes)}
afcc5de0
IB
25 max_age: 604800
26 '';
27 root = pkgs.runCommand "mta-sts_root" {} ''
28 mkdir -p $out
29 ${builtins.concatStringsSep "\n" (map (d:
30 "cp ${file d} $out/${d.domain}.txt"
31 ) domains)}
32 '';
8415083e 33 cfg = config.myServices.websites.tools.email;
afcc5de0
IB
34in
35{
8415083e
IB
36 config = lib.mkIf cfg.enable {
37 myServices.websites.webappDirs = {
38 _mta-sts = root;
39 };
afcc5de0 40
8415083e
IB
41 services.websites.env.tools.vhostConfs.mta_sts = {
42 certName = "mail";
43 addToCerts = true;
44 hosts = ["mta-sts.mail.immae.eu"] ++ map (v: "mta-sts.${v.domain}") domains;
45 root = "/run/current-system/webapps/_mta-sts";
46 extraConfig = [
47 ''
48 RewriteEngine on
49 RewriteCond %{HTTP_HOST} ^mta-sts.(.*)$
50 RewriteRule ^/.well-known/mta-sts.txt$ %{DOCUMENT_ROOT}/%1.txt [L]
51 <Directory /run/current-system/webapps/_mta-sts>
52 Require all granted
53 Options -Indexes
54 </Directory>
55 ''
56 ];
57 };
afcc5de0 58 };
afcc5de0 59}