fruitbasket/modules/mail.nix

89 lines
2.2 KiB
Nix

{ config, pkgs, ... }:
let
hostname = "mail.${config.fsr.domain}";
domain = config.fsr.domain;
in
{
sops.secrets."rspamd-password".owner = config.users.user.rspamd.name;
networking.firewall.allowedTCPPorts = [ 25 465 993 ];
services = {
postfix = {
enable = true;
hostname = "${hostname}";
domain = "${domain}";
relayHost = "";
origin = "${domain}";
destination = [ "${hostname}" "${domain}" "localhost" ];
sslCert = "/var/lib/acme/${hostname}/fullchain.pem";
sslKey = "/var/lib/acme/${hostname}/key.pem";
config = {
smtpd_recipient_restrictions = [
"reject_unauth_destination"
"permit_sasl_authenticated"
"permit_mynetworks"
];
smtpd_sasl_auth_enable = true;
smtpd_sasl_path = "/var/lib/postfix/auth";
virtual_mailbox_base = "/var/spool/mail";
};
};
dovecot2 = {
enable = true;
enableImap = true;
enableQuota = false;
sslServerCert = "/var/lib/acme/${hostname}/fullchain.pem";
sslServerKey = "/var/lib/acme/${hostname}/key.pem";
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/mail/%u
auth_mechanisms = plain login
disable_plaintext_auth = no
userdb {
driver = passwd
args = blocking=no
}
service auth {
unix_listener /var/lib/postfix/auth {
group = postfix
mode = 0660
user = postfix
}
}
'';
};
rspamd = {
enable = true;
postfix.enable = true;
locals = {
"worker-controller.inc".source = config.sops.secrets."rspamd-password".path;
};
};
nginx = {
enable = true;
virtualHosts."${hostname}" = {
forceSSL = true;
enableACME = true;
};
};
};
}