dovecot: split passdb and userdb

This commit is contained in:
Lafiel 2023-03-16 16:59:05 +03:00 committed by lewo
parent bd99079363
commit d8131ffc61
1 changed files with 15 additions and 6 deletions

View File

@ -22,7 +22,8 @@ let
cfg = config.mailserver; cfg = config.mailserver;
passwdDir = "/run/dovecot2"; passwdDir = "/run/dovecot2";
passwdFile = "${passwdDir}/passwd"; passdbFile = "${passwdDir}/passdb";
userdbFile = "${passwdDir}/userdb";
bool2int = x: if x then "1" else "0"; bool2int = x: if x then "1" else "0";
@ -74,16 +75,23 @@ let
fi fi
done done
cat <<EOF > ${passwdFile} cat <<EOF > ${passdbFile}
${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value: ${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value:
"${name}:${"$(head -n 1 ${passwordFiles."${name}"})"}:${builtins.toString cfg.vmailUID}:${builtins.toString cfg.vmailUID}::${cfg.mailDirectory}:/run/current-system/sw/bin/nologin:" "${name}:${"$(head -n 1 ${passwordFiles."${name}"})"}::::::"
) cfg.loginAccounts)}
EOF
cat <<EOF > ${userdbFile}
${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value:
"${name}:::::::"
+ (if lib.isString value.quota + (if lib.isString value.quota
then "userdb_quota_rule=*:storage=${value.quota}" then "userdb_quota_rule=*:storage=${value.quota}"
else "") else "")
) cfg.loginAccounts)} ) cfg.loginAccounts)}
EOF EOF
chmod 600 ${passwdFile} chmod 600 ${passdbFile}
chmod 600 ${userdbFile}
''; '';
junkMailboxes = builtins.attrNames (lib.filterAttrs (n: v: v ? "specialUse" && v.specialUse == "Junk") cfg.mailboxes); junkMailboxes = builtins.attrNames (lib.filterAttrs (n: v: v ? "specialUse" && v.specialUse == "Junk") cfg.mailboxes);
@ -212,12 +220,13 @@ in
passdb { passdb {
driver = passwd-file driver = passwd-file
args = ${passwdFile} args = ${passdbFile}
} }
userdb { userdb {
driver = passwd-file driver = passwd-file
args = ${passwdFile} args = ${userdbFile}
default_fields = uid=${builtins.toString cfg.vmailUID} gid=${builtins.toString cfg.vmailUID} home=${cfg.mailDirectory}
} }
service auth { service auth {