complete module rewrite

This commit is contained in:
Robin Raymond 2017-09-03 11:13:34 +02:00
parent 3eb363fc71
commit 28225fb1d6
5 changed files with 144 additions and 143 deletions

View file

@ -253,15 +253,8 @@ in
./mail-server/environment.nix
./mail-server/networking.nix
./mail-server/systemd.nix
./mail-server/dovecot.nix
./mail-server/postfix.nix
./mail-server/rmilter.nix
];
config = mkIf cfg.enable {
services = import ./mail-server/services.nix {
inherit lib;
inherit (cfg) mailDirectory vmailUserName vmailGroupName virtualAliases domain
enableImap enablePop3 dkimSigning dkimSelector dkimKeyDirectory
certificateScheme certificateFile keyFile certificateDirectory virusScanning;
};
};
}

View file

@ -14,23 +14,28 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
{ vmailGroupName, vmailUserName, mailDirectory, enableImap, enablePop3, cert,
key }:
{ config, pkgs, lib, ... }:
with (import ./common.nix { inherit config; });
let
cfg = config.mailserver;
# maildir in format "/${domain}/${user}/"
dovecot_maildir = "maildir:${mailDirectory}/%d/%n/";
dovecot_maildir = "maildir:${cfg.mailDirectory}/%d/%n/";
in
{
config = with cfg; lib.mkIf enable {
services.dovecot2 = {
enable = true;
enableImap = enableImap;
enablePop3 = enablePop3;
mailGroup = vmailGroupName;
mailUser = vmailUserName;
mailLocation = dovecot_maildir;
sslServerCert = cert;
sslServerKey = key;
sslServerCert = certificatePath;
sslServerKey = keyPath;
enableLmtp = true;
extraConfig = ''
#Extra Config
@ -83,4 +88,6 @@ in
}
}
'';
};
};
}

View file

@ -14,21 +14,25 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
{ lib, mailDirectory, domain, virtualAliases, cert, key }:
{ config, pkgs, lib, ... }:
with (import ./common.nix { inherit config; });
let
cfg = config.mailserver;
# valiases_postfix :: [ String ]
valiases_postfix = map
(from:
let to = virtualAliases.${from};
in "${from}@${domain} ${to}@${domain}")
(builtins.attrNames virtualAliases);
let to = cfg.virtualAliases.${from};
in "${from}@${cfg.domain} ${to}@${cfg.domain}")
(builtins.attrNames cfg.virtualAliases);
# valiases_file :: Path
valiases_file = builtins.toFile "valias" (lib.concatStringsSep "\n" valiases_postfix);
# vhosts_file :: Path
vhosts_file = builtins.toFile "vhosts" domain;
vhosts_file = builtins.toFile "vhosts" cfg.domain;
# vaccounts_file :: Path
# see
@ -39,17 +43,19 @@ let
in
{
config = with cfg; lib.mkIf enable {
services.postfix = {
enable = true;
networksStyle = "host";
mapFiles."valias" = valiases_file;
mapFiles."vaccounts" = vaccounts_file;
sslCert = cert;
sslKey = key;
sslCert = certificatePath;
sslKey = keyPath;
enableSubmission = true;
extraConfig =
''
# Extra Config
smtpd_banner = $myhostname ESMTP NO UCE
@ -85,4 +91,6 @@ in
smtpd_sender_restrictions = "reject_sender_login_mismatch";
smtpd_recipient_restrictions = "reject_non_fqdn_recipient,reject_unknown_recipient_domain,permit_sasl_authenticated,reject";
};
};
};
}

View file

@ -14,10 +14,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
{ domain, virusScanning, dkimSigning, dkimKeyDirectory, dkimSelector }:
{ config, pkgs, lib, ... }:
let
clamav = if virusScanning
cfg = config.mailserver;
clamav = if cfg.virusScanning
then
''
clamav {
@ -25,14 +27,14 @@ let
};
''
else "";
dkim = if dkimSigning
dkim = if cfg.dkimSigning
then
''
dkim {
domain {
key = "${dkimKeyDirectory}";
key = "${cfg.dkimKeyDirectory}";
domain = "*";
selector = "${dkimSelector}";
selector = "${cfg.dkimSelector}";
};
sign_alg = sha256;
auth_only = yes;
@ -41,15 +43,17 @@ let
else "";
in
{
enable = true;
# debug = true;
postfix.enable = true;
rspamd.enable = true;
extraConfig =
config = with cfg; lib.mkIf enable {
services.rmilter.enable = true;
# services.rmilter.debug = true;
services.rmilter.postfix.enable = true;
services.rmilter.rspamd.enable = true;
services.rmilter.extraConfig =
''
${clamav}
${dkim}
'';
};
}

View file

@ -14,42 +14,31 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
{ lib, mailDirectory, vmailUserName, vmailGroupName, virtualAliases, domain,
enableImap, enablePop3, virusScanning, dkimSigning, dkimSelector,
dkimKeyDirectory, certificateScheme, certificateFile, keyFile,
certificateDirectory }:
{ config, pkgs, lib, ... }:
let
cfg = config.mailserver;
# cert :: PATH
cert = if certificateScheme == 1
then certificateFile
else if certificateScheme == 2
then "${certificateDirectory}/cert-${domain}.pem"
cert = if cfg.certificateScheme == 1
then cfg.certificateFile
else if cfg.certificateScheme == 2
then "${cfg.certificateDirectory}/cert-${cfg.domain}.pem"
else "";
# key :: PATH
key = if certificateScheme == 1
then keyFile
else if certificateScheme == 2
then "${certificateDirectory}/key-${domain}.pem"
key = if cfg.certificateScheme == 1
then cfg.keyFile
else if cfg.certificateScheme == 2
then "${cfg.certificateDirectory}/key-${cfg.domain}.pem"
else "";
in
{
# rspamd
rspamd = {
enable = true;
};
rmilter = import ./rmilter.nix {
inherit domain virusScanning dkimSigning dkimSelector dkimKeyDirectory;
};
postfix = import ./postfix.nix {
inherit lib mailDirectory domain virtualAliases cert key;
};
dovecot2 = import ./dovecot.nix {
inherit vmailGroupName vmailUserName mailDirectory enableImap
enablePop3 cert key;
};
imports = [
./rmilter.nix
./postfix.nix key
./dovecot.nix
];
}