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