users: remove global with config.mailserver
This commit is contained in:
+26
-26
@@ -31,16 +31,16 @@ with (import ./common.nix {
|
||||
;
|
||||
});
|
||||
|
||||
with config.mailserver;
|
||||
|
||||
let
|
||||
cfg = config.mailserver;
|
||||
|
||||
vmail_user = {
|
||||
name = vmailUserName;
|
||||
name = cfg.vmailUserName;
|
||||
isSystemUser = true;
|
||||
uid = vmailUID;
|
||||
home = mailDirectory;
|
||||
uid = cfg.vmailUID;
|
||||
home = cfg.mailDirectory;
|
||||
createHome = true;
|
||||
group = vmailGroupName;
|
||||
group = cfg.vmailGroupName;
|
||||
};
|
||||
|
||||
virtualMailUsersActivationScript =
|
||||
@@ -55,10 +55,10 @@ let
|
||||
umask 007
|
||||
|
||||
# Create directory to store user sieve scripts if it doesn't exist
|
||||
if (! test -d "${sieveDirectory}"); then
|
||||
mkdir "${sieveDirectory}"
|
||||
chown "${vmailUserName}:${vmailGroupName}" "${sieveDirectory}"
|
||||
chmod 770 "${sieveDirectory}"
|
||||
if (! test -d "${cfg.sieveDirectory}"); then
|
||||
mkdir "${cfg.sieveDirectory}"
|
||||
chown "${cfg.vmailUserName}:${cfg.vmailGroupName}" "${cfg.sieveDirectory}"
|
||||
chmod 770 "${cfg.sieveDirectory}"
|
||||
fi
|
||||
|
||||
# Copy user's sieve script to the correct location (if it exists). If it
|
||||
@@ -67,30 +67,30 @@ let
|
||||
{ name, sieveScript }:
|
||||
if lib.isString sieveScript then
|
||||
''
|
||||
if (! test -d "${sieveDirectory}/${name}"); then
|
||||
mkdir -p "${sieveDirectory}/${name}"
|
||||
chown "${vmailUserName}:${vmailGroupName}" "${sieveDirectory}/${name}"
|
||||
chmod 770 "${sieveDirectory}/${name}"
|
||||
if (! test -d "${cfg.sieveDirectory}/${name}"); then
|
||||
mkdir -p "${cfg.sieveDirectory}/${name}"
|
||||
chown "${cfg.vmailUserName}:${cfg.vmailGroupName}" "${cfg.sieveDirectory}/${name}"
|
||||
chmod 770 "${cfg.sieveDirectory}/${name}"
|
||||
fi
|
||||
cat << 'EOF' > "${sieveDirectory}/${name}/default.sieve"
|
||||
cat << 'EOF' > "${cfg.sieveDirectory}/${name}/default.sieve"
|
||||
${sieveScript}
|
||||
EOF
|
||||
chown "${vmailUserName}:${vmailGroupName}" "${sieveDirectory}/${name}/default.sieve"
|
||||
chown "${cfg.vmailUserName}:${cfg.vmailGroupName}" "${cfg.sieveDirectory}/${name}/default.sieve"
|
||||
''
|
||||
else
|
||||
''
|
||||
if (test -f "${sieveDirectory}/${name}/default.sieve"); then
|
||||
rm "${sieveDirectory}/${name}/default.sieve"
|
||||
if (test -f "${cfg.sieveDirectory}/${name}/default.sieve"); then
|
||||
rm "${cfg.sieveDirectory}/${name}/default.sieve"
|
||||
fi
|
||||
if (test -f "${sieveDirectory}/${name}.svbin"); then
|
||||
rm "${sieveDirectory}/${name}/default.svbin"
|
||||
if (test -f "${cfg.sieveDirectory}/${name}.svbin"); then
|
||||
rm "${cfg.sieveDirectory}/${name}/default.svbin"
|
||||
fi
|
||||
''
|
||||
) (map (user: { inherit (user) name sieveScript; }) (lib.attrValues accounts))}
|
||||
) (map (user: { inherit (user) name sieveScript; }) (lib.attrValues cfg.accounts))}
|
||||
'';
|
||||
in
|
||||
{
|
||||
config = lib.mkIf enable {
|
||||
config = lib.mkIf cfg.enable {
|
||||
# assert that all accounts provide a password
|
||||
assertions = map (acct: {
|
||||
assertion =
|
||||
@@ -102,21 +102,21 @@ in
|
||||
]
|
||||
) == 1;
|
||||
message = "Login account ${acct.name} must provide exactly one of password file, hashed password, or hashed password file";
|
||||
}) (lib.attrValues accounts);
|
||||
}) (lib.attrValues cfg.accounts);
|
||||
|
||||
# warn for accounts that specify both password and file
|
||||
warnings =
|
||||
map (acct: "${acct.name} specifies both a password hash and hash file; hash file will be used")
|
||||
(
|
||||
lib.filter (acct: (acct.hashedPassword != null && acct.hashedPasswordFile != null)) (
|
||||
lib.attrValues accounts
|
||||
lib.attrValues cfg.accounts
|
||||
)
|
||||
);
|
||||
|
||||
# set the vmail gid to a specific value
|
||||
users.groups = {
|
||||
"${vmailGroupName}" = {
|
||||
gid = vmailUID;
|
||||
"${cfg.vmailGroupName}" = {
|
||||
gid = cfg.vmailUID;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user