{ config, lib, pkgs, ... }:
let
cfg = config.sbruder.mailserver;
mkConfigFile = domain: pkgs.writeText "config-v1.1.xml" ''
${lib.escapeXML domain}
${lib.escapeXML domain}
${lib.escapeXML domain}
${lib.escapeXML cfg.fqdn}
993
SSL
password-cleartext
%EMAILADDRESS%
${lib.escapeXML cfg.fqdn}
465
SSL
password-cleartext
%EMAILADDRESS%
'';
in
{
options.sbruder.mailserver.autoconfig = {
enable = lib.mkEnableOption "autoconfiguration of compatible clients. Requires autoconfig. to exist for all specified domains";
};
config = lib.mkIf cfg.enable {
services.nginx = lib.mkIf cfg.autoconfig.enable {
enable = true;
virtualHosts = lib.listToAttrs (map
(domain: lib.nameValuePair "autoconfig.${domain}" {
enableACME = true;
forceSSL = true;
locations."=/mail/config-v1.1.xml".alias = mkConfigFile domain;
})
cfg.domains);
};
};
}