nixos/postfix: add options to compile additional maps and aliases
This commit is contained in:
parent
9c502abb1c
commit
1edb62b40a
@ -356,6 +356,18 @@ in
|
|||||||
description = "Extra lines to append to the generated master.cf file.";
|
description = "Extra lines to append to the generated master.cf file.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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.";
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -363,92 +375,99 @@ in
|
|||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkIf config.services.postfix.enable {
|
config = mkIf config.services.postfix.enable (mkMerge [
|
||||||
|
{
|
||||||
|
|
||||||
environment = {
|
environment = {
|
||||||
etc = singleton
|
etc = singleton
|
||||||
{ source = "/var/lib/postfix/conf";
|
{ source = "/var/lib/postfix/conf";
|
||||||
target = "postfix";
|
target = "postfix";
|
||||||
|
};
|
||||||
|
|
||||||
|
# This makes comfortable for root to run 'postqueue' for example.
|
||||||
|
systemPackages = [ pkgs.postfix ];
|
||||||
|
};
|
||||||
|
|
||||||
|
services.mail.sendmailSetuidWrapper = mkIf config.services.postfix.setSendmail {
|
||||||
|
program = "sendmail";
|
||||||
|
source = "${pkgs.postfix}/bin/sendmail";
|
||||||
|
group = setgidGroup;
|
||||||
|
setuid = false;
|
||||||
|
setgid = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
users.extraUsers = optional (user == "postfix")
|
||||||
|
{ name = "postfix";
|
||||||
|
description = "Postfix mail server user";
|
||||||
|
uid = config.ids.uids.postfix;
|
||||||
|
group = group;
|
||||||
};
|
};
|
||||||
|
|
||||||
# This makes comfortable for root to run 'postqueue' for example.
|
users.extraGroups =
|
||||||
systemPackages = [ pkgs.postfix ];
|
optional (group == "postfix")
|
||||||
};
|
{ name = group;
|
||||||
|
gid = config.ids.gids.postfix;
|
||||||
services.mail.sendmailSetuidWrapper = mkIf config.services.postfix.setSendmail {
|
}
|
||||||
program = "sendmail";
|
++ optional (setgidGroup == "postdrop")
|
||||||
source = "${pkgs.postfix}/bin/sendmail";
|
{ name = setgidGroup;
|
||||||
group = setgidGroup;
|
gid = config.ids.gids.postdrop;
|
||||||
setuid = false;
|
|
||||||
setgid = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
users.extraUsers = optional (user == "postfix")
|
|
||||||
{ name = "postfix";
|
|
||||||
description = "Postfix mail server user";
|
|
||||||
uid = config.ids.uids.postfix;
|
|
||||||
group = group;
|
|
||||||
};
|
|
||||||
|
|
||||||
users.extraGroups =
|
|
||||||
optional (group == "postfix")
|
|
||||||
{ name = group;
|
|
||||||
gid = config.ids.gids.postfix;
|
|
||||||
}
|
|
||||||
++ optional (setgidGroup == "postdrop")
|
|
||||||
{ name = setgidGroup;
|
|
||||||
gid = config.ids.gids.postdrop;
|
|
||||||
};
|
|
||||||
|
|
||||||
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 -c /etc/postfix start";
|
|
||||||
ExecStop = "${pkgs.postfix}/bin/postfix -c /etc/postfix stop";
|
|
||||||
ExecReload = "${pkgs.postfix}/bin/postfix -c /etc/postfix reload";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
preStart = ''
|
systemd.services.postfix =
|
||||||
mkdir -p /var/lib/postfix/data /var/lib/postfix/queue/{pid,public,maildrop}
|
{ description = "Postfix mail server";
|
||||||
|
|
||||||
chown -R ${user}:${group} /var/lib/postfix
|
wantedBy = [ "multi-user.target" ];
|
||||||
chown root /var/lib/postfix/queue
|
after = [ "network.target" ];
|
||||||
chown root /var/lib/postfix/queue/pid
|
path = [ pkgs.postfix ];
|
||||||
chgrp -R ${setgidGroup} /var/lib/postfix/queue/{public,maildrop}
|
|
||||||
chmod 770 /var/lib/postfix/queue/{public,maildrop}
|
|
||||||
|
|
||||||
rm -rf /var/lib/postfix/conf
|
serviceConfig = {
|
||||||
mkdir -p /var/lib/postfix/conf
|
Type = "forking";
|
||||||
ln -sf ${mainCfFile} /var/lib/postfix/conf/main.cf
|
Restart = "always";
|
||||||
ln -sf ${masterCfFile} /var/lib/postfix/conf/master.cf
|
PIDFile = "/var/lib/postfix/queue/pid/master.pid";
|
||||||
${optionalString haveAliases ''
|
ExecStart = "${pkgs.postfix}/bin/postfix start";
|
||||||
ln -sf ${aliasesFile} /var/lib/postfix/conf/aliases
|
ExecStop = "${pkgs.postfix}/bin/postfix stop";
|
||||||
postalias /var/lib/postfix/conf/aliases
|
ExecReload = "${pkgs.postfix}/bin/postfix reload";
|
||||||
''}
|
};
|
||||||
${optionalString haveTransport ''
|
|
||||||
${pkgs.coreutils}/bin/ln -sf ${transportFile} /var/lib/postfix/conf/transport
|
|
||||||
${pkgs.postfix}/bin/postmap /var/lib/postfix/conf/transport
|
|
||||||
''}
|
|
||||||
${optionalString haveVirtual ''
|
|
||||||
ln -sf ${virtualFile} /var/lib/postfix/conf/virtual
|
|
||||||
postmap /var/lib/postfix/conf/virtual
|
|
||||||
''}
|
|
||||||
|
|
||||||
mkdir -p /var/spool/mail
|
preStart = ''
|
||||||
chown root:root /var/spool/mail
|
mkdir -p /var/lib/postfix/data /var/lib/postfix/queue/{pid,public,maildrop}
|
||||||
chmod a+rwxt /var/spool/mail
|
|
||||||
ln -sf /var/spool/mail /var/
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
chown -R ${user}:${group} /var/lib/postfix
|
||||||
|
chown root /var/lib/postfix/queue
|
||||||
|
chown root /var/lib/postfix/queue/pid
|
||||||
|
chgrp -R ${setgidGroup} /var/lib/postfix/queue/{public,maildrop}
|
||||||
|
chmod 770 /var/lib/postfix/queue/{public,maildrop}
|
||||||
|
|
||||||
|
rm -rf /var/lib/postfix/conf
|
||||||
|
mkdir -p /var/lib/postfix/conf
|
||||||
|
ln -sf ${mainCfFile} /var/lib/postfix/conf/main.cf
|
||||||
|
ln -sf ${masterCfFile} /var/lib/postfix/conf/master.cf
|
||||||
|
${concatStringsSep "\n" (mapAttrsToList (to: from: ''
|
||||||
|
ln -sf ${from} /var/lib/postfix/conf/${to}
|
||||||
|
postalias /var/lib/postfix/conf/${to}
|
||||||
|
'') cfg.aliasFiles)}
|
||||||
|
${concatStringsSep "\n" (mapAttrsToList (to: from: ''
|
||||||
|
ln -sf ${from} /var/lib/postfix/conf/${to}
|
||||||
|
postmap /var/lib/postfix/conf/${to}
|
||||||
|
'') 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/
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
(mkIf haveAliases {
|
||||||
|
services.postfix.aliasFiles."aliases" = aliasesFile;
|
||||||
|
})
|
||||||
|
(mkIf haveTransport {
|
||||||
|
services.postfix.mapFiles."transport" = transportFile;
|
||||||
|
})
|
||||||
|
(mkIf haveVirtual {
|
||||||
|
services.postfix.mapFiles."virtual" = virtualFile;
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user