fruitbasket/modules/mail.nix

170 lines
3.8 KiB
Nix
Raw Normal View History

{ config, pkgs, ... }:
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
#search_base = ou=mail, dc=ifsr, dc=de
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:40:37 +01:00
dnpass = $(${pkgs.coreutils}/bin/cat ${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-01-27 16:39:25 +01:00
user_filter = (&(ou=mail)(uid=%n))
pass_filter = (&(ou=mail)(uid=%n))
'';
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:40:37 +01:00
sops.secrets."dovecot_ldap_search" = {
key = "portunus_search";
owner = config.services.dovecot2.user;
};
2023-01-06 16:57:26 +01:00
networking.firewall.allowedTCPPorts = [ 25 465 993 ];
2022-12-17 21:33:45 +01:00
services = {
postfix = {
enable = true;
hostname = "${hostname}";
domain = "${domain}";
relayHost = "";
origin = "${domain}";
destination = [ "${hostname}" "${domain}" "localhost" ];
2023-01-06 16:57:26 +01:00
sslCert = "/var/lib/acme/${hostname}/fullchain.pem";
sslKey = "/var/lib/acme/${hostname}/key.pem";
2022-12-17 21:33:45 +01:00
config = {
smtpd_recipient_restrictions = [
"reject_unauth_destination"
"permit_sasl_authenticated"
"permit_mynetworks"
];
2023-02-03 15:37:56 +01:00
#alias_maps = [ "ldap:${ldap-aliases}" ];
2022-12-17 21:33:45 +01:00
smtpd_sasl_auth_enable = true;
smtpd_sasl_path = "/var/lib/postfix/auth";
virtual_mailbox_base = "/var/lib/mail";
2022-12-17 21:33:45 +01:00
};
};
dovecot2 = {
enable = true;
enableImap = true;
enableQuota = false;
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 = ''
mail_location = maildir:/var/lib/mail/%u
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
}
}
'';
};
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-01-20 15:57:12 +01:00
"dkim_signing.conf".text = ''
path = "/var/lib/rspamd/dkim/$domain.$selector.key";
selector = "quitte";
sign_authenticated = true;
use_domain = "header";
'';
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
};
};
}