complete module rewrite
This commit is contained in:
parent
3eb363fc71
commit
28225fb1d6
13
default.nix
13
default.nix
|
@ -253,15 +253,8 @@ in
|
||||||
./mail-server/environment.nix
|
./mail-server/environment.nix
|
||||||
./mail-server/networking.nix
|
./mail-server/networking.nix
|
||||||
./mail-server/systemd.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;
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,23 +14,28 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
|
||||||
{ vmailGroupName, vmailUserName, mailDirectory, enableImap, enablePop3, cert,
|
{ config, pkgs, lib, ... }:
|
||||||
key }:
|
|
||||||
|
with (import ./common.nix { inherit config; });
|
||||||
|
|
||||||
let
|
let
|
||||||
|
cfg = config.mailserver;
|
||||||
|
|
||||||
# maildir in format "/${domain}/${user}/"
|
# maildir in format "/${domain}/${user}/"
|
||||||
dovecot_maildir = "maildir:${mailDirectory}/%d/%n/";
|
dovecot_maildir = "maildir:${cfg.mailDirectory}/%d/%n/";
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
config = with cfg; lib.mkIf enable {
|
||||||
|
services.dovecot2 = {
|
||||||
enable = true;
|
enable = true;
|
||||||
enableImap = enableImap;
|
enableImap = enableImap;
|
||||||
enablePop3 = enablePop3;
|
enablePop3 = enablePop3;
|
||||||
mailGroup = vmailGroupName;
|
mailGroup = vmailGroupName;
|
||||||
mailUser = vmailUserName;
|
mailUser = vmailUserName;
|
||||||
mailLocation = dovecot_maildir;
|
mailLocation = dovecot_maildir;
|
||||||
sslServerCert = cert;
|
sslServerCert = certificatePath;
|
||||||
sslServerKey = key;
|
sslServerKey = keyPath;
|
||||||
enableLmtp = true;
|
enableLmtp = true;
|
||||||
extraConfig = ''
|
extraConfig = ''
|
||||||
#Extra Config
|
#Extra Config
|
||||||
|
@ -83,4 +88,6 @@ in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,21 +14,25 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
# 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
|
let
|
||||||
|
cfg = config.mailserver;
|
||||||
|
|
||||||
# valiases_postfix :: [ String ]
|
# valiases_postfix :: [ String ]
|
||||||
valiases_postfix = map
|
valiases_postfix = map
|
||||||
(from:
|
(from:
|
||||||
let to = virtualAliases.${from};
|
let to = cfg.virtualAliases.${from};
|
||||||
in "${from}@${domain} ${to}@${domain}")
|
in "${from}@${cfg.domain} ${to}@${cfg.domain}")
|
||||||
(builtins.attrNames virtualAliases);
|
(builtins.attrNames cfg.virtualAliases);
|
||||||
|
|
||||||
# valiases_file :: Path
|
# valiases_file :: Path
|
||||||
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" domain;
|
vhosts_file = builtins.toFile "vhosts" cfg.domain;
|
||||||
|
|
||||||
# vaccounts_file :: Path
|
# vaccounts_file :: Path
|
||||||
# see
|
# see
|
||||||
|
@ -39,17 +43,19 @@ let
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
config = with cfg; lib.mkIf enable {
|
||||||
|
|
||||||
|
services.postfix = {
|
||||||
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 = cert;
|
sslCert = certificatePath;
|
||||||
sslKey = key;
|
sslKey = keyPath;
|
||||||
enableSubmission = true;
|
enableSubmission = true;
|
||||||
|
|
||||||
extraConfig =
|
extraConfig =
|
||||||
''
|
''
|
||||||
|
|
||||||
# Extra Config
|
# Extra Config
|
||||||
|
|
||||||
smtpd_banner = $myhostname ESMTP NO UCE
|
smtpd_banner = $myhostname ESMTP NO UCE
|
||||||
|
@ -85,4 +91,6 @@ in
|
||||||
smtpd_sender_restrictions = "reject_sender_login_mismatch";
|
smtpd_sender_restrictions = "reject_sender_login_mismatch";
|
||||||
smtpd_recipient_restrictions = "reject_non_fqdn_recipient,reject_unknown_recipient_domain,permit_sasl_authenticated,reject";
|
smtpd_recipient_restrictions = "reject_non_fqdn_recipient,reject_unknown_recipient_domain,permit_sasl_authenticated,reject";
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,12 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
|
||||||
{ domain, virusScanning, dkimSigning, dkimKeyDirectory, dkimSelector }:
|
{ config, pkgs, lib, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
clamav = if virusScanning
|
cfg = config.mailserver;
|
||||||
|
|
||||||
|
clamav = if cfg.virusScanning
|
||||||
then
|
then
|
||||||
''
|
''
|
||||||
clamav {
|
clamav {
|
||||||
|
@ -25,14 +27,14 @@ let
|
||||||
};
|
};
|
||||||
''
|
''
|
||||||
else "";
|
else "";
|
||||||
dkim = if dkimSigning
|
dkim = if cfg.dkimSigning
|
||||||
then
|
then
|
||||||
''
|
''
|
||||||
dkim {
|
dkim {
|
||||||
domain {
|
domain {
|
||||||
key = "${dkimKeyDirectory}";
|
key = "${cfg.dkimKeyDirectory}";
|
||||||
domain = "*";
|
domain = "*";
|
||||||
selector = "${dkimSelector}";
|
selector = "${cfg.dkimSelector}";
|
||||||
};
|
};
|
||||||
sign_alg = sha256;
|
sign_alg = sha256;
|
||||||
auth_only = yes;
|
auth_only = yes;
|
||||||
|
@ -41,15 +43,17 @@ let
|
||||||
else "";
|
else "";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
enable = true;
|
config = with cfg; lib.mkIf enable {
|
||||||
# debug = true;
|
services.rmilter.enable = true;
|
||||||
postfix.enable = true;
|
# services.rmilter.debug = true;
|
||||||
rspamd.enable = true;
|
services.rmilter.postfix.enable = true;
|
||||||
extraConfig =
|
services.rmilter.rspamd.enable = true;
|
||||||
|
services.rmilter.extraConfig =
|
||||||
''
|
''
|
||||||
${clamav}
|
${clamav}
|
||||||
|
|
||||||
${dkim}
|
${dkim}
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,42 +14,31 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
|
||||||
{ lib, mailDirectory, vmailUserName, vmailGroupName, virtualAliases, domain,
|
|
||||||
enableImap, enablePop3, virusScanning, dkimSigning, dkimSelector,
|
{ config, pkgs, lib, ... }:
|
||||||
dkimKeyDirectory, certificateScheme, certificateFile, keyFile,
|
|
||||||
certificateDirectory }:
|
|
||||||
|
|
||||||
let
|
let
|
||||||
|
cfg = config.mailserver;
|
||||||
|
|
||||||
# cert :: PATH
|
# cert :: PATH
|
||||||
cert = if certificateScheme == 1
|
cert = if cfg.certificateScheme == 1
|
||||||
then certificateFile
|
then cfg.certificateFile
|
||||||
else if certificateScheme == 2
|
else if cfg.certificateScheme == 2
|
||||||
then "${certificateDirectory}/cert-${domain}.pem"
|
then "${cfg.certificateDirectory}/cert-${cfg.domain}.pem"
|
||||||
else "";
|
else "";
|
||||||
|
|
||||||
# key :: PATH
|
# key :: PATH
|
||||||
key = if certificateScheme == 1
|
key = if cfg.certificateScheme == 1
|
||||||
then keyFile
|
then cfg.keyFile
|
||||||
else if certificateScheme == 2
|
else if cfg.certificateScheme == 2
|
||||||
then "${certificateDirectory}/key-${domain}.pem"
|
then "${cfg.certificateDirectory}/key-${cfg.domain}.pem"
|
||||||
else "";
|
else "";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# rspamd
|
|
||||||
rspamd = {
|
|
||||||
enable = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
rmilter = import ./rmilter.nix {
|
imports = [
|
||||||
inherit domain virusScanning dkimSigning dkimSelector dkimKeyDirectory;
|
./rmilter.nix
|
||||||
};
|
./postfix.nix key
|
||||||
|
./dovecot.nix
|
||||||
postfix = import ./postfix.nix {
|
];
|
||||||
inherit lib mailDirectory domain virtualAliases cert key;
|
|
||||||
};
|
|
||||||
|
|
||||||
dovecot2 = import ./dovecot.nix {
|
|
||||||
inherit vmailGroupName vmailUserName mailDirectory enableImap
|
|
||||||
enablePop3 cert key;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue