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 =
12 ssl_cert = </var/lib/acme/${domain}/fullchain.pem
13 ssl_key = </var/lib/acme/${domain}/key.pem
16 local_name mail.${domain} {
19 local_name imap.${domain} {
23 username_filter = *@${domain}
24 # Because auth_bind=yes and auth_bind_userdn are used,
25 # this cannot prefetch any userdb_*.
27 # The path to the ldap.conf must be unique,
28 # otherwise dovecot caches the result from other passdb,
29 # which may be wrong because of username_filter.
30 args = ${pkgs.writeText "${domain}-ldap.conf" (readFile ./ldap.conf)}
36 users.groups.acme.members = [ dovecot2.user ];
37 systemd.services.dovecot2.after = [
38 "acme-${domain}.service"
40 systemd.services.dovecot2 = {
42 install -D -d -m 1770 \
43 -o "${dovecot2.user}" \
45 ${stateDir}/home/${domain} \
46 ${stateDir}/control/${domain} \
47 ${stateDir}/index/${domain} \
48 ${stateDir}/acl/${domain}
50 # NOTE: do not set the sticky bit (+t)
51 # on acl/<domain>/, to let dovecot
52 # rename acl.db.lock (own by new user)
53 # to acl.db (own by old user)
54 chmod -t ${stateDir}/acl/${domain}
57 services.nginx.virtualHosts."autoconfig.${domain}" = {
58 serverName = "autoconfig.${domain}";