1 { pkgs, lib, config, ... }:
3 inherit (builtins) readFile;
4 inherit (config.services) dovecot2;
5 stateDir = "/var/lib/dovecot";
6 domain = "sourcephile.fr";
7 domainGroup = "sourcephile";
10 services.dovecot2.extraConfig =
13 ssl_cert = </var/lib/acme/${domain}/fullchain.pem
14 ssl_key = </var/lib/acme/${domain}/key.pem
18 local_name mail.${domain} {
21 local_name imap.${domain} {
25 username_filter = *@${domain}
26 # Because auth_bind=yes and auth_bind_userdn are used,
27 # this cannot prefetch any userdb_*.
29 # The path to the ldap.conf must be unique,
30 # otherwise dovecot caches the result from other passdb,
31 # which may be wrong because of username_filter.
32 args = ${pkgs.writeText "${domain}-ldap.conf" (readFile ./ldap.conf)}
38 security.acme.certs."${domain}" = {
39 postRun = "systemctl reload dovecot2";
41 systemd.services.dovecot2 = {
42 wants = [ "acme-selfsigned-${domain}.service" "acme-${domain}.service" ];
43 after = [ "acme-selfsigned-${domain}.service" ];
45 install -D -d -m 1770 \
46 -o "${dovecot2.user}" \
48 ${stateDir}/home/${domain} \
49 ${stateDir}/control/${domain} \
50 ${stateDir}/index/${domain} \
51 ${stateDir}/acl/${domain}
53 # NOTE: do not set the sticky bit (+t)
54 # on acl/<domain>/, to let dovecot
55 # rename acl.db.lock (own by new user)
56 # to acl.db (own by old user)
57 chmod -t ${stateDir}/acl/${domain}
60 services.nginx.virtualHosts."autoconfig.${domain}" = {
61 serverName = "autoconfig.${domain}";