1 { config, lib, pkgs, ... }:
4 cfg = config.services.davmail;
6 configType = with lib.types;
7 oneOf [ (attrsOf configType) str int bool ] // {
8 description = "davmail config type (str, int, bool or attribute set thereof)";
11 toStr = val: if lib.isBool val then lib.boolToString val else toString val;
13 linesForAttrs = attrs: lib.concatMap (name: let value = attrs.${name}; in
15 then map (line: name + "." + line) (linesForAttrs value)
16 else [ "${name}=${toStr value}" ]
17 ) (lib.attrNames attrs);
19 configFile = pkgs.writeText "davmail.properties" (lib.concatStringsSep "\n" (linesForAttrs cfg.config));
24 options.services.davmail = {
25 enable = lib.mkEnableOption "davmail, an MS Exchange gateway";
29 description = "Outlook Web Access URL to access the exchange server, i.e. the base webmail URL.";
30 example = "https://outlook.office365.com/EWS/Exchange.asmx";
33 config = lib.mkOption {
37 Davmail configuration. Refer to
38 <http://davmail.sourceforge.net/serversetup.html>
39 and <http://davmail.sourceforge.net/advanced.html>
40 for details on supported values.
42 example = lib.literalExpression ''
44 davmail.allowRemote = true;
45 davmail.imapPort = 55555;
46 davmail.bindAddress = "10.0.1.2";
47 davmail.smtpSaveInSent = true;
48 davmail.folderSizeLimit = 10;
49 davmail.caldavAutoSchedule = false;
50 log4j.logger.rootLogger = "DEBUG";
56 config = lib.mkIf cfg.enable {
58 services.davmail.config = {
59 davmail = lib.mapAttrs (name: lib.mkDefault) {
61 disableUpdateCheck = true;
62 logFilePath = "/var/log/davmail/davmail.log";
73 logger.davmail = lib.mkDefault "WARN";
74 logger.httpclient.wire = lib.mkDefault "WARN";
75 logger.org.apache.commons.httpclient = lib.mkDefault "WARN";
76 rootLogger = lib.mkDefault "WARN";
80 systemd.services.davmail = {
81 description = "DavMail POP/IMAP/SMTP Exchange Gateway";
82 after = [ "network.target" ];
83 wantedBy = [ "multi-user.target" ];
87 ExecStart = "${pkgs.davmail}/bin/davmail ${configFile}";
88 Restart = "on-failure";
90 LogsDirectory = "davmail";
92 CapabilityBoundingSet = [ "" ];
94 LockPersonality = true;
95 NoNewPrivileges = true;
96 PrivateDevices = true;
100 ProtectControlGroups = true;
102 ProtectSystem = "strict";
103 ProtectHostname = true;
104 ProtectKernelLogs = true;
105 ProtectKernelModules = true;
106 ProtectKernelTunables = true;
107 ProtectProc = "invisible";
109 RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
110 RestrictNamespaces = true;
111 RestrictRealtime = true;
112 RestrictSUIDSGID = true;
113 SystemCallArchitectures = "native";
114 SystemCallFilter = "@system-service";
115 SystemCallErrorNumber = "EPERM";
121 environment.systemPackages = [ pkgs.davmail ];