fruitbasket/modules/mail.nix

198 lines
5.6 KiB
Nix
Raw Normal View History

2023-03-01 16:34:15 +01:00
{ config, pkgs, lib, ... }:
2022-12-17 21:33:45 +01:00
let
2023-01-06 16:57:26 +01:00
hostname = "mail.${config.fsr.domain}";
domain = config.fsr.domain;
rspamd-domain = "rspamd.${config.fsr.domain}";
2023-02-03 15:37:56 +01:00
# brauchen wir das überhaupt?
#ldap-aliases = pkgs.writeText "ldap-aliases.cf" ''
2023-02-03 15:50:36 +01:00
#server_host = ldap://localhost
2023-02-24 17:11:53 +01:00
#search_base = dc=ifsr, dc=de
#query_filter = (&(objectClass=posixAccount)(uid=%n))
#result_attribute=mail
2023-02-03 15:37:56 +01:00
#'';
2023-01-27 16:39:25 +01:00
dovecot-ldap-args = pkgs.writeText "ldap-args" ''
2023-02-03 15:37:56 +01:00
uris = ldap://localhost
dn = uid=search, ou=users, dc=ifsr, dc=de
2023-01-27 16:39:25 +01:00
auth_bind = yes
2023-02-15 14:47:14 +01:00
!include ${config.sops.secrets."dovecot_ldap_search".path}
2023-02-03 15:37:56 +01:00
2023-01-27 16:39:25 +01:00
ldap_version = 3
scope = subtree
2023-02-03 15:37:56 +01:00
base = dc=ifsr, dc=de
2023-02-24 17:11:53 +01:00
user_filter = (&(objectClass=posixAccount)(mail=%u))
pass_filter = (&(objectClass=posixAccount)(mail=%u))
2023-01-27 16:39:25 +01:00
'';
2022-12-17 21:33:45 +01:00
in
{
2023-01-09 18:14:32 +01:00
sops.secrets."rspamd-password".owner = config.users.users.rspamd.name;
2023-02-15 14:47:14 +01:00
sops.secrets."dovecot_ldap_search".owner = config.services.dovecot2.user;
2023-01-06 16:57:26 +01:00
networking.firewall.allowedTCPPorts = [ 25 465 993 ];
2023-03-01 15:44:04 +01:00
users.users.postfix.extraGroups = [ "opendkim" ];
2023-01-06 16:57:26 +01:00
2022-12-17 21:33:45 +01:00
services = {
postfix = {
enable = true;
2023-02-24 17:11:53 +01:00
enableSubmissions = true;
2022-12-17 21:33:45 +01:00
hostname = "${hostname}";
domain = "${domain}";
origin = "${domain}";
destination = [ "${hostname}" "${domain}" "localhost" ];
2023-02-24 17:11:53 +01:00
networks = [ "127.0.0.1" "141.30.30.169" ];
2023-01-06 16:57:26 +01:00
sslCert = "/var/lib/acme/${hostname}/fullchain.pem";
sslKey = "/var/lib/acme/${hostname}/key.pem";
2023-03-24 16:24:18 +01:00
extraAliases = ''
# Taken from kaki, maybe we can throw out some at some point
# General redirections for pseudo accounts
bin: root
daemon: root
named: root
nobody: root
uucp: root
www: root
ftp-bugs: root
postfix: root
# Well-known aliases
manager: root
dumper: root
operator: root
abuse: postmaster
# trap decode to catch security attacks
decode: root
'';
2022-12-17 21:33:45 +01:00
config = {
2023-03-22 11:19:15 +01:00
home_mailbox = "Maildir/";
2023-03-01 15:44:04 +01:00
smtp_use_tls = true;
smtp_tls_security_level = "encrypt";
smtpd_use_tls = true;
smtpd_tls_security_level = lib.mkForce "encrypt";
smtpd_tls_auth_only = true;
smtpd_tls_protocols = [
"!SSLv2"
"!SSLv3"
"!TLSv1"
"!TLSv1.1"
];
2022-12-17 21:33:45 +01:00
smtpd_recipient_restrictions = [
2023-02-24 17:11:53 +01:00
"permit_sasl_authenticated"
"permit_mynetworks"
2022-12-17 21:33:45 +01:00
"reject_unauth_destination"
2023-03-01 15:44:04 +01:00
"reject_non_fqdn_hostname"
"reject_non_fqdn_sender"
"reject_non_fqdn_recipient"
"reject_unknown_sender_domain"
"reject_unknown_recipient_domain"
"reject_unauth_destination"
"reject_unauth_pipelining"
"reject_invalid_hostname"
2023-02-24 17:11:53 +01:00
];
smtpd_relay_restrictions = [
2022-12-17 21:33:45 +01:00
"permit_sasl_authenticated"
"permit_mynetworks"
2023-02-24 17:11:53 +01:00
"reject_unauth_destination"
2022-12-17 21:33:45 +01:00
];
2023-02-03 15:37:56 +01:00
#alias_maps = [ "ldap:${ldap-aliases}" ];
2023-03-01 15:44:04 +01:00
smtpd_milters = [ "local:/run/opendkim/opendkim.sock" ];
2023-03-01 15:23:07 +01:00
non_smtpd_milters = [ "local:/var/run/opendkim/opendkim.sock" ];
2022-12-17 21:33:45 +01:00
smtpd_sasl_auth_enable = true;
smtpd_sasl_path = "/var/lib/postfix/auth";
2023-02-24 17:11:53 +01:00
smtpd_sasl_type = "dovecot";
2023-03-24 15:51:57 +01:00
# virtual_mailbox_base = "/var/mail";
2022-12-17 21:33:45 +01:00
};
};
dovecot2 = {
enable = true;
enableImap = true;
enableQuota = false;
2023-03-24 15:51:57 +01:00
mailLocation = "maildir:~/Maildir";
2023-01-06 16:57:26 +01:00
sslServerCert = "/var/lib/acme/${hostname}/fullchain.pem";
sslServerKey = "/var/lib/acme/${hostname}/key.pem";
2022-12-17 21:33:45 +01:00
mailboxes = {
Spam = {
auto = "create";
specialUse = "Junk";
};
Sent = {
auto = "create";
specialUse = "Sent";
};
Drafts = {
auto = "create";
specialUse = "Drafts";
};
Trash = {
auto = "create";
specialUse = "Trash";
};
};
extraConfig = ''
2023-01-27 16:39:25 +01:00
passdb {
driver = ldap
args = ${dovecot-ldap-args}
}
2022-12-17 21:33:45 +01:00
userdb {
2023-01-27 16:39:25 +01:00
driver = ldap
args = ${dovecot-ldap-args}
2022-12-17 21:33:45 +01:00
}
service auth {
2023-01-06 16:57:26 +01:00
unix_listener /var/lib/postfix/auth {
2022-12-17 21:33:45 +01:00
group = postfix
mode = 0660
user = postfix
}
}
2023-03-01 15:23:07 +01:00
'';
};
opendkim = {
enable = true;
domains = "csl:${config.fsr.domain}";
selector = config.networking.hostName;
configFile = pkgs.writeText "opendkim-config" ''
UMask 0117
2022-12-17 21:33:45 +01:00
'';
};
rspamd = {
enable = true;
2023-01-06 16:57:26 +01:00
postfix.enable = true;
locals = {
"worker-controller.inc".source = config.sops.secrets."rspamd-password".path;
2023-01-09 18:14:32 +01:00
"redis.conf".text = ''
read_servers = "127.0.0.1";
write_servers = "127.0.0.1";
'';
2023-02-03 15:50:36 +01:00
};
2023-01-09 18:14:32 +01:00
};
redis = {
vmOverCommit = true;
servers.rspamd = {
enable = true;
port = 6379;
2022-12-17 21:33:45 +01:00
};
};
2023-01-06 16:57:26 +01:00
nginx = {
2022-12-17 21:33:45 +01:00
enable = true;
2023-01-09 18:14:32 +01:00
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedProxySettings = true;
recommendedTlsSettings = true;
2023-01-06 16:57:26 +01:00
virtualHosts."${hostname}" = {
forceSSL = true;
enableACME = true;
};
virtualHosts."${rspamd-domain}" = {
forceSSL = true;
enableACME = true;
2023-01-09 18:14:32 +01:00
locations = {
"/" = {
proxyPass = "http://127.0.0.1:11334";
2023-01-09 18:14:32 +01:00
proxyWebsockets = true;
};
};
2023-01-06 16:57:26 +01:00
};
2022-12-17 21:33:45 +01:00
};
};
}