2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.davmail;
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
configType = with lib.types;
|
2020-04-24 23:36:52 +00:00
|
|
|
oneOf [ (attrsOf configType) str int bool ] // {
|
|
|
|
description = "davmail config type (str, int, bool or attribute set thereof)";
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
toStr = val: if lib.isBool val then lib.boolToString val else toString val;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
linesForAttrs = attrs: lib.concatMap (name: let value = attrs.${name}; in
|
|
|
|
if lib.isAttrs value
|
2020-04-24 23:36:52 +00:00
|
|
|
then map (line: name + "." + line) (linesForAttrs value)
|
|
|
|
else [ "${name}=${toStr value}" ]
|
2024-09-19 14:19:46 +00:00
|
|
|
) (lib.attrNames attrs);
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
configFile = pkgs.writeText "davmail.properties" (lib.concatStringsSep "\n" (linesForAttrs cfg.config));
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options.services.davmail = {
|
2024-09-19 14:19:46 +00:00
|
|
|
enable = lib.mkEnableOption "davmail, an MS Exchange gateway";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
url = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Outlook Web Access URL to access the exchange server, i.e. the base webmail URL.";
|
2020-04-24 23:36:52 +00:00
|
|
|
example = "https://outlook.office365.com/EWS/Exchange.asmx";
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
config = lib.mkOption {
|
2020-04-24 23:36:52 +00:00
|
|
|
type = configType;
|
|
|
|
default = {};
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Davmail configuration. Refer to
|
2022-08-12 12:06:08 +00:00
|
|
|
<http://davmail.sourceforge.net/serversetup.html>
|
|
|
|
and <http://davmail.sourceforge.net/advanced.html>
|
2020-04-24 23:36:52 +00:00
|
|
|
for details on supported values.
|
|
|
|
'';
|
2024-09-19 14:19:46 +00:00
|
|
|
example = lib.literalExpression ''
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
|
|
|
davmail.allowRemote = true;
|
|
|
|
davmail.imapPort = 55555;
|
|
|
|
davmail.bindAddress = "10.0.1.2";
|
|
|
|
davmail.smtpSaveInSent = true;
|
|
|
|
davmail.folderSizeLimit = 10;
|
|
|
|
davmail.caldavAutoSchedule = false;
|
|
|
|
log4j.logger.rootLogger = "DEBUG";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
services.davmail.config = {
|
2024-09-19 14:19:46 +00:00
|
|
|
davmail = lib.mapAttrs (name: lib.mkDefault) {
|
2020-04-24 23:36:52 +00:00
|
|
|
server = true;
|
|
|
|
disableUpdateCheck = true;
|
|
|
|
logFilePath = "/var/log/davmail/davmail.log";
|
|
|
|
logFileSize = "1MB";
|
|
|
|
mode = "auto";
|
|
|
|
url = cfg.url;
|
|
|
|
caldavPort = 1080;
|
|
|
|
imapPort = 1143;
|
|
|
|
ldapPort = 1389;
|
|
|
|
popPort = 1110;
|
|
|
|
smtpPort = 1025;
|
|
|
|
};
|
|
|
|
log4j = {
|
2024-09-19 14:19:46 +00:00
|
|
|
logger.davmail = lib.mkDefault "WARN";
|
|
|
|
logger.httpclient.wire = lib.mkDefault "WARN";
|
|
|
|
logger.org.apache.commons.httpclient = lib.mkDefault "WARN";
|
|
|
|
rootLogger = lib.mkDefault "WARN";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.davmail = {
|
|
|
|
description = "DavMail POP/IMAP/SMTP Exchange Gateway";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
ExecStart = "${pkgs.davmail}/bin/davmail ${configFile}";
|
|
|
|
Restart = "on-failure";
|
|
|
|
DynamicUser = "yes";
|
|
|
|
LogsDirectory = "davmail";
|
2023-07-15 17:15:38 +00:00
|
|
|
|
|
|
|
CapabilityBoundingSet = [ "" ];
|
|
|
|
DeviceAllow = [ "" ];
|
|
|
|
LockPersonality = true;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
RemoveIPC = true;
|
|
|
|
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = "@system-service";
|
|
|
|
SystemCallErrorNumber = "EPERM";
|
|
|
|
UMask = "0077";
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.davmail ];
|
|
|
|
};
|
|
|
|
}
|