nixos/services/mailserver.nix

57 lines
1.8 KiB
Nix
Raw Normal View History

2023-09-10 15:22:33 +02:00
{ config, lib, fn, mailserver, ... }:
2019-02-26 13:44:40 +01:00
with lib;
2019-02-26 13:44:40 +01:00
2023-09-10 15:22:33 +02:00
{
imports = [
mailserver.nixosModules.mailserver
];
} // mkIf (elem "mailserver" config.machine.services) {
mailserver = let
cfg = config.machine;
2019-10-08 13:15:38 +02:00
domain = cfg.domain;
fdomain = (findFirst (s: s.service == "mail") cfg cfg.vHosts).domain;
mkFqdnAlias = name: [ "${name}@${domain}" "${name}@${fdomain}" ];
2019-10-08 13:15:38 +02:00
mkExDomAlias = name: (map (exDom: "${name}@${exDom}") cfg.extraDomains);
mkUser = user: rec {
name = "${user.name}@${domain}";
value = {
2023-09-10 15:22:33 +02:00
hashedPasswordFile = config.sops.secrets."users/${user.name}/mail".path;
2019-10-08 13:15:38 +02:00
aliases = [ "${user.name}@${fdomain}" ]
++ (flatten (map mkFqdnAlias user.aliases))
++ (flatten (map mkExDomAlias ([ user.name ] ++ user.aliases)));
};
};
in rec {
2019-02-26 13:44:40 +01:00
enable = true;
fqdn = fdomain;
2019-10-08 13:15:38 +02:00
domains = ([ fdomain domain ] ++ cfg.extraDomains);
loginAccounts = listToAttrs (map mkUser cfg.mailAccounts);
2019-02-26 13:44:40 +01:00
# Use Let's Encrypt certificates. Note that this needs to set up a stripped
# down nginx and opens port 80.
2023-09-10 15:22:33 +02:00
certificateScheme = "manual";
certificateFile = "/var/lib/acme/" + fdomain + "/fullchain.pem";
keyFile = "/var/lib/acme/" + fdomain + "/key.pem";
2019-02-26 13:44:40 +01:00
#dhParamBitLength = 4096; # this doesn't exist???
# Enable IMAP and POP3
enableImap = true;
enablePop3 = false;
2019-02-26 13:44:40 +01:00
enableImapSsl = true;
enablePop3Ssl = false;
2019-02-26 13:44:40 +01:00
# Enable the ManageSieve protocol
enableManageSieve = true;
# 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;
};
2023-09-10 15:22:33 +02:00
sops.secrets = (fn.sopsHelper
(user: "users/${user.name}/mail")
config.machine.mailAccounts
{});
2019-02-26 13:44:40 +01:00
}