nixos/services/mailserver.nix

72 lines
2 KiB
Nix
Raw Normal View History

2023-09-10 15:22:33 +02:00
{
2023-09-11 20:23:04 +02:00
config,
lib,
fn,
mailserver,
...
}:
with lib;
{
imports = [
mailserver.nixosModules.mailserver
];
}
2024-12-07 21:43:57 +01:00
// mkIf (elem "mailserver" config.machine.services) (
let
cfg = config.machine;
inherit (cfg) domain;
fdomain = (findFirst (s: s.service == "mail") cfg cfg.vHosts).domain;
mkFqdnAlias = name: [
"${name}@${domain}"
"${name}@${fdomain}"
];
mkExDomAlias = name: (map (exDom: "${name}@${exDom}") cfg.extraDomains);
mkUser = user: {
name = "${user.name}@${domain}";
value = {
hashedPasswordFile = config.sops.secrets."users/${user.name}/mail".path;
aliases =
[ "${user.name}@${fdomain}" ]
++ (flatten (map mkFqdnAlias user.aliases))
++ (flatten (map mkExDomAlias ([ user.name ] ++ user.aliases)));
};
2024-12-07 21:43:57 +01:00
};
in
{
mailserver = {
2023-09-11 20:23:04 +02:00
enable = true;
fqdn = fdomain;
domains = [
fdomain
domain
] ++ cfg.extraDomains;
2023-09-11 20:23:04 +02:00
loginAccounts = listToAttrs (map mkUser cfg.mailAccounts);
2023-09-11 20:23:04 +02:00
# Use Let's Encrypt certificates. Note that this needs to set up a stripped
# down nginx and opens port 80.
certificateScheme = "manual";
certificateFile = "/var/lib/acme/" + fdomain + "/fullchain.pem";
keyFile = "/var/lib/acme/" + fdomain + "/key.pem";
2019-02-26 13:44:40 +01:00
2023-09-11 20:23:04 +02:00
#dhParamBitLength = 4096; # this doesn't exist???
2019-02-26 13:44:40 +01:00
2023-09-11 20:23:04 +02:00
# Enable IMAP and POP3
enableImap = true;
enablePop3 = false;
enableImapSsl = true;
enablePop3Ssl = false;
2019-02-26 13:44:40 +01:00
2023-09-11 20:23:04 +02:00
# Enable the ManageSieve protocol
enableManageSieve = true;
2019-02-26 13:44:40 +01:00
2023-09-11 20:23:04 +02:00
# whether to scan inbound emails for viruses (note that this requires at least
# 1 Gb RAM for the server. Without virus scanning 256 MB RAM should be plenty)
virusScanning = false;
};
2024-12-07 21:43:57 +01:00
systemd.services."acme-${fdomain}".serviceConfig.ExecStartPost = [
"+systemctl reload dovecot2"
];
sops.secrets = fn.sopsHelper (user: "users/${user.name}/mail") config.machine.mailAccounts { };
}
)