2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-03-06 12:27:07 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2009-03-06 12:27:07 +00:00
|
|
|
|
2008-06-30 15:13:02 +00:00
|
|
|
let
|
2009-10-12 16:36:19 +00:00
|
|
|
|
2008-06-30 15:13:02 +00:00
|
|
|
cfg = config.services.postfix;
|
|
|
|
user = cfg.user;
|
|
|
|
group = cfg.group;
|
|
|
|
setgidGroup = cfg.setgidGroup;
|
|
|
|
|
2016-01-09 12:48:36 +00:00
|
|
|
haveAliases = cfg.postmasterAlias != "" || cfg.rootAlias != "" || cfg.extraAliases != "";
|
|
|
|
haveTransport = cfg.transport != "";
|
|
|
|
haveVirtual = cfg.virtual != "";
|
|
|
|
|
2011-09-14 18:20:50 +00:00
|
|
|
mainCf =
|
2009-10-12 16:36:19 +00:00
|
|
|
''
|
2015-10-25 11:06:56 +00:00
|
|
|
compatibility_level = 2
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
mail_owner = ${user}
|
|
|
|
default_privs = nobody
|
|
|
|
|
2016-01-18 21:10:58 +00:00
|
|
|
# NixOS specific locations
|
|
|
|
data_directory = /var/lib/postfix/data
|
|
|
|
queue_directory = /var/lib/postfix/queue
|
|
|
|
|
|
|
|
# Default location of everything in package
|
|
|
|
meta_directory = ${pkgs.postfix}/etc/postfix
|
|
|
|
command_directory = ${pkgs.postfix}/bin
|
|
|
|
sample_directory = /etc/postfix
|
|
|
|
newaliases_path = ${pkgs.postfix}/bin/newaliases
|
|
|
|
mailq_path = ${pkgs.postfix}/bin/mailq
|
|
|
|
readme_directory = no
|
|
|
|
sendmail_path = ${pkgs.postfix}/bin/sendmail
|
|
|
|
daemon_directory = ${pkgs.postfix}/libexec/postfix
|
|
|
|
manpage_directory = ${pkgs.postfix}/share/man
|
|
|
|
html_directory = ${pkgs.postfix}/share/postfix/doc/html
|
|
|
|
shlib_directory = no
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
''
|
2012-03-11 11:12:02 +00:00
|
|
|
+ optionalString config.networking.enableIPv6 ''
|
|
|
|
inet_protocols = all
|
|
|
|
''
|
2009-10-12 16:36:19 +00:00
|
|
|
+ (if cfg.networks != null then
|
|
|
|
''
|
|
|
|
mynetworks = ${concatStringsSep ", " cfg.networks}
|
|
|
|
''
|
|
|
|
else if cfg.networksStyle != "" then
|
|
|
|
''
|
2011-09-14 18:20:50 +00:00
|
|
|
mynetworks_style = ${cfg.networksStyle}
|
2009-10-12 16:36:19 +00:00
|
|
|
''
|
|
|
|
else
|
2015-10-25 11:06:56 +00:00
|
|
|
"")
|
2009-10-12 16:36:19 +00:00
|
|
|
+ optionalString (cfg.hostname != "") ''
|
|
|
|
myhostname = ${cfg.hostname}
|
|
|
|
''
|
|
|
|
+ optionalString (cfg.domain != "") ''
|
|
|
|
mydomain = ${cfg.domain}
|
|
|
|
''
|
|
|
|
+ optionalString (cfg.origin != "") ''
|
|
|
|
myorigin = ${cfg.origin}
|
|
|
|
''
|
|
|
|
+ optionalString (cfg.destination != null) ''
|
|
|
|
mydestination = ${concatStringsSep ", " cfg.destination}
|
|
|
|
''
|
|
|
|
+ optionalString (cfg.relayDomains != null) ''
|
|
|
|
relay_domains = ${concatStringsSep ", " cfg.relayDomains}
|
|
|
|
''
|
|
|
|
+ ''
|
|
|
|
local_recipient_maps =
|
2011-09-14 18:20:50 +00:00
|
|
|
|
|
|
|
relayhost = ${if cfg.lookupMX || cfg.relayHost == "" then
|
|
|
|
cfg.relayHost
|
|
|
|
else
|
2009-10-12 16:36:19 +00:00
|
|
|
"[" + cfg.relayHost + "]"}
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
mail_spool_directory = /var/spool/mail/
|
|
|
|
|
|
|
|
setgid_group = ${setgidGroup}
|
|
|
|
''
|
|
|
|
+ optionalString (cfg.sslCert != "") ''
|
|
|
|
|
|
|
|
smtp_tls_CAfile = ${cfg.sslCACert}
|
|
|
|
smtp_tls_cert_file = ${cfg.sslCert}
|
|
|
|
smtp_tls_key_file = ${cfg.sslKey}
|
|
|
|
|
|
|
|
smtp_use_tls = yes
|
|
|
|
|
|
|
|
smtpd_tls_CAfile = ${cfg.sslCACert}
|
|
|
|
smtpd_tls_cert_file = ${cfg.sslCert}
|
|
|
|
smtpd_tls_key_file = ${cfg.sslKey}
|
|
|
|
|
2011-09-14 18:20:50 +00:00
|
|
|
smtpd_use_tls = yes
|
2015-09-23 01:03:25 +00:00
|
|
|
''
|
|
|
|
+ optionalString (cfg.recipientDelimiter != "") ''
|
2015-06-26 12:03:21 +00:00
|
|
|
recipient_delimiter = ${cfg.recipientDelimiter}
|
2011-01-02 18:49:11 +00:00
|
|
|
''
|
2016-01-09 12:48:36 +00:00
|
|
|
+ optionalString haveAliases ''
|
|
|
|
alias_maps = hash:/etc/postfix/aliases
|
2012-08-23 22:27:07 +00:00
|
|
|
''
|
2016-01-09 12:48:36 +00:00
|
|
|
+ optionalString haveTransport ''
|
2016-01-05 10:59:16 +00:00
|
|
|
transport_maps = hash:/etc/postfix/transport
|
2016-01-09 12:48:36 +00:00
|
|
|
''
|
|
|
|
+ optionalString haveVirtual ''
|
|
|
|
virtual_alias_maps = hash:/etc/postfix/virtual
|
2016-01-05 10:59:16 +00:00
|
|
|
''
|
2011-01-02 18:49:11 +00:00
|
|
|
+ cfg.extraConfig;
|
2008-06-30 15:13:02 +00:00
|
|
|
|
2012-09-23 10:21:34 +00:00
|
|
|
masterCf = ''
|
|
|
|
# ==========================================================================
|
|
|
|
# service type private unpriv chroot wakeup maxproc command + args
|
2015-10-25 11:06:56 +00:00
|
|
|
# (yes) (yes) (no) (never) (100)
|
2012-09-23 10:21:34 +00:00
|
|
|
# ==========================================================================
|
|
|
|
smtp inet n - n - - smtpd
|
|
|
|
#submission inet n - n - - smtpd
|
|
|
|
# -o smtpd_tls_security_level=encrypt
|
|
|
|
# -o smtpd_sasl_auth_enable=yes
|
|
|
|
# -o smtpd_client_restrictions=permit_sasl_authenticated,reject
|
|
|
|
# -o milter_macro_daemon_name=ORIGINATING
|
2014-11-23 22:41:29 +00:00
|
|
|
pickup unix n - n 60 1 pickup
|
2012-09-23 10:21:34 +00:00
|
|
|
cleanup unix n - n - 0 cleanup
|
2014-11-23 22:41:29 +00:00
|
|
|
qmgr unix n - n 300 1 qmgr
|
2012-09-23 10:21:34 +00:00
|
|
|
tlsmgr unix - - n 1000? 1 tlsmgr
|
|
|
|
rewrite unix - - n - - trivial-rewrite
|
|
|
|
bounce unix - - n - 0 bounce
|
|
|
|
defer unix - - n - 0 bounce
|
|
|
|
trace unix - - n - 0 bounce
|
|
|
|
verify unix - - n - 1 verify
|
|
|
|
flush unix n - n 1000? 0 flush
|
|
|
|
proxymap unix - - n - - proxymap
|
|
|
|
proxywrite unix - - n - 1 proxymap
|
2016-01-05 10:57:52 +00:00
|
|
|
''
|
|
|
|
+ optionalString cfg.enableSmtp ''
|
2012-09-23 10:21:34 +00:00
|
|
|
smtp unix - - n - - smtp
|
|
|
|
relay unix - - n - - smtp
|
|
|
|
-o smtp_fallback_relay=
|
|
|
|
# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
|
2016-01-05 10:57:52 +00:00
|
|
|
''
|
|
|
|
+ ''
|
2012-09-23 10:21:34 +00:00
|
|
|
showq unix n - n - - showq
|
|
|
|
error unix - - n - - error
|
|
|
|
retry unix - - n - - error
|
|
|
|
discard unix - - n - - discard
|
|
|
|
local unix - n n - - local
|
|
|
|
virtual unix - n n - - virtual
|
|
|
|
lmtp unix - - n - - lmtp
|
|
|
|
anvil unix - - n - 1 anvil
|
|
|
|
scache unix - - n - 1 scache
|
|
|
|
${cfg.extraMasterConf}
|
|
|
|
'';
|
|
|
|
|
2011-09-14 18:20:50 +00:00
|
|
|
aliases =
|
2009-10-12 16:36:19 +00:00
|
|
|
optionalString (cfg.postmasterAlias != "") ''
|
2008-06-30 15:13:02 +00:00
|
|
|
postmaster: ${cfg.postmasterAlias}
|
2009-10-12 16:36:19 +00:00
|
|
|
''
|
|
|
|
+ optionalString (cfg.rootAlias != "") ''
|
2008-06-30 15:13:02 +00:00
|
|
|
root: ${cfg.rootAlias}
|
2009-10-12 16:36:19 +00:00
|
|
|
''
|
2008-06-30 15:13:02 +00:00
|
|
|
+ cfg.extraAliases
|
|
|
|
;
|
|
|
|
|
|
|
|
aliasesFile = pkgs.writeText "postfix-aliases" aliases;
|
2012-08-23 22:27:07 +00:00
|
|
|
virtualFile = pkgs.writeText "postfix-virtual" cfg.virtual;
|
2008-06-30 15:13:02 +00:00
|
|
|
mainCfFile = pkgs.writeText "postfix-main.cf" mainCf;
|
2012-09-23 10:21:34 +00:00
|
|
|
masterCfFile = pkgs.writeText "postfix-master.cf" masterCf;
|
2016-01-05 10:59:16 +00:00
|
|
|
transportFile = pkgs.writeText "postfix-transport" cfg.transport;
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2008-06-30 15:13:02 +00:00
|
|
|
in
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
services.postfix = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
enable = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.bool;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = false;
|
|
|
|
description = "Whether to run the Postfix mail server.";
|
|
|
|
};
|
2010-10-10 10:43:28 +00:00
|
|
|
|
2016-01-05 10:57:52 +00:00
|
|
|
enableSmtp = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = "Whether to enable smtp in master.cf.";
|
|
|
|
};
|
|
|
|
|
2010-10-10 10:43:28 +00:00
|
|
|
setSendmail = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.bool;
|
2010-10-10 10:43:28 +00:00
|
|
|
default = true;
|
|
|
|
description = "Whether to set the system sendmail to postfix's.";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
user = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "postfix";
|
|
|
|
description = "What to call the Postfix user (must be used only for postfix).";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
group = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "postfix";
|
|
|
|
description = "What to call the Postfix group (must be used only for postfix).";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
setgidGroup = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "postdrop";
|
|
|
|
description = "
|
2011-09-14 18:20:50 +00:00
|
|
|
How to call postfix setgid group (for postdrop). Should
|
2009-10-12 16:36:19 +00:00
|
|
|
be uniquely used group.
|
|
|
|
";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
networks = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.nullOr (types.listOf types.str);
|
2009-10-12 16:36:19 +00:00
|
|
|
default = null;
|
|
|
|
example = ["192.168.0.1/24"];
|
|
|
|
description = "
|
2011-09-14 18:20:50 +00:00
|
|
|
Net masks for trusted - allowed to relay mail to third parties -
|
|
|
|
hosts. Leave empty to use mynetworks_style configuration or use
|
2009-10-12 16:36:19 +00:00
|
|
|
default (localhost-only).
|
|
|
|
";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
networksStyle = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "";
|
|
|
|
description = "
|
|
|
|
Name of standard way of trusted network specification to use,
|
2011-09-14 18:20:50 +00:00
|
|
|
leave blank if you specify it explicitly or if you want to use
|
2009-10-12 16:36:19 +00:00
|
|
|
default (localhost-only).
|
|
|
|
";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
hostname = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "";
|
|
|
|
description ="
|
|
|
|
Hostname to use. Leave blank to use just the hostname of machine.
|
|
|
|
It should be FQDN.
|
|
|
|
";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
domain = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "";
|
|
|
|
description ="
|
|
|
|
Domain to use. Leave blank to use hostname minus first component.
|
|
|
|
";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
origin = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "";
|
|
|
|
description ="
|
|
|
|
Origin to use in outgoing e-mail. Leave blank to use hostname.
|
|
|
|
";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
destination = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.nullOr (types.listOf types.str);
|
2009-10-12 16:36:19 +00:00
|
|
|
default = null;
|
|
|
|
example = ["localhost"];
|
|
|
|
description = "
|
2011-09-14 18:20:50 +00:00
|
|
|
Full (!) list of domains we deliver locally. Leave blank for
|
2009-10-12 16:36:19 +00:00
|
|
|
acceptable Postfix default.
|
|
|
|
";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
relayDomains = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.nullOr (types.listOf types.str);
|
2009-10-12 16:36:19 +00:00
|
|
|
default = null;
|
|
|
|
example = ["localdomain"];
|
|
|
|
description = "
|
2015-10-25 11:06:56 +00:00
|
|
|
List of domains we agree to relay to. Default is empty.
|
2009-10-12 16:36:19 +00:00
|
|
|
";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
relayHost = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "";
|
|
|
|
description = "
|
|
|
|
Mail relay for outbound mail.
|
|
|
|
";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
lookupMX = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.bool;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
Whether relay specified is just domain whose MX must be used.
|
|
|
|
";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
postmasterAlias = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "root";
|
|
|
|
description = "Who should receive postmaster e-mail.";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
rootAlias = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "";
|
|
|
|
description = "
|
|
|
|
Who should receive root e-mail. Blank for no redirection.
|
|
|
|
";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
extraAliases = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.lines;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "";
|
|
|
|
description = "
|
2015-05-06 19:51:01 +00:00
|
|
|
Additional entries to put verbatim into aliases file, cf. man-page aliases(8).
|
2009-10-12 16:36:19 +00:00
|
|
|
";
|
|
|
|
};
|
|
|
|
|
2011-01-02 18:49:11 +00:00
|
|
|
extraConfig = mkOption {
|
2016-01-15 16:53:42 +00:00
|
|
|
type = types.lines;
|
2011-01-02 18:49:11 +00:00
|
|
|
default = "";
|
|
|
|
description = "
|
2012-09-23 10:21:34 +00:00
|
|
|
Extra lines to be added verbatim to the main.cf configuration file.
|
2011-01-02 18:49:11 +00:00
|
|
|
";
|
|
|
|
};
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
sslCert = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "";
|
|
|
|
description = "SSL certificate to use.";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
sslCACert = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "";
|
|
|
|
description = "SSL certificate of CA.";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
sslKey = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "";
|
|
|
|
description = "SSL key to use.";
|
|
|
|
};
|
|
|
|
|
2015-06-26 12:03:21 +00:00
|
|
|
recipientDelimiter = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.str;
|
2015-06-26 12:03:21 +00:00
|
|
|
default = "";
|
|
|
|
example = "+";
|
|
|
|
description = "
|
|
|
|
Delimiter for address extension: so mail to user+test can be handled by ~user/.forward+test
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
2012-08-23 22:27:07 +00:00
|
|
|
virtual = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.lines;
|
2012-08-23 22:27:07 +00:00
|
|
|
default = "";
|
|
|
|
description = "
|
2015-05-06 19:51:01 +00:00
|
|
|
Entries for the virtual alias map, cf. man-page virtual(8).
|
2012-08-23 22:27:07 +00:00
|
|
|
";
|
|
|
|
};
|
|
|
|
|
2016-01-05 10:59:16 +00:00
|
|
|
transport = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "
|
|
|
|
Entries for the transport map, cf. man-page transport(8).
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
2012-09-23 10:21:34 +00:00
|
|
|
extraMasterConf = mkOption {
|
2015-11-02 01:13:17 +00:00
|
|
|
type = types.lines;
|
2012-09-23 10:21:34 +00:00
|
|
|
default = "";
|
|
|
|
example = "submission inet n - n - - smtpd";
|
|
|
|
description = "Extra lines to append to the generated master.cf file.";
|
|
|
|
};
|
|
|
|
|
2016-01-10 02:39:17 +00:00
|
|
|
aliasFiles = mkOption {
|
|
|
|
type = types.attrsOf types.path;
|
|
|
|
default = {};
|
|
|
|
description = "Aliases' tables to be compiled and placed into /var/lib/postfix/conf.";
|
|
|
|
};
|
|
|
|
|
|
|
|
mapFiles = mkOption {
|
|
|
|
type = types.attrsOf types.path;
|
|
|
|
default = {};
|
|
|
|
description = "Maps to be compiled and placed into /var/lib/postfix/conf.";
|
|
|
|
};
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
2008-06-30 15:13:02 +00:00
|
|
|
|
2009-03-06 12:27:07 +00:00
|
|
|
};
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2016-01-10 02:39:17 +00:00
|
|
|
config = mkIf config.services.postfix.enable (mkMerge [
|
|
|
|
{
|
2009-10-12 16:36:19 +00:00
|
|
|
|
2016-01-10 02:39:17 +00:00
|
|
|
environment = {
|
|
|
|
etc = singleton
|
|
|
|
{ source = "/var/lib/postfix/conf";
|
|
|
|
target = "postfix";
|
|
|
|
};
|
2010-10-10 10:43:28 +00:00
|
|
|
|
2016-01-10 02:39:17 +00:00
|
|
|
# This makes comfortable for root to run 'postqueue' for example.
|
|
|
|
systemPackages = [ pkgs.postfix ];
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
2009-03-06 12:27:07 +00:00
|
|
|
|
2016-01-10 02:39:17 +00:00
|
|
|
services.mail.sendmailSetuidWrapper = mkIf config.services.postfix.setSendmail {
|
|
|
|
program = "sendmail";
|
|
|
|
source = "${pkgs.postfix}/bin/sendmail";
|
|
|
|
group = setgidGroup;
|
|
|
|
setuid = false;
|
|
|
|
setgid = true;
|
2016-01-09 00:36:39 +00:00
|
|
|
};
|
2009-03-06 12:27:07 +00:00
|
|
|
|
2016-01-10 02:39:17 +00:00
|
|
|
users.extraUsers = optional (user == "postfix")
|
|
|
|
{ name = "postfix";
|
|
|
|
description = "Postfix mail server user";
|
|
|
|
uid = config.ids.uids.postfix;
|
|
|
|
group = group;
|
2015-10-25 11:06:56 +00:00
|
|
|
};
|
2010-06-11 21:44:06 +00:00
|
|
|
|
2016-01-10 02:39:17 +00:00
|
|
|
users.extraGroups =
|
|
|
|
optional (group == "postfix")
|
|
|
|
{ name = group;
|
|
|
|
gid = config.ids.gids.postfix;
|
|
|
|
}
|
|
|
|
++ optional (setgidGroup == "postdrop")
|
|
|
|
{ name = setgidGroup;
|
|
|
|
gid = config.ids.gids.postdrop;
|
|
|
|
};
|
2009-03-06 12:27:07 +00:00
|
|
|
|
2016-01-10 02:39:17 +00:00
|
|
|
systemd.services.postfix =
|
|
|
|
{ description = "Postfix mail server";
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
path = [ pkgs.postfix ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
|
|
|
Restart = "always";
|
|
|
|
PIDFile = "/var/lib/postfix/queue/pid/master.pid";
|
|
|
|
ExecStart = "${pkgs.postfix}/bin/postfix start";
|
|
|
|
ExecStop = "${pkgs.postfix}/bin/postfix stop";
|
|
|
|
ExecReload = "${pkgs.postfix}/bin/postfix reload";
|
|
|
|
};
|
|
|
|
|
|
|
|
preStart = ''
|
2016-01-10 12:33:23 +00:00
|
|
|
# Backwards compatibility
|
|
|
|
if [ ! -d /var/lib/postfix ] && [ -d /var/postfix ]; then
|
|
|
|
mkdir -p /var/lib
|
|
|
|
mv /var/postfix /var/lib/postfix
|
|
|
|
fi
|
2016-01-10 02:39:17 +00:00
|
|
|
|
2016-01-18 21:10:58 +00:00
|
|
|
# All permissions set according ${pkgs.postfix}/etc/postfix/postfix-files script
|
|
|
|
mkdir -p /var/lib/postfix /var/lib/postfix/queue/{pid,public,maildrop}
|
|
|
|
chmod 0755 /var/lib/postfix
|
|
|
|
chown root:root /var/lib/postfix
|
2016-01-10 02:39:17 +00:00
|
|
|
|
|
|
|
rm -rf /var/lib/postfix/conf
|
|
|
|
mkdir -p /var/lib/postfix/conf
|
2016-01-18 21:10:58 +00:00
|
|
|
chmod 0755 /var/lib/postfix/conf
|
|
|
|
ln -sf ${pkgs.postfix}/etc/postfix/postfix-files
|
2016-01-10 02:39:17 +00:00
|
|
|
ln -sf ${mainCfFile} /var/lib/postfix/conf/main.cf
|
|
|
|
ln -sf ${masterCfFile} /var/lib/postfix/conf/master.cf
|
2016-01-18 21:10:58 +00:00
|
|
|
|
2016-01-10 02:39:17 +00:00
|
|
|
${concatStringsSep "\n" (mapAttrsToList (to: from: ''
|
|
|
|
ln -sf ${from} /var/lib/postfix/conf/${to}
|
2016-01-18 21:10:58 +00:00
|
|
|
${pkgs.postfix}/bin/postalias /var/lib/postfix/conf/${to}
|
2016-01-10 02:39:17 +00:00
|
|
|
'') cfg.aliasFiles)}
|
|
|
|
${concatStringsSep "\n" (mapAttrsToList (to: from: ''
|
|
|
|
ln -sf ${from} /var/lib/postfix/conf/${to}
|
2016-01-18 21:10:58 +00:00
|
|
|
${pkgs.postfix}/bin/postmap /var/lib/postfix/conf/${to}
|
2016-01-10 02:39:17 +00:00
|
|
|
'') cfg.mapFiles)}
|
|
|
|
|
|
|
|
mkdir -p /var/spool/mail
|
|
|
|
chown root:root /var/spool/mail
|
|
|
|
chmod a+rwxt /var/spool/mail
|
|
|
|
ln -sf /var/spool/mail /var/
|
2016-01-18 21:10:58 +00:00
|
|
|
|
|
|
|
#Finally delegate to postfix checking remain directories in /var/lib/postfix and set permissions on them
|
|
|
|
${pkgs.postfix}/bin/postfix set-permissions config_directory=/var/lib/postfix/conf
|
2016-01-10 02:39:17 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
(mkIf haveAliases {
|
|
|
|
services.postfix.aliasFiles."aliases" = aliasesFile;
|
|
|
|
})
|
|
|
|
(mkIf haveTransport {
|
|
|
|
services.postfix.mapFiles."transport" = transportFile;
|
|
|
|
})
|
|
|
|
(mkIf haveVirtual {
|
|
|
|
services.postfix.mapFiles."virtual" = virtualFile;
|
|
|
|
})
|
|
|
|
]);
|
2009-10-12 16:36:19 +00:00
|
|
|
|
2008-06-30 15:13:02 +00:00
|
|
|
}
|