mermet: nebula: sourcephile.fr: adapt to new conventions
[sourcephile-nix.git] / hosts / mermet / dovecot.nix
index eb7d2a4189ecd2193c06cae5c546cb89ec87679a..4180b1315c6ffa8e3fb4683f0e072c0e95521094 100644 (file)
@@ -6,14 +6,6 @@ let
 
   stateDir = "/var/lib/dovecot";
 
-  sieve_pipe_bin_dir = pkgs.buildEnv {
-    name = "sieve_pipe_bin_dir";
-    pathsToLink = [ "/bin" ];
-    paths = [
-      learn-spam
-      learn-ham
-    ];
-  };
   learn-spam = pkgs.writeShellScriptBin "learn-spam.sh" ''
     exec ${pkgs.rspamd}/bin/rspamc -h /run/rspamd/learner.sock learn_spam
   '';
@@ -21,22 +13,8 @@ let
     exec ${pkgs.rspamd}/bin/rspamc -h /run/rspamd/learner.sock learn_ham
   '';
 
-  dovecot-virtual = pkgs.buildEnv {
-    name = "dovecot-virtual";
-    pathsToLink = [ "/" ];
-    paths = [
-      dovecot-virtual-all
-      dovecot-virtual-recents
-    ];
-  };
-  dovecot-virtual-all = pkgs.writeTextFile {
-    name = "dovecot-virtual-all";
-    destination = "/All/dovecot-virtual";
-    text = ''
-      *
-        all
-    '';
-  };
+  dovecot-virtual = pkgs.buildEnv { name = "dovecot-virtual"; pathsToLink = [ "/" ]; paths = [ dovecot-virtual-all dovecot-virtual-recents ]; };
+  dovecot-virtual-all = pkgs.writeTextFile { name = "dovecot-virtual-all"; destination = "/All/dovecot-virtual"; text = '' * all ''; };
   dovecot-virtual-recents = pkgs.writeTextFile {
     name = "dovecot-virtual-recents";
     destination = "/Recents/dovecot-virtual";
@@ -106,7 +84,8 @@ in
     enable = true;
     modules = [
       pkgs.dovecot_pigeonhole
-      pkgs.dovecot_fts_xapian
+      # Commented out because it uses too much disk space
+      #pkgs.dovecot_fts_xapian
     ];
     enablePAM = false;
     enableImap = true;
@@ -122,14 +101,55 @@ in
     mailUser = "";
     mailGroup = "";
     sslServerCert = null;
-    sieveScripts = {
-      global = dovecot/sieve/global;
+    sieve = {
+      plugins = [
+        #"sieve_extprograms"
+        "sieve_imapsieve"
+      ];
+      extensions = [
+        "copy"
+        "envelope"
+        "environment"
+        "fileinto"
+        "imap4flags"
+        "imapsieve"
+        "include"
+        "mailbox"
+        "subaddress"
+        "variables"
+        "vnd.dovecot.environment"
+      ];
+      globalExtensions = [
+        "vnd.dovecot.pipe"
+      ];
+      pipeBins = builtins.map lib.getExe [
+        learn-ham
+        learn-spam
+      ];
+      scripts = {
+        global = dovecot/sieve/global;
+      };
+    };
+    mailPlugins = {
+      globally.enable = [
+        "virtual"
+        "acl"
+        "quota"
+        #"fts"
+        #"fts_xapian"
+      ];
+      perProtocol = {
+        lda.enable = [ "sieve" ];
+        lmtp.enable = [ "sieve" ];
+        imap.enable = [ "imap_acl" "imap_quota" "imap_sieve" "virtual" ];
+        pop3.enable = [ "virtual" ];
+      };
     };
     extraConfig = ''
-      auth_verbose = no
-      auth_debug = no
-      mail_debug = no
-      verbose_ssl = no
+      #auth_verbose = yes
+      #auth_debug = yes
+      #mail_debug = yes
+      #verbose_ssl = yes
       log_timestamp = "%Y-%m-%d %H:%M:%S "
 
       ssl = required
@@ -147,10 +167,6 @@ in
       mail_home = ${stateDir}/home/%d/%n
       # Read multiple mails in parallel, improves performance
       mail_prefetch_count = 20
-      # Default VSZ (virtual memory size) limit for service processes. This is mainly
-      # intended to catch and kill processes that leak memory before they eat up everything.
-      # Increased for fts_xapian.
-      default_vsz_limit = 1G
 
       # DOC: https://doc.dovecot.org/configuration_manual/authentication/authentication_mechanisms/
       # DOC: https://ldapwiki.com/wiki/DIGEST-MD5
@@ -228,7 +244,6 @@ in
         separator = +
         subscriptions = yes
       }
-      mail_plugins = $mail_plugins virtual
       namespace Virtual {
         prefix = Virtual+
         separator = +
@@ -238,7 +253,6 @@ in
         location = virtual:${dovecot-virtual}:UTF-8:INDEX=${stateDir}/index/%d/%n/virtual
       }
 
-      mail_plugins = $mail_plugins acl
       plugin {
         acl = vfile:/etc/dovecot/acl/global
         acl_anyone = allow
@@ -248,26 +262,28 @@ in
         acl_shared_dict = file:${stateDir}/acl/%d/acl.db
       }
 
-      mail_plugins = $mail_plugins fts fts_xapian
-      plugin {
-        # WARNING: doveadm fts rescan is buggy, it will delete the index:
-        # https://dovecot.org/pipermail/dovecot/2019-February/114709.html
-        # If need be, use rather: doveadm index -u "*@sourcephile.fr" -q '*'
-        plugin = fts fts_xapian
-        fts = xapian
-        fts_autoindex = yes
-        fts_autoindex_exclude = \Junk
-        fts_autoindex_exclude2 = \Trash
-        fts_enforced = yes
-        # 2 and 20 are the NGram values for header fields, which means the
-        # keywords created for fields (To, Cc, ...) are between is 2 and 20 chars long.
-        # Full words are also added by default.
-        fts_xapian = partial=2 full=20 attachments=1 verbose=0
-        fts_languages = en fr
-        #fts_dovecot_fs = posix:prefix=%h/fts/
-      }
+      # Default VSZ (virtual memory size) limit for service processes. This is mainly
+      # intended to catch and kill processes that leak memory before they eat up everything.
+      # Increased for fts_xapian.
+      #default_vsz_limit = 1G
+      #plugin {
+      #  # WARNING: doveadm fts rescan is buggy, it will delete the index:
+      #  # https://dovecot.org/pipermail/dovecot/2019-February/114709.html
+      #  # If need be, use rather: doveadm index -u "*@sourcephile.fr" -q '*'
+      #  plugin = fts fts_xapian
+      #  fts = xapian
+      #  fts_autoindex = yes
+      #  fts_autoindex_exclude = \Junk
+      #  fts_autoindex_exclude2 = \Trash
+      #  fts_enforced = yes
+      #  # 2 and 20 are the NGram values for header fields, which means the
+      #  # keywords created for fields (To, Cc, ...) are between is 2 and 20 chars long.
+      #  # Full words are also added by default.
+      #  fts_xapian = partial=2 full=20 attachments=1 verbose=0
+      #  fts_languages = en fr
+      #  #fts_dovecot_fs = posix:prefix=%h/fts/
+      #}
 
-      mail_plugins = $mail_plugins quota
       plugin {
         quota = maildir:User quota
         quota_rule = *:storage=256M
@@ -281,7 +297,6 @@ in
 
       protocol lda {
         hostname = ${networking.domain}
-        mail_plugins = $mail_plugins sieve
         postmaster_address = root+dovecot+lda@${networking.domain}
         syslog_facility = mail
       }
@@ -289,7 +304,6 @@ in
       lda_mailbox_autosubscribe = yes
 
       protocol lmtp {
-        mail_plugins = $mail_plugins sieve
         postmaster_address = root+dovecot+lmtp@${networking.domain}
       }
       service lmtp {
@@ -329,7 +343,6 @@ in
       imapc_features = $imapc_features fetch-headers
       protocol imap {
         #mail_max_userip_connections = 10
-        mail_plugins = $mail_plugins imap_acl imap_quota imap_sieve virtual
         imap_metadata = yes
 
         # DOC: https://wiki.dovecot.org/MailboxSettings
@@ -411,20 +424,18 @@ in
         }
       }
       plugin {
-        sieve_plugins = sieve_imapsieve sieve_extprograms
-        sieve_global_extensions = +vnd.dovecot.environment +vnd.dovecot.pipe
-        #sieve_extensions = +editheader
         sieve = file:~/sieve;active=~/active.sieve
         sieve_default = file:${stateDir}/sieve/global/default.sieve
         sieve_default_name = main
-        sieve_pipe_bin_dir = ${sieve_pipe_bin_dir}/bin
         sieve_max_script_size = 1M
         sieve_quota_max_scripts = 0
         sieve_quota_max_storage = 10M
         #sieve_spamtest_max_value = 10
         #sieve_spamtest_status_header = X-Spam-Score
         #sieve_spamtest_status_type = strlen
-        #sieve_user_log = ~/sieve.log
+        #sieve_user_log = ~/active.sieve.log
+        #sieve_trace_dir = ~/sieve-log
+        #sieve_trace_level = matching
         # Enables support for user Sieve scripts in IMAP
         #imapsieve_url = sieve://mail.${networking.domain}:4190
 
@@ -505,7 +516,6 @@ in
       }
 
       protocol pop3 {
-        mail_plugins = $mail_plugins virtual
         #mail_max_userip_connections = 10
         # Virtual namespace for the virtual INBOX.
         # Use a global directory for dovecot-virtual files.