fruitbasket/modules/mail.nix

117 lines
2.9 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;
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-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"
];
smtpd_sasl_auth_enable = true;
smtpd_sasl_path = "/var/lib/postfix/auth";
2023-01-06 16:57:26 +01:00
virtual_mailbox_base = "/var/spool/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 = ''
2023-01-06 16:57:26 +01:00
mail_location = maildir:/var/mail/%u
2022-12-17 21:33:45 +01:00
auth_mechanisms = plain login
disable_plaintext_auth = no
userdb {
2023-01-06 16:57:26 +01:00
driver = passwd
args = blocking=no
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";
'';
};
};
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;
2023-01-09 18:14:32 +01:00
locations = {
"/rspamd" = {
proxyWebsockets = true;
# maybe there is a more beautiful way for this
extraConfig = ''
if ($request_uri ~* "/rspamd/(.*)") {
proxy_pass http://127.0.0.1:11334/$1;
}
'';
};
};
2023-01-06 16:57:26 +01:00
};
2022-12-17 21:33:45 +01:00
};
};
}