mirror of
https://gitlab.com/simple-nixos-mailserver/nixos-mailserver.git
synced 2024-11-11 19:39:16 +05:00
Preliminary multi-domain support
This commit is contained in:
parent
3d2f41dedc
commit
ebd0f656ed
10
default.nix
10
default.nix
@ -28,8 +28,14 @@ in
|
|||||||
|
|
||||||
domain = mkOption {
|
domain = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
example = "example.com";
|
example = "[ example.com ]";
|
||||||
description = "The domain that this mail server serves. So far only one domain is supported";
|
description = "The primary domain that this mail server serves.";
|
||||||
|
};
|
||||||
|
|
||||||
|
extraDomains = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
example = "[ example.com ]";
|
||||||
|
description = "Extra domains that this mail server serves.";
|
||||||
};
|
};
|
||||||
|
|
||||||
hostPrefix = mkOption {
|
hostPrefix = mkOption {
|
||||||
|
@ -21,23 +21,34 @@ with (import ./common.nix { inherit config; });
|
|||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.mailserver;
|
cfg = config.mailserver;
|
||||||
|
allDomains = [ cfg.domain ] ++ cfg.extraDomains;
|
||||||
|
acmeRoot = "/var/lib/acme/acme-challenge";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
config = with cfg; lib.mkIf (certificateScheme == 3) {
|
config = with cfg; lib.mkIf (certificateScheme == 3) {
|
||||||
|
|
||||||
services.nginx = {
|
services.nginx = {
|
||||||
enable = true;
|
enable = true;
|
||||||
virtualHosts = {
|
virtualHosts = genAttrs allDomains (domain: {
|
||||||
domain = {
|
serverName = "${hostPrefix}.${domain}";
|
||||||
serverName = "${hostPrefix}.${domain}";
|
forceSSL = true;
|
||||||
forceSSL = true;
|
enableACME = true;
|
||||||
enableACME = true;
|
locations."/" = {
|
||||||
locations."/" = {
|
root = "/var/www";
|
||||||
root = "/var/www";
|
};
|
||||||
};
|
acmeRoot = acmeRoot;
|
||||||
acmeRoot = "/var/lib/acme/acme-challenge";
|
});
|
||||||
};
|
};
|
||||||
};
|
security.acme.certs."${hostPrefix}.${domain}" = {
|
||||||
|
# @todo what user/group should this run as?
|
||||||
|
user = "postfix"; # cfg.user;
|
||||||
|
group = "postfix"; # lib.mkDefault cfg.group;
|
||||||
|
domain = "${hostPrefix}.${domain}";
|
||||||
|
extraDomains = map (domain: "${hostPrefix}.${domain}") extraDomains;
|
||||||
|
webroot = acmeRoot;
|
||||||
|
# @todo should we reload postfix here?
|
||||||
|
postRun = ''
|
||||||
|
systemctl reload nginx
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,19 @@
|
|||||||
with (import ./common.nix { inherit config; });
|
with (import ./common.nix { inherit config; });
|
||||||
|
|
||||||
let
|
let
|
||||||
|
inherit (lib.strings) concatStringsSep;
|
||||||
cfg = config.mailserver;
|
cfg = config.mailserver;
|
||||||
|
allDomains = [ cfg.domain ] ++ cfg.extraDomains;
|
||||||
|
|
||||||
# valiases_postfix :: [ String ]
|
# valiases_postfix :: [ String ]
|
||||||
valiases_postfix = map
|
valiases_postfix = map
|
||||||
(from:
|
(from:
|
||||||
let to = cfg.virtualAliases.${from};
|
let to = cfg.virtualAliases.${from};
|
||||||
in "${from}@${cfg.domain} ${to}@${cfg.domain}")
|
in "${from} ${to}")
|
||||||
(builtins.attrNames cfg.virtualAliases);
|
(builtins.attrNames cfg.virtualAliases);
|
||||||
|
|
||||||
# accountToIdentity :: User -> String
|
# accountToIdentity :: User -> String
|
||||||
accountToIdentity = account: "${account.name}@${cfg.domain} ${account.name}@${cfg.domain}";
|
accountToIdentity = account: "${account.name} ${account.name}";
|
||||||
|
|
||||||
# vaccounts_identity :: [ String ]
|
# vaccounts_identity :: [ String ]
|
||||||
vaccounts_identity = map accountToIdentity (lib.attrValues cfg.loginAccounts);
|
vaccounts_identity = map accountToIdentity (lib.attrValues cfg.loginAccounts);
|
||||||
@ -38,7 +40,7 @@ let
|
|||||||
valiases_file = builtins.toFile "valias" (lib.concatStringsSep "\n" valiases_postfix);
|
valiases_file = builtins.toFile "valias" (lib.concatStringsSep "\n" valiases_postfix);
|
||||||
|
|
||||||
# vhosts_file :: Path
|
# vhosts_file :: Path
|
||||||
vhosts_file = builtins.toFile "vhosts" cfg.domain;
|
vhosts_file = builtins.toFile "vhosts" (concatStringsSep ", " allDomains);
|
||||||
|
|
||||||
# vaccounts_file :: Path
|
# vaccounts_file :: Path
|
||||||
# see
|
# see
|
||||||
@ -47,7 +49,7 @@ let
|
|||||||
# every alias is owned (uniquely) by its user. We have to add the users own
|
# every alias is owned (uniquely) by its user. We have to add the users own
|
||||||
# address though
|
# address though
|
||||||
vaccounts_file = builtins.toFile "vaccounts" (lib.concatStringsSep "\n" (vaccounts_identity ++ valiases_postfix));
|
vaccounts_file = builtins.toFile "vaccounts" (lib.concatStringsSep "\n" (vaccounts_identity ++ valiases_postfix));
|
||||||
|
|
||||||
submissionHeaderCleanupRules = pkgs.writeText "submission_header_cleanup_rules" ''
|
submissionHeaderCleanupRules = pkgs.writeText "submission_header_cleanup_rules" ''
|
||||||
# Removes sensitive headers from mails handed in via the submission port.
|
# Removes sensitive headers from mails handed in via the submission port.
|
||||||
# See https://thomas-leister.de/mailserver-debian-stretch/
|
# See https://thomas-leister.de/mailserver-debian-stretch/
|
||||||
@ -67,12 +69,12 @@ in
|
|||||||
enable = true;
|
enable = true;
|
||||||
networksStyle = "host";
|
networksStyle = "host";
|
||||||
mapFiles."valias" = valiases_file;
|
mapFiles."valias" = valiases_file;
|
||||||
mapFiles."vaccounts" = vaccounts_file;
|
mapFiles."vaccounts" = vaccounts_file;
|
||||||
sslCert = certificatePath;
|
sslCert = certificatePath;
|
||||||
sslKey = keyPath;
|
sslKey = keyPath;
|
||||||
enableSubmission = true;
|
enableSubmission = true;
|
||||||
|
|
||||||
extraConfig =
|
extraConfig =
|
||||||
''
|
''
|
||||||
# Extra Config
|
# Extra Config
|
||||||
|
|
||||||
@ -116,7 +118,7 @@ in
|
|||||||
'';
|
'';
|
||||||
|
|
||||||
submissionOptions =
|
submissionOptions =
|
||||||
{
|
{
|
||||||
smtpd_tls_security_level = "encrypt";
|
smtpd_tls_security_level = "encrypt";
|
||||||
smtpd_sasl_auth_enable = "yes";
|
smtpd_sasl_auth_enable = "yes";
|
||||||
smtpd_sasl_type = "dovecot";
|
smtpd_sasl_type = "dovecot";
|
||||||
|
@ -64,7 +64,7 @@ in
|
|||||||
# Create certificates and maildir folder
|
# Create certificates and maildir folder
|
||||||
systemd.services.postfix = {
|
systemd.services.postfix = {
|
||||||
after = (if (certificateScheme == 3) then [ "nginx.service" ] else []);
|
after = (if (certificateScheme == 3) then [ "nginx.service" ] else []);
|
||||||
preStart =
|
preStart =
|
||||||
''
|
''
|
||||||
# Create mail directory and set permissions. See
|
# Create mail directory and set permissions. See
|
||||||
# <http://wiki2.dovecot.org/SharedMailboxes/Permissions>.
|
# <http://wiki2.dovecot.org/SharedMailboxes/Permissions>.
|
||||||
|
@ -30,7 +30,7 @@ let
|
|||||||
|
|
||||||
# accountsToUser :: String -> UserRecord
|
# accountsToUser :: String -> UserRecord
|
||||||
accountsToUser = account: {
|
accountsToUser = account: {
|
||||||
name = account.name + "@" + domain;
|
name = account.name;
|
||||||
isNormalUser = false;
|
isNormalUser = false;
|
||||||
group = vmailGroupName;
|
group = vmailGroupName;
|
||||||
inherit (account) hashedPassword;
|
inherit (account) hashedPassword;
|
||||||
|
@ -11,17 +11,22 @@
|
|||||||
mailserver = {
|
mailserver = {
|
||||||
enable = true;
|
enable = true;
|
||||||
domain = "example.com";
|
domain = "example.com";
|
||||||
|
extraDomains = [ "example2.com" ];
|
||||||
|
|
||||||
hostPrefix = "mail";
|
hostPrefix = "mail";
|
||||||
loginAccounts = {
|
loginAccounts = {
|
||||||
user1 = {
|
"user1@example.com" = {
|
||||||
hashedPassword = "$6$/z4n8AQl6K$kiOkBTWlZfBd7PvF5GsJ8PmPgdZsFGN1jPGZufxxr60PoR0oUsrvzm2oQiflyz5ir9fFJ.d/zKm/NgLXNUsNX/";
|
hashedPassword = "$6$/z4n8AQl6K$kiOkBTWlZfBd7PvF5GsJ8PmPgdZsFGN1jPGZufxxr60PoR0oUsrvzm2oQiflyz5ir9fFJ.d/zKm/NgLXNUsNX/";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
virtualAliases = {
|
virtualAliases = {
|
||||||
info = "user1";
|
"user1@example2.com" = "user1@example.com";
|
||||||
postmaster = "user1";
|
"info@example.com" = "user1@example.com";
|
||||||
abuse = "user1";
|
"postmaster@example.com" = "user1@example.com";
|
||||||
|
"abuse@example.com" = "user1@example.com";
|
||||||
|
"info@example2.com" = "user1@example.com";
|
||||||
|
"postmaster@example2.com" = "user1@example.com";
|
||||||
|
"abuse@example2.com" = "user1@example.com";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user