X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=modules%2Fprivate%2Fmail%2Fdovecot.nix;h=0ef3467ad66ad607ad1254cde8610e07a2dc2ed5;hb=4c4652aabf2cb3ac8b40f2856eca07a1df9c27e0;hp=047d7d0b688549eb27e773e65c3c4b9cd2954341;hpb=aa4f91ad67fa6287217bf67e8122a703327e5e0e;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/modules/private/mail/dovecot.nix b/modules/private/mail/dovecot.nix index 047d7d0..0ef3467 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,235 +12,284 @@ let ''; in { - config.secrets.keys = [ - { - dest = "dovecot/ldap"; + config = lib.mkIf config.myServices.mail.enable { + systemd.services.dovecot2.serviceConfig.Slice = "mail.slice"; + services.duplyBackup.profiles.mail.excludeFile = '' + + /var/lib/dhparams + + /var/lib/dovecot + ''; + secrets.keys."dovecot/ldap" = { user = config.services.dovecot2.user; group = config.services.dovecot2.group; permissions = "0400"; text = '' - hosts = ${myconfig.env.mail.dovecot.ldap.host} + hosts = ${config.myEnv.mail.dovecot.ldap.host} tls = yes - dn = ${myconfig.env.mail.dovecot.ldap.dn} - dnpass = ${myconfig.env.mail.dovecot.ldap.password} + dn = ${config.myEnv.mail.dovecot.ldap.dn} + dnpass = ${config.myEnv.mail.dovecot.ldap.password} auth_bind = yes ldap_version = 3 - base = ${myconfig.env.mail.dovecot.ldap.base} + base = ${config.myEnv.mail.dovecot.ldap.base} scope = subtree - user_filter = ${myconfig.env.mail.dovecot.ldap.filter} - pass_filter = ${myconfig.env.mail.dovecot.ldap.filter} + pass_filter = ${config.myEnv.mail.dovecot.ldap.filter} + pass_attrs = ${config.myEnv.mail.dovecot.ldap.pass_attrs} - user_attrs = ${myconfig.env.mail.dovecot.ldap.user_attrs} - pass_attrs = ${myconfig.env.mail.dovecot.ldap.pass_attrs} + 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} ''; - } - ]; + }; + + 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 = { + Trash = { auto = "subscribe"; specialUse = "Trash"; }; + Junk = { auto = "subscribe"; specialUse = "Junk"; }; + Sent = { auto = "subscribe"; specialUse = "Sent"; }; + 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; + }; }; }; }