Add alias to mail accounts.

Automatically add fqdn as mail alias.
This commit is contained in:
Kevin Baensch 2019-08-27 23:32:46 +02:00
parent a80b06b881
commit 7d70e000ce
4 changed files with 11 additions and 8 deletions

View file

@ -10,7 +10,7 @@ with lib;
config.machine = rec {
hostName = "DavidsServer";
administrators = [ { name = "david"; id = 1000; } ];
mailAccounts = [ "david" ];
mailAccounts = [ { name = "david"; aliases = []; } ];
domain = "davids-planet.de";
allowUnfree = true;
conffiles = [

View file

@ -11,7 +11,7 @@ with lib;
config.machine = rec {
hostName = "Ophanim";
administrators = [ { name = "derped"; id = 1337; } ];
mailAccounts = [ "derped" "mailman3" ];
mailAccounts = [ { name = "derped"; aliases = [ "postmaster" ]; } { name = "mailman3"; aliases = []; } ];
domain = "ophanim.de";
allowUnfree = true;
conffiles = [

View file

@ -48,7 +48,7 @@ with lib;
'';
};
mailAccounts = mkOption {
type = types.listOf types.string;
type = types.listOf types.attrs;
description = ''
List of mail account user names.
'';

View file

@ -4,16 +4,19 @@ with lib;
mkIf (elem "mailserver" config.machine.services) {
mailserver = let
mkUser = username: {
name = "${username}@${config.machine.domain}";
domain = config.machine.domain;
mkFqdnAlias = name: [ "${name}@${domain}" "${name}@mail.${domain}" ];
mkUser = user: rec {
name = "${user.name}@${domain}";
value = {
hashedPassword = (fileContents "/secret/${username}.mail");
hashedPassword = (fileContents "/secret/${user.name}.mail");
aliases = [ "${user.name}@mail.${domain}" ] ++ (flatten (map mkFqdnAlias user.aliases));
};
};
in rec {
enable = true;
fqdn = "mail.${config.machine.domain}";
domains = [ config.machine.domain ];
fqdn = "mail.${domain}";
domains = [ domain ];
loginAccounts = listToAttrs (map mkUser config.machine.mailAccounts);
# Use Let's Encrypt certificates. Note that this needs to set up a stripped