X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=systems%2Feldiron%2Fmail%2Fdovecot.nix;h=a1282e3def28da74253b494669a595dd86ab6e46;hb=1a64deeb894dc95e2645a75771732c6cc53a79ad;hpb=fa25ffd4583cc362075cd5e1b4130f33306103f0;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/systems/eldiron/mail/dovecot.nix b/systems/eldiron/mail/dovecot.nix new file mode 100644 index 0000000..a1282e3 --- /dev/null +++ b/systems/eldiron/mail/dovecot.nix @@ -0,0 +1,348 @@ +{ lib, pkgs, config, ... }: +let + sieve_bin = pkgs.runCommand "sieve_bin" { + buildInputs = [ pkgs.makeWrapper ]; + } '' + cp -a ${./sieve_bin} $out + chmod -R u+w $out + patchShebangs $out + for i in $out/*; do + wrapProgram "$i" --prefix PATH : ${lib.makeBinPath [ pkgs.coreutils ]} + done + ''; +in +{ + config = lib.mkIf config.myServices.mail.enable { + myServices.dns.zones."immae.eu".subdomains = + with config.myServices.dns.helpers; + { + imap = ips servers.eldiron.ips.main; + pop3 = ips servers.eldiron.ips.main; + }; + + myServices.chatonsProperties.services.email = { + file.datetime = "2022-08-22T01:00:00"; + service = { + name = "E-mail account"; + description = "Compte e-mail avec configuration imap et smtp/pop3"; + logo = "https://www.dovecot.org/wp-content/uploads/2021/09/favicon.ico"; + website = "https://mail.immae.eu/"; + status.level = "OK"; + status.description = "OK"; + registration."" = ["MEMBER" "CLIENT"]; + registration.load = "OPEN"; + install.type = "PACKAGE"; + }; + software = { + name = "Dovecot"; + website = "https://www.dovecot.org/"; + license.url = "https://github.com/dovecot/core/blob/main/COPYING"; + license.name = "MIT and LGPLv2.1 Licenses"; + version = pkgs.dovecot.version; + source.url = "https://github.com/dovecot/core"; + modules = ["roundcube" "rainloop"] ++ map (a: a.pname) config.services.dovecot2.modules; + }; + }; + systemd.services.dovecot2.serviceConfig.Slice = "mail.slice"; + secrets.keys."dovecot/ldap" = { + user = config.services.dovecot2.user; + group = config.services.dovecot2.group; + permissions = "0400"; + text = '' + hosts = ${config.myEnv.mail.dovecot.ldap.host} + tls = yes + + dn = ${config.myEnv.mail.dovecot.ldap.dn} + dnpass = ${config.myEnv.mail.dovecot.ldap.password} + + auth_bind = yes + + ldap_version = 3 + + base = ${config.myEnv.mail.dovecot.ldap.base} + scope = subtree + + pass_filter = ${config.myEnv.mail.dovecot.ldap.filter} + pass_attrs = ${config.myEnv.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; + users.users."${config.services.dovecot2.user}".extraGroups = [ "acme" ]; + + nixpkgs.overlays = [ + (self: super: { + dovecot = super.dovecot.override { openldap = self.openldap_libressl_cyrus; }; + }) + ]; + + # 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 = "/etc/dovecot/fullchain.pem"; + sslServerKey = "/var/lib/acme/mail/key.pem"; + sslCACert = "/etc/dovecot/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 + ''; + extraDomainNames = [ "imap.immae.eu" "pop3.immae.eu" ]; + }; + security.acme.certs."mail" = { + postRun = '' + systemctl restart dovecot2.service + ''; + extraDomainNames = [ "imap.immae.eu" "pop3.immae.eu" ]; + }; + myServices.monitoring.fromMasterActivatedPlugins = [ "imap" "tcp" ]; + myServices.monitoring.fromMasterObjects.service = [ + { + service_description = "imap connection works"; + host_name = config.hostEnv.fqdn; + use = "external-service"; + check_command = "check_imap_connection"; + + servicegroups = "webstatus-remote-services,webstatus-email"; + _webstatus_name = "IMAP"; + _webstatus_url = "imap.immae.eu"; + } + + { + service_description = "imap SSL is up to date"; + host_name = config.hostEnv.fqdn; + use = "external-service"; + check_command = ["check_tcp_ssl" "993"]; + + servicegroups = "webstatus-ssl"; + _webstatus_name = "IMAP"; + _webstatus_url = "imap.immae.eu"; + } + + ]; + }; +} +