diff --git a/mail-server/dovecot.nix b/mail-server/dovecot.nix index 59ec2bc..b67a1a4 100644 --- a/mail-server/dovecot.nix +++ b/mail-server/dovecot.nix @@ -33,7 +33,7 @@ let # maildir in format "/${domain}/${user}" dovecotMaildir = - "maildir:${cfg.mailDirectory}/%d/%n${maildirLayoutAppendix}${maildirUTF8FolderNames}" + "maildir:${cfg.mailDirectory}/%d/%n/mail${maildirLayoutAppendix}${maildirUTF8FolderNames}" + (lib.optionalString (cfg.indexDir != null) ":INDEX=${cfg.indexDir}/%d/%n" ); @@ -87,6 +87,23 @@ let ''; }; + # Move all mailboxes from the old location // + # to the new location ///mail. + moveMailDirsScript = pkgs.writeScript "move-mail-dirs" '' + #!${pkgs.stdenv.shell} + + set -euo pipefail + shopt -s dotglob extglob + + for mailbox in $(find "${cfg.mailDirectory}" -mindepth 2 -maxdepth 2 -type d); do + if [ ! -d "$mailbox/mail" ]; then + mkdir "$mailbox/mail" + mv "$mailbox"/!(mail) "$mailbox/mail/" + chown -R ${cfg.vmailUserName}:${cfg.vmailGroupName} "$mailbox/mail" + fi + done + ''; + setPwdInLdapConfFile = appendLdapBindPwd { name = "ldap-conf-file"; file = ldapConfig; @@ -308,7 +325,7 @@ in userdb { driver = passwd-file args = ${userdbFile} - default_fields = uid=${builtins.toString cfg.vmailUID} gid=${builtins.toString cfg.vmailUID} home=${cfg.mailDirectory} + default_fields = home=${cfg.mailDirectory}/%d/%n uid=${toString cfg.vmailUID} gid=${toString cfg.vmailUID} } ${lib.optionalString cfg.ldap.enable '' @@ -320,7 +337,7 @@ in userdb { driver = ldap args = ${ldapConfFile} - default_fields = home=/var/vmail/ldap/%u uid=${toString cfg.vmailUID} gid=${toString cfg.vmailUID} + default_fields = home=${cfg.mailDirectory}/%d/%n uid=${toString cfg.vmailUID} gid=${toString cfg.vmailUID} } ''} @@ -374,6 +391,7 @@ in systemd.services.dovecot2 = { preStart = '' + ${moveMailDirsScript} ${genPasswdScript} '' + (lib.optionalString cfg.ldap.enable setPwdInLdapConfFile); };