1 { lib, pkgs, config, myconfig, ... }:
3 sieve_bin = pkgs.runCommand "sieve_bin" {
4 buildInputs = [ pkgs.makeWrapper ];
6 cp -a ${./sieve_bin} $out
10 wrapProgram "$i" --prefix PATH : ${lib.makeBinPath [ pkgs.coreutils ]}
15 config.secrets.keys = [
17 dest = "dovecot/ldap";
18 user = config.services.dovecot2.user;
19 group = config.services.dovecot2.group;
22 hosts = ${myconfig.env.mail.dovecot.ldap.host}
25 dn = ${myconfig.env.mail.dovecot.ldap.dn}
26 dnpass = ${myconfig.env.mail.dovecot.ldap.password}
32 base = ${myconfig.env.mail.dovecot.ldap.base}
35 user_filter = ${myconfig.env.mail.dovecot.ldap.filter}
36 pass_filter = ${myconfig.env.mail.dovecot.ldap.filter}
38 user_attrs = ${myconfig.env.mail.dovecot.ldap.user_attrs}
39 pass_attrs = ${myconfig.env.mail.dovecot.ldap.pass_attrs}
44 config.users.users.vhost = {
46 uid = config.ids.uids.vhost;
48 config.users.groups.vhost.gid = config.ids.gids.vhost;
50 # https://blog.zeninc.net/index.php?post/2018/04/01/Un-annuaire-pour-les-gouverner-tous.......
51 config.services.dovecot2 = {
57 protocols = [ "sieve" ];
59 pkgs.dovecot_pigeonhole
60 pkgs.dovecot_deleted-to-trash
61 pkgs.dovecot_fts-xapian
65 createMailUser = false;
67 { name = "Trash"; auto = "subscribe"; specialUse = "Trash"; }
68 { name = "Junk"; auto = "subscribe"; specialUse = "Junk"; }
69 { name = "Sent"; auto = "subscribe"; specialUse = "Sent"; }
70 { name = "Drafts"; auto = "subscribe"; specialUse = "Drafts"; }
72 mailLocation = "mbox:~/Mail:INBOX=~/Mail/Inbox:INDEX=~/.imap";
73 sslServerCert = "/var/lib/acme/mail/fullchain.pem";
74 sslServerKey = "/var/lib/acme/mail/key.pem";
75 sslCACert = "/var/lib/acme/mail/fullchain.pem";
76 extraConfig = builtins.concatStringsSep "\n" [
78 postmaster_address = postmaster@immae.eu
79 mail_attribute_dict = file:%h/dovecot-attributes
80 imap_idle_notify_interval = 20 mins
91 # needs to be bigger than any mailbox size
92 default_vsz_limit = 2GB
93 mail_plugins = $mail_plugins fts fts_xapian
95 plugin = fts fts_xapian
97 fts_xapian = partial=2 full=20
99 fts_autoindex_exclude = \Junk
100 fts_autoindex_exclude2 = \Trash
101 fts_autoindex_exclude3 = Virtual/*
106 # https://docs.iredmail.org/dovecot.imapsieve.html
108 # imap_sieve plugin added below
111 sieve_plugins = sieve_imapsieve sieve_extprograms
112 imapsieve_url = sieve://127.0.0.1:4190
114 # From elsewhere to Junk folder
115 imapsieve_mailbox1_name = Junk
116 imapsieve_mailbox1_causes = COPY APPEND
117 imapsieve_mailbox1_before = file:${./sieve_scripts}/report_spam.sieve;bindir=/var/lib/vhost/.imapsieve_bin
119 # From Junk folder to elsewhere
120 imapsieve_mailbox2_name = *
121 imapsieve_mailbox2_from = Junk
122 imapsieve_mailbox2_causes = COPY
123 imapsieve_mailbox2_before = file:${./sieve_scripts}/report_ham.sieve;bindir=/var/lib/vhost/.imapsieve_bin
125 sieve_pipe_bin_dir = ${sieve_bin}
127 sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.environment
135 inet_listener imaps {
141 inet_listener pop3s {
149 unix_listener auth-userdb {
151 unix_listener ${config.services.postfix.config.queue_directory}/private/auth {
155 service auth-worker {
162 unix_listener stats-reader {
167 unix_listener stats-writer {
177 first_valid_uid = ${toString config.ids.uids.vhost}
178 disable_plaintext_auth = yes
181 args = ${config.secrets.fullPaths."dovecot/ldap"}
185 args = user=%u uid=vhost gid=vhost home=/var/lib/vhost/%d/%n/ mail=mbox:~/Mail:INBOX=~/Mail/Inbox:INDEX=~/.imap
191 mail_plugins = $mail_plugins zlib
201 sieve = file:~/sieve;bindir=~/.sieve-bin;active=~/.dovecot.sieve
203 service managesieve-login {
205 service managesieve {
212 deleted_to_trash_folder = Trash
218 mail_plugins = $mail_plugins virtual
221 location = virtual:~/Virtual
225 # Protocol specific configuration
226 # Needs to come last if there are mail_plugins entries
229 mail_plugins = $mail_plugins deleted_to_trash imap_sieve
232 mail_plugins = $mail_plugins sieve
237 config.networking.firewall.allowedTCPPorts = [ 110 143 993 995 4190 ];
238 config.system.activationScripts.dovecot = {
241 install -m 0755 -o vhost -g vhost -d /var/lib/vhost
245 config.security.acme.certs."mail" = {
247 systemctl restart dovecot2.service
250 "imap.immae.eu" = null;
251 "pop3.immae.eu" = null;