64 lines
2.1 KiB
Nix
64 lines
2.1 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
let
|
|
cfg = config.sbruder.mailserver;
|
|
|
|
configFile = pkgs.writeText "config-v1.1.xml" ''
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<clientConfig version="1.1">
|
|
<emailProvider id="mysystems.tld">
|
|
<domain>${lib.escapeXML cfg.autoconfig.domain}</domain>
|
|
<displayName>${lib.escapeXML cfg.autoconfig.displayName}</displayName>
|
|
<displayShortName>${lib.escapeXML cfg.autoconfig.displayShortName}</displayShortName>
|
|
<incomingServer type="imap">
|
|
<hostname>${lib.escapeXML cfg.fqdn}</hostname>
|
|
<port>993</port>
|
|
<socketType>SSL</socketType>
|
|
<authentication>password-cleartext</authentication>
|
|
<username>%EMAILADDRESS%</username>
|
|
</incomingServer>
|
|
<outgoingServer type="smtp">
|
|
<hostname>${lib.escapeXML cfg.fqdn}</hostname>
|
|
<port>465</port>
|
|
<socketType>SSL</socketType>
|
|
<authentication>password-cleartext</authentication>
|
|
<username>%EMAILADDRESS%</username>
|
|
</outgoingServer>
|
|
</emailProvider>
|
|
</clientConfig>
|
|
'';
|
|
in
|
|
{
|
|
options.sbruder.mailserver.autoconfig = {
|
|
enable = lib.mkEnableOption "autoconfiguration of compatible clients. Requires autoconfig.<domain> to exist for all specified domains";
|
|
domain = lib.mkOption {
|
|
type = lib.types.str;
|
|
description = "Domain of the mail system.";
|
|
example = "example.com";
|
|
};
|
|
displayName = lib.mkOption {
|
|
type = lib.types.str;
|
|
description = "Name of the mail system.";
|
|
default = cfg.autoconfig.domain;
|
|
};
|
|
displayShortName = lib.mkOption {
|
|
type = lib.types.str;
|
|
description = "Short name of the mail system.";
|
|
default = cfg.autoconfig.displayName;
|
|
};
|
|
};
|
|
|
|
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 = configFile;
|
|
})
|
|
cfg.domains);
|
|
};
|
|
};
|
|
}
|