X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FConfig%2FNix.git;a=blobdiff_plain;f=modules%2Fprivate%2Fmail%2Fdovecot.nix;h=0304b899cb724f7b02e483d3918b8ab9f8ad4087;hp=d757f59a7db81576818671a21a8448972bc5e0ee;hb=5153eb54abab92497093fffa60c487c3523016d4;hpb=a929614f94d11a4f397e72e74f38b3212c24cdee diff --git a/modules/private/mail/dovecot.nix b/modules/private/mail/dovecot.nix index d757f59..0304b89 100644 --- a/modules/private/mail/dovecot.nix +++ b/modules/private/mail/dovecot.nix @@ -1,4 +1,4 @@ -{ lib, pkgs, config, myconfig, ... }: +{ lib, pkgs, config, ... }: let sieve_bin = pkgs.runCommand "sieve_bin" { buildInputs = [ pkgs.makeWrapper ]; @@ -12,243 +12,286 @@ let ''; in { - config.secrets.keys = [ - { - dest = "dovecot/ldap"; - user = config.services.dovecot2.user; - group = config.services.dovecot2.group; - permissions = "0400"; - text = '' - hosts = ${myconfig.env.mail.dovecot.ldap.host} - tls = yes - - dn = ${myconfig.env.mail.dovecot.ldap.dn} - dnpass = ${myconfig.env.mail.dovecot.ldap.password} + config = lib.mkIf config.myServices.mail.enable { + services.duplyBackup.profiles.mail.excludeFile = '' + + /var/lib/dhparams + + /var/lib/dovecot + ''; + secrets.keys = [ + { + dest = "dovecot/ldap"; + user = config.services.dovecot2.user; + group = config.services.dovecot2.group; + permissions = "0400"; + text = '' + hosts = ${config.myEnv.mail.dovecot.ldap.host} + tls = yes - auth_bind = yes + dn = ${config.myEnv.mail.dovecot.ldap.dn} + dnpass = ${config.myEnv.mail.dovecot.ldap.password} - ldap_version = 3 + auth_bind = yes - base = ${myconfig.env.mail.dovecot.ldap.base} - scope = subtree + ldap_version = 3 - user_filter = ${myconfig.env.mail.dovecot.ldap.filter} - pass_filter = ${myconfig.env.mail.dovecot.ldap.filter} + base = ${config.myEnv.mail.dovecot.ldap.base} + scope = subtree - user_attrs = ${myconfig.env.mail.dovecot.ldap.user_attrs} - pass_attrs = ${myconfig.env.mail.dovecot.ldap.pass_attrs} - ''; - } - ]; + pass_filter = ${config.myEnv.mail.dovecot.ldap.filter} + pass_attrs = ${config.myEnv.mail.dovecot.ldap.pass_attrs} - config.users.users.vhost = { - group = "vhost"; - uid = config.ids.uids.vhost; - }; - config.users.groups.vhost.gid = config.ids.gids.vhost; - - # https://blog.zeninc.net/index.php?post/2018/04/01/Un-annuaire-pour-les-gouverner-tous....... - config.services.dovecot2 = { - enable = true; - enablePAM = false; - enablePop3 = true; - enableImap = true; - enableLmtp = true; - protocols = [ "sieve" ]; - modules = [ - pkgs.dovecot_pigeonhole - pkgs.dovecot_deleted-to-trash - pkgs.dovecot_fts-xapian - ]; - mailUser = "vhost"; - mailGroup = "vhost"; - createMailUser = false; - mailboxes = [ - { name = "Trash"; auto = "subscribe"; specialUse = "Trash"; } - { name = "Junk"; auto = "subscribe"; specialUse = "Junk"; } - { name = "Sent"; auto = "subscribe"; specialUse = "Sent"; } - { name = "Drafts"; auto = "subscribe"; specialUse = "Drafts"; } + user_attrs = ${config.myEnv.mail.dovecot.ldap.user_attrs} + user_filter = ${config.myEnv.mail.dovecot.ldap.filter} + iterate_attrs = ${config.myEnv.mail.dovecot.ldap.iterate_attrs} + iterate_filter = ${config.myEnv.mail.dovecot.ldap.iterate_filter} + ''; + } ]; - mailLocation = "mbox:~/Mail:INBOX=~/Mail/Inbox:INDEX=~/.imap"; - sslServerCert = "/var/lib/acme/mail/fullchain.pem"; - sslServerKey = "/var/lib/acme/mail/key.pem"; - sslCACert = "/var/lib/acme/mail/fullchain.pem"; - extraConfig = builtins.concatStringsSep "\n" [ - '' - postmaster_address = postmaster@immae.eu - mail_attribute_dict = file:%h/dovecot-attributes - imap_idle_notify_interval = 20 mins - namespace inbox { - type = private - separator = / - inbox = yes - list = yes - } - '' - - # Full text search - '' - # needs to be bigger than any mailbox size - default_vsz_limit = 2GB - mail_plugins = $mail_plugins fts fts_xapian + + users.users.vhost = { + group = "vhost"; + uid = config.ids.uids.vhost; + }; + users.groups.vhost.gid = config.ids.gids.vhost; + + # https://blog.zeninc.net/index.php?post/2018/04/01/Un-annuaire-pour-les-gouverner-tous....... + services.dovecot2 = { + enable = true; + enablePAM = false; + enablePop3 = true; + enableImap = true; + enableLmtp = true; + protocols = [ "sieve" ]; + modules = [ + pkgs.dovecot_pigeonhole + pkgs.dovecot_fts-xapian + ]; + mailUser = "vhost"; + mailGroup = "vhost"; + createMailUser = false; + mailboxes = [ + { name = "Trash"; auto = "subscribe"; specialUse = "Trash"; } + { name = "Junk"; auto = "subscribe"; specialUse = "Junk"; } + { name = "Sent"; auto = "subscribe"; specialUse = "Sent"; } + { name = "Drafts"; auto = "subscribe"; specialUse = "Drafts"; } + ]; + mailLocation = "mbox:~/Mail:INBOX=~/Mail/Inbox:INDEX=~/.imap"; + sslServerCert = "/var/lib/acme/mail/fullchain.pem"; + sslServerKey = "/var/lib/acme/mail/key.pem"; + sslCACert = "/var/lib/acme/mail/fullchain.pem"; + extraConfig = builtins.concatStringsSep "\n" [ + # For printer which doesn’t support elliptic curve + '' + ssl_alt_cert = &1 > /dev/null | grep -v "Mailbox doesn't exist:" | grep -v "Info: Opening DB" + ${pkgs.dovecot}/bin/doveadm expunge -A MAILBOX Junk SEEN NOT FLAGGED BEFORE 4w 2>&1 > /dev/null | grep -v "Mailbox doesn't exist:" | grep -v "Info: Opening DB" + ${pkgs.dovecot}/bin/doveadm expunge -A MAILBOX Trash NOT FLAGGED BEFORE 4w 2>&1 > /dev/null | grep -v "Mailbox doesn't exist:" | grep -v "Info: Opening DB" + ''; + in + [ + "0 2 * * * root ${cron_script}/bin/cleanup-imap-folders" + ]; + security.acme.certs."mail-rsa" = { + postRun = '' + systemctl restart dovecot2.service + ''; + extraDomains = { + "imap.immae.eu" = null; + "pop3.immae.eu" = null; + }; + }; + security.acme.certs."mail" = { + postRun = '' + systemctl restart dovecot2.service + ''; + extraDomains = { + "imap.immae.eu" = null; + "pop3.immae.eu" = null; + }; }; }; }