3 inherit (config) networking users;
4 inherit (config.services) postfix;
8 #postfix/autogeree.net.nix
9 #postfix/sourcephile.fr.nix
11 users.groups.acme.members = [ postfix.user ];
12 networking.nftables.ruleset = ''
15 #tcp dport 25 counter accept comment "postfix: SMTP"
16 #tcp dport 465 counter accept comment "postfix: submissions"
19 skuid ${postfix.user} tcp dport smtp counter accept comment "postfix: SMTP"
25 networksStyle = "host";
26 hostname = "${networking.hostName}.${networking.domain}";
27 domain = networking.domain;
28 origin = "$myhostname";
31 "localhost.localdomain"
34 postmasterAlias = "root";
35 rootAlias = "root@${networking.domain}";
41 # Parse the extension in email address, eg. contact+extension@
42 recipientDelimiter = "+";
44 debug_peer_level = "4";
46 #"chomsky.autogeree.net"
48 #"mail.sourcephile.fr"
52 # Sending to the world
54 # Appending .domain is the MUA's job
55 append_dot_mydomain = false;
56 smtp_body_checks = "";
57 #smtp_cname_overrides_servername = false;
58 smtp_connect_timeout = "60s";
59 #smtp_header_checks = "regexp:/var/lib/postfix/smtp_header_checks";
60 smtp_mime_header_checks = "";
61 smtp_nested_header_checks = "";
62 smtp_tls_exclude_ciphers = [
73 #smtp_tls_fingerprint_digest = "sha1";
74 smtp_tls_loglevel = "1";
75 #smtp_tls_note_starttls_offer = true;
76 #smtp_tls_policy_maps = "hash:/var/lib/postfix/conf/tls_policy";
77 # Only allow TLSv* protocols
78 smtp_tls_protocols = [
82 #smtp_tls_scert_verifydepth = "5";
83 #smtp_tls_secure_cert_match = [ "nexthop" "dot-nexthop" ];
84 smtp_tls_security_level = "may";
85 smtp_tls_session_cache_database = "btree:$data_directory/smtp_tls_session_cache";
86 #smtp_tls_session_cache_timeout = "3600s";
87 #smtp_tls_verify_cert_match = "hostname";
90 # Receiving from the world
92 message_size_limit = 20480000;
93 maximal_queue_lifetime = "5d";
94 default_extra_recipient_limit = "5000";
95 line_length_limit = "2048";
96 duplicate_filter_limit = "5000";
97 # Stops mail from poorly written software
98 strict_rfc821_envelopes = true;
99 mime_header_checks = [ ];
100 milter_header_checks = [ ];
101 nested_header_checks = [ ];
104 permit_mx_backup_networks = [ ];
105 propagate_unmatched_extensions = [
110 #masquerade_classes = [ "envelope_sender" "header_sender" "header_recipient" ];
111 #masquerade_domains = "";
112 #masquerade_exceptions = "root";
114 # Stops some techniques used to harvest email addresses
115 disable_vrfy_command = true;
116 enable_long_queue_ids = false;
117 # Useful to test restrictions
118 smtpd_authorized_xclient_hosts = "127.0.0.1";
119 smtpd_banner = "$myhostname ESMTP $mail_name (NixOS)";
120 smtpd_client_connection_count_limit = "50";
121 smtpd_client_connection_rate_limit = "0";
122 smtpd_client_event_limit_exceptions = "$mynetworks";
123 smtpd_client_message_rate_limit = "0";
124 smtpd_client_new_tls_session_rate_limit = "0";
125 smtpd_client_port_logging = false;
126 smtpd_client_recipient_rate_limit = "0";
128 smtpd_error_sleep_time = "5";
129 # Needed to enforce reject_unknown_helo_hostname
130 smtpd_helo_required = true;
131 smtpd_helo_restrictions = [
132 "reject_invalid_helo_hostname"
133 "reject_non_fqdn_helo_hostname"
134 # Don't talk to mail systems that don't know their own hostname.
135 "reject_unknown_helo_hostname"
138 smtpd_client_restrictions = [
140 # Set in postfix/*.nix and used in submissions/smptd
141 # with reject_sender_login_mismatch
142 smtpd_sender_login_maps = [ ];
143 smtpd_sender_restrictions = [
144 "reject_non_fqdn_sender"
147 smtpd_reject_unlisted_recipient = true;
148 # Check the RCPT TO, before smtpd_recipient_restrictions
149 # Restrictions based on what is allowed or not,
150 # these are applied before smtpd_recipient_restrictions
151 smtpd_relay_restrictions = [
153 # Check the recipient's address in virtual_mailbox_domains and virtual_mailbox_maps
154 "permit_auth_destination"
155 # The world is only authorized to use our relay for the above destinations.
158 # Restrictions based on what is working or not
159 smtpd_recipient_restrictions = [
160 # Reject if the domain is not fully qualified
161 "reject_non_fqdn_recipient"
162 # Reject if the domain is not working, even before bothering to check the address
163 "reject_unknown_recipient_domain"
164 # Reject if the address is not working
165 # WARNING: this does not work if the recipient is greylisting.
166 # WARNING: verify(8) has a cache, dumpable if verify(8) is stopped, with:
167 # postmap -s btree:/var/lib/postfix/data/verify_cache
168 #"reject_unverified_recipient"
171 # Trust the verify database
172 #unverified_recipient_reject_code = "550";
173 smtpd_data_restrictions = [
174 # Force the smtpd's client to wait OK before sending
175 "reject_unauth_pipelining"
178 smtpd_end_of_data_restrictions = [
179 # Enforce mail volume quota via policy service callouts.
180 #check_policy_service unix:private/policy
183 smtpd_peername_lookup = true;
184 smtpd_recipient_limit = "5000";
185 smtpd_recipient_overshoot_limit = "5000";
186 #smtpd_restriction_classes = "";
187 #smtpd_sasl_auth_enable = true;
188 #smtpd_sasl_path = "private/auth";
189 #smtpd_sasl_security_options = "noanonymous";
190 #smtpd_sasl_type = "dovecot";
191 smtpd_starttls_timeout = "300s";
192 #smtpd_tls_always_issue_session_ids = true;
193 #smtpd_tls_CApath = "/etc/postfix/x509/ca/";
194 smtpd_tls_ask_ccert = false;
195 #smtpd_tls_ccert_verifydepth = "5";
196 smtpd_tls_ciphers = "high";
197 smtpd_tls_eecdh_grade = "auto";
198 # Disable weak ciphers as reported by https://ssl-tools.net
199 # https://serverfault.com/questions/744168/how-to-disable-rc4-on-postfix
200 smtpd_tls_exclude_ciphers = [
211 smtpd_tls_fingerprint_digest = "sha512";
212 # Log only a summary message on TLS handshake completion
213 smtpd_tls_loglevel = "1";
214 smtpd_tls_mandatory_ciphers = "high";
215 smtpd_tls_mandatory_protocols = [
220 smtpd_tls_protocols = [
224 #smtpd_tls_received_header = false;
225 smtpd_tls_req_ccert = false;
226 # Postfix 2.3 and later
228 # Mandatory TLS encryption: announce STARTTLS support to SMTP clients, and require that clients use TLS
229 # encryption. According to [1720]RFC 2487 this MUST NOT be applied in case of a publicly-referenced
230 # SMTP server. Instead, this option should be used only on dedicated servers.
231 smtpd_tls_security_level = "may";
232 smtpd_tls_session_cache_database = "btree:$data_directory/smtpd_tls_session_cache";
233 #smtpd_tls_session_cache_timeout = "3600s";
234 #smtpd_tls_chain_files =
237 #relay_clientcerts = hash:/var/lib/postfix/conf/relay_clientcerts
238 # This is where to put backup MX domains
240 relay_recipient_maps = [ ];
242 # Use a non blocking source of randomness
243 tls_random_source = "dev:/dev/urandom";
244 # Map each domain to a specific X.509 certificate
245 tls_server_sni_maps = "hash:/run/postfix/postfix-sni";
247 # Only explicitely aliased accounts have a mail, not all the passwd
248 #local_recipient_maps = "$alias_maps";
249 # Note that the local transport rewrites the envelope recipient
250 # according to the alias_maps, and thus the aliasing is transparent
251 # to the nexthop (eg. dovecot)
252 local_transport = "local:$myhostname";
253 # No console bell on new mail
256 # "$home/.forward''${recipient_delimiter}''${extension}"
260 # Filled by the postfix/*.nix
261 virtual_mailbox_domains = [ ];
262 # Completed by the postfix/*.nix
263 virtual_mailbox_maps = [
264 #"hash:/etc/postfix/virtual"
266 #virtual_transport = "lmtp:unix:private/dovecot-lmtp";
268 dovecot_destination_recipient_limit = "1";
269 virtual_transport = "dovecot";
272 # There is no fallback
273 fallback_transport = "";
276 sourcephile.wg local:losurdo
278 virtualMapType = "hash";
283 if lib.isList value then
284 lib.concatStringsSep "," value
285 else if value == true then
287 else if value == false then
291 mkKeyVal = opt: val: [
293 (opt + "=" + mkVal val)
295 mkArgs = args: lib.concatLists (lib.mapAttrsToList mkKeyVal args);
300 cleanup_service_name = "submissions-header-cleanup";
304 # Implicit TLS on port 465
305 # https://tools.ietf.org/html/rfc8314#section-3.3
311 syslog_name = "postfix/submissions";
312 # Implicit TLS, not STARTTLS
313 smtpd_tls_wrappermode = true;
314 smtpd_tls_mandatory_protocols = [
316 # FIXME: to be removed when K-9 Mail will support TLSv1.3,
317 # K-9 Mail 5.600 does not.
320 milter_macro_daemon_name = "ORIGINATING";
321 smtpd_helo_restrictions = [
322 "permit_sasl_authenticated"
323 ] ++ postfix.config.smtpd_helo_restrictions;
324 smtpd_relay_restrictions = [
325 # SASL authorizes to send to the world
326 "permit_sasl_authenticated"
329 smtpd_sasl_auth_enable = true;
330 smtpd_sasl_type = "dovecot";
331 smtpd_sasl_path = "private/auth";
332 smtpd_sasl_local_domain = "";
333 # Offer SASL authentication only after a TLS-encrypted session has been established
334 smtpd_tls_auth_only = true;
335 smtpd_sasl_tls_security_options = [ "noanonymous" ];
336 # Do not put SASL logins in mail headers
337 smtpd_sasl_authenticated_header = false;
338 # Who cares about (old) Outlook
339 broken_sasl_auth_clients = false;
340 smtpd_sender_restrictions = [
341 "reject_non_fqdn_sender"
342 # Check that the SASL user is using only its own
343 # mail addresses on the envelope, as indicated in smtpd_sender_login_maps
344 "reject_sender_login_mismatch"
347 # No X.509 certificates for users, for now
348 smtpd_tls_ask_ccert = false;
349 smtpd_tls_ccert_verifydepth = 0;
350 smtpd_tls_loglevel = 1;
351 smtpd_tls_req_ccert = false;
352 cleanup_service_name = "submissions-header-cleanup";
357 extraMasterConf = "";
360 # Warning(maint/update):
361 # storing a key and its associated certificate chain in separate files is not recommended,
362 # because this is prone to race conditions during key rollover,
363 # as there is no way to update multiple files atomically.
364 smtpd_tls_chain_files = [
365 "/var/lib/acme/${networking.domain}/key.pem"
366 "/var/lib/acme/${networking.domain}/fullchain.pem"