2016-07-25 15:48:40 +00:00
|
|
|
# nixos-mailserver: a simple mail server
|
2017-08-12 09:27:19 +00:00
|
|
|
# Copyright (C) 2016-2017 Robin Raymond
|
2016-07-25 15:48:40 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
|
2017-09-03 09:13:34 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with (import ./common.nix { inherit config; });
|
2017-08-12 09:27:19 +00:00
|
|
|
|
2017-08-12 14:14:16 +00:00
|
|
|
let
|
2017-09-03 09:13:34 +00:00
|
|
|
cfg = config.mailserver;
|
|
|
|
|
2017-08-12 14:14:16 +00:00
|
|
|
# valiases_postfix :: [ String ]
|
2017-08-29 22:58:44 +00:00
|
|
|
valiases_postfix = map
|
|
|
|
(from:
|
2017-09-03 09:13:34 +00:00
|
|
|
let to = cfg.virtualAliases.${from};
|
|
|
|
in "${from}@${cfg.domain} ${to}@${cfg.domain}")
|
|
|
|
(builtins.attrNames cfg.virtualAliases);
|
2017-08-12 14:14:16 +00:00
|
|
|
|
|
|
|
# valiases_file :: Path
|
2017-08-29 22:58:44 +00:00
|
|
|
valiases_file = builtins.toFile "valias" (lib.concatStringsSep "\n" valiases_postfix);
|
2017-08-12 14:14:16 +00:00
|
|
|
|
|
|
|
# vhosts_file :: Path
|
2017-09-03 09:13:34 +00:00
|
|
|
vhosts_file = builtins.toFile "vhosts" cfg.domain;
|
2017-08-12 16:27:22 +00:00
|
|
|
|
2017-08-13 12:05:40 +00:00
|
|
|
# vaccounts_file :: Path
|
|
|
|
# see
|
|
|
|
# https://blog.grimneko.de/2011/12/24/a-bunch-of-tips-for-improving-your-postfix-setup/
|
|
|
|
# for details on how this file looks. By using the same file as valiases,
|
|
|
|
# every alias is owned (uniquely) by its user.
|
|
|
|
vaccounts_file = valiases_file;
|
|
|
|
|
2017-08-12 14:14:16 +00:00
|
|
|
in
|
2016-07-25 15:48:40 +00:00
|
|
|
{
|
2017-09-03 09:13:34 +00:00
|
|
|
config = with cfg; lib.mkIf enable {
|
2017-08-12 14:14:16 +00:00
|
|
|
|
2017-09-03 09:13:34 +00:00
|
|
|
services.postfix = {
|
|
|
|
enable = true;
|
|
|
|
networksStyle = "host";
|
|
|
|
mapFiles."valias" = valiases_file;
|
|
|
|
mapFiles."vaccounts" = vaccounts_file;
|
|
|
|
sslCert = certificatePath;
|
|
|
|
sslKey = keyPath;
|
|
|
|
enableSubmission = true;
|
2017-08-12 14:14:16 +00:00
|
|
|
|
2017-09-03 09:13:34 +00:00
|
|
|
extraConfig =
|
|
|
|
''
|
|
|
|
# Extra Config
|
2017-08-12 14:14:16 +00:00
|
|
|
|
2017-09-03 09:13:34 +00:00
|
|
|
smtpd_banner = $myhostname ESMTP NO UCE
|
|
|
|
smtpd_tls_auth_only = yes
|
|
|
|
disable_vrfy_command = yes
|
|
|
|
message_size_limit = 20971520
|
2017-08-12 14:14:16 +00:00
|
|
|
|
2017-09-03 09:13:34 +00:00
|
|
|
# virtual mail system
|
|
|
|
virtual_uid_maps = static:5000
|
|
|
|
virtual_gid_maps = static:5000
|
|
|
|
virtual_mailbox_base = ${mailDirectory}
|
|
|
|
virtual_mailbox_domains = ${vhosts_file}
|
|
|
|
virtual_alias_maps = hash:/var/lib/postfix/conf/valias
|
|
|
|
virtual_transport = lmtp:unix:private/dovecot-lmtp
|
2017-08-12 14:14:16 +00:00
|
|
|
|
2017-09-03 09:13:34 +00:00
|
|
|
# sasl with dovecot
|
|
|
|
smtpd_sasl_type = dovecot
|
|
|
|
smtpd_sasl_path = private/auth
|
|
|
|
smtpd_sasl_auth_enable = yes
|
|
|
|
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
|
|
|
|
'';
|
2017-08-12 14:14:16 +00:00
|
|
|
|
2017-09-03 09:13:34 +00:00
|
|
|
submissionOptions =
|
|
|
|
{
|
|
|
|
smtpd_tls_security_level = "encrypt";
|
|
|
|
smtpd_sasl_auth_enable = "yes";
|
|
|
|
smtpd_sasl_type = "dovecot";
|
|
|
|
smtpd_sasl_path = "private/auth";
|
|
|
|
smtpd_sasl_security_options = "noanonymous";
|
|
|
|
smtpd_sasl_local_domain = "$myhostname";
|
|
|
|
smtpd_client_restrictions = "permit_sasl_authenticated,reject";
|
|
|
|
smtpd_sender_login_maps = "hash:/etc/postfix/vaccounts";
|
|
|
|
smtpd_sender_restrictions = "reject_sender_login_mismatch";
|
|
|
|
smtpd_recipient_restrictions = "reject_non_fqdn_recipient,reject_unknown_recipient_domain,permit_sasl_authenticated,reject";
|
|
|
|
};
|
|
|
|
};
|
2017-08-13 12:05:40 +00:00
|
|
|
};
|
2016-07-25 15:48:40 +00:00
|
|
|
}
|