main
nix 169 lines 4.59 KB
Raw
1 {
2 inputs,
3 config,
4 lib,
5 pkgs,
6 ...
7 }:
8
9 {
10 imports = [
11 inputs.simple-nixos-mailserver.nixosModule
12 ./mailing-lists.nix
13 ./freescout.nix
14 ];
15
16 # enabled through systemd.network.enable
17 services.resolved.enable = false;
18
19 services.nginx = {
20 enable = true;
21 virtualHosts.${config.mailserver.fqdn} = {
22 enableACME = true;
23 forceSSL = true;
24 locations."/".return = "204";
25 };
26 };
27
28 mailserver = {
29 enable = true;
30 enableImap = false;
31 stateVersion = 3;
32
33 fqdn = config.networking.fqdn;
34
35 x509.useACMEHost = config.mailserver.fqdn;
36
37 domains = [
38 "nixcon.org"
39 "nixos.org"
40 ];
41
42 dkim.domains =
43 let
44 selectors = {
45 "mail" = {
46 # legacy managed key
47 };
48 "r202605" = {
49 keyType = "rsa";
50 keyLength = 2048;
51 };
52 "e202605" = {
53 keyType = "ed25519";
54 keyLength = null;
55 };
56 };
57 in
58 lib.genAttrs config.mailserver.domains (_: {
59 inherit selectors;
60 });
61
62 srs.enable = true;
63 };
64
65 # https://nixos-mailserver.readthedocs.io/en/latest/backup-guide.html
66 services.backup.includes = [ config.mailserver.storage.path ];
67
68 sops.secrets."nixos.org.mail.key" = {
69 format = "binary";
70 owner = "rspamd";
71 group = "rspamd";
72 mode = "0600";
73
74 # How to generate:
75 #
76 # ```console
77 # cd non-critical-infra
78 # DOMAIN=nixos.org
79 # SELECTOR=mail
80 # PRIVATE_KEY_PATH=secrets/$DOMAIN.$SELECTOR.key.umbriel
81 # nix shell nixpkgs#opendkim --command opendkim-genkey --selector="$SELECTOR" --domain="$DOMAIN" --bits=1024
82 # mv mail.private "$PRIVATE_KEY_PATH"
83 # sops encrypt --in-place "$PRIVATE_KEY_PATH"
84 # ```
85 #
86 # Next, look at `mail.txt` and update DNS accordingly.
87 sopsFile = ../../secrets/nixos.org.mail.key.umbriel;
88
89 # Ensure the file gets symlinked to where Simple NixOS Mailserver expects
90 # to find it.
91 path = "${config.mailserver.dkim.keyDirectory}/nixos.org.mail.key";
92 };
93
94 sops.secrets."nixcon.org.mail.key" = {
95 format = "binary";
96 owner = "rspamd";
97 group = "rspamd";
98 mode = "0600";
99 sopsFile = ../../secrets/nixcon.org.mail.key.umbriel;
100 path = "${config.mailserver.dkim.keyDirectory}/nixcon.org.mail.key";
101 };
102
103 services.postfix.settings.main.bounce_template_file = "${pkgs.writeText "bounce-template.cf" ''
104 failure_template = <<EOF
105 Charset: us-ascii
106 From: MAILER-DAEMON (Mail Delivery System)
107 Subject: Undelivered Mail Returned to Sender
108 Postmaster-Subject: Postmaster Copy: Undelivered Mail
109
110 This is the mail system at host $myhostname.
111
112 I'm sorry to have to inform you that your message could not
113 be delivered to one or more recipients. It's attached below.
114
115 For further assistance, please file an issue at
116 https://github.com/NixOS/infra/issues/new. Please anonymize any personal
117 email addresses in your report.
118
119 If you do so, please include this problem report. You can
120 delete your own text from the attached returned message.
121
122 The mail system
123 EOF
124
125 delay_template = <<EOF
126 Charset: us-ascii
127 From: MAILER-DAEMON (Mail Delivery System)
128 Subject: Delayed Mail (still being retried)
129 Postmaster-Subject: Postmaster Warning: Delayed Mail
130
131 This is the mail system at host $myhostname.
132
133 ####################################################################
134 # THIS IS A WARNING ONLY. YOU DO NOT NEED TO RESEND YOUR MESSAGE. #
135 ####################################################################
136
137 Your message could not be delivered for more than $delay_warning_time_hours hour(s).
138 It will be retried until it is $maximal_queue_lifetime_days day(s) old.
139
140 For further assistance, please file an issue at
141 https://github.com/NixOS/infra/issues/new. Please anonymize any personal
142 email addresses in your report.
143
144 If you do so, please include this problem report. You can
145 delete your own text from the attached returned message.
146
147 The mail system
148 EOF
149 ''}";
150
151 services.postsrsd.secretsFile = config.sops.secrets.postsrsd-secret.path;
152
153 # ```
154 # How to generate:
155 #
156 # ```console
157 # cd non-critical-infra
158 # SECRET_PATH=secrets/postsrsd-secret.umbriel
159 # dd if=/dev/random bs=18 count=1 status=none | base64 > "$SECRET_PATH"
160 # sops encrypt --in-place "$SECRET_PATH"
161 # ```
162 sops.secrets.postsrsd-secret = {
163 format = "binary";
164 owner = config.services.postsrsd.user;
165 group = config.services.postsrsd.group;
166 sopsFile = ../../secrets/postsrsd-secret.umbriel;
167 restartUnits = [ "postsrsd.service" ];
168 };
169 }