summary refs log tree commit diff
path: root/nixos/modules/services/mail/davmail.nix
diff options
context:
space:
mode:
authorSean Haugh <sean@lfo.team>2018-12-14 12:25:27 -0600
committerSean Haugh <shaugh@sunpower.com>2019-03-09 12:05:15 -0600
commitf2730d881b18e114e36b627639eeb5e14a355877 (patch)
tree6fad1fc688942ec6020b5c30f823a33be899cd30 /nixos/modules/services/mail/davmail.nix
parent4387bbf1496045533b7317bc804c3870782d6665 (diff)
downloadnixpkgs-f2730d881b18e114e36b627639eeb5e14a355877.tar
nixpkgs-f2730d881b18e114e36b627639eeb5e14a355877.tar.gz
nixpkgs-f2730d881b18e114e36b627639eeb5e14a355877.tar.bz2
nixpkgs-f2730d881b18e114e36b627639eeb5e14a355877.tar.lz
nixpkgs-f2730d881b18e114e36b627639eeb5e14a355877.tar.xz
nixpkgs-f2730d881b18e114e36b627639eeb5e14a355877.tar.zst
nixpkgs-f2730d881b18e114e36b627639eeb5e14a355877.zip
nixos/davmail: init
Co-authored-by: Aaron Andersen <aaron@fosslib.net>
Co-authored-by: Silvan Mosberger <infinisil@icloud.com>
Diffstat (limited to 'nixos/modules/services/mail/davmail.nix')
-rw-r--r--nixos/modules/services/mail/davmail.nix91
1 files changed, 91 insertions, 0 deletions
diff --git a/nixos/modules/services/mail/davmail.nix b/nixos/modules/services/mail/davmail.nix
new file mode 100644
index 00000000000..a0cb81f84da
--- /dev/null
+++ b/nixos/modules/services/mail/davmail.nix
@@ -0,0 +1,91 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+
+  cfg = config.services.davmail;
+
+  configType = with types;
+    either (either (attrsOf configType) str) (either int bool) // {
+      description = "davmail config type (str, int, bool or attribute set thereof)";
+    };
+
+  toStr = val: if isBool val then boolToString val else toString val;
+
+  linesForAttrs = attrs: concatMap (name: let value = attrs.${name}; in
+    if isAttrs value
+      then map (line: name + "." + line) (linesForAttrs value)
+      else [ "${name}=${toStr value}" ]
+  ) (attrNames attrs);
+
+  configFile = pkgs.writeText "davmail.properties" (concatStringsSep "\n" (linesForAttrs cfg.config));
+
+in
+
+  {
+    options.services.davmail = {
+      enable = mkEnableOption "davmail, an MS Exchange gateway";
+
+      url = mkOption {
+        type = types.str;
+        description = "Outlook Web Access URL to access the exchange server, i.e. the base webmail URL.";
+        example = "https://outlook.office365.com/EWS/Exchange.asmx";
+      };
+
+      config = mkOption {
+        type = configType;
+        default = {};
+        description = ''
+          Davmail configuration. Refer to
+          <link xlink:href="http://davmail.sourceforge.net/serversetup.html"/>
+          and <link xlink:href="http://davmail.sourceforge.net/advanced.html"/>
+          for details on supported values.
+        '';
+        example = literalExample ''
+          {
+            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";
+          }
+        '';
+      };
+    };
+
+    config = mkIf cfg.enable {
+
+      services.davmail.config.davmail = mapAttrs (name: mkDefault) {
+        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;
+      };
+
+      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";
+        };
+      };
+
+      environment.systemPackages = [ pkgs.davmail ];
+    };
+  }