Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/mailman: make Postfix support optional (provided you configure the MTA yourself) #105397

Merged
merged 1 commit into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions nixos/doc/manual/release-notes/rl-2103.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@
<title>Other Notable Changes</title>

<itemizedlist>
<listitem>
<para>
The Mailman NixOS module (<literal>services.mailman</literal>) has a new
option <xref linkend="opt-services.mailman.enablePostfix" />, defaulting
to true, that controls integration with Postfix.
</para>
<para>
If this option is disabled, default MTA config becomes not set and you
should set the options in <literal>services.mailman.settings.mta</literal>
according to the desired configuration as described in
<link xlink:href="https://mailman.readthedocs.io/en/latest/src/mailman/docs/mta.html">Mailman documentation</link>.
</para>
</listitem>
<listitem>
<para>
The default-version of <literal>nextcloud</literal> is <package>nextcloud20</package>.
Expand Down
36 changes: 29 additions & 7 deletions nixos/modules/services/mail/mailman.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let
webSettingsJSON = pkgs.writeText "settings.json" (builtins.toJSON webSettings);

# TODO: Should this be RFC42-ised so that users can set additional options without modifying the module?
mtaConfig = pkgs.writeText "mailman-postfix.cfg" ''
postfixMtaConfig = pkgs.writeText "mailman-postfix.cfg" ''
[postfix]
postmap_command: ${pkgs.postfix}/bin/postmap
transport_file_type: hash
Expand Down Expand Up @@ -81,7 +81,7 @@ in {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable Mailman on this host. Requires an active Postfix installation.";
description = "Enable Mailman on this host. Requires an active MTA on the host (e.g. Postfix).";
};

package = mkOption {
Expand All @@ -92,6 +92,20 @@ in {
description = "Mailman package to use";
};

enablePostfix = mkOption {
type = types.bool;
default = true;
example = false;
description = ''
Enable Postfix integration. Requires an active Postfix installation.

If you want to use another MTA, set this option to false and configure
settings in services.mailman.settings.mta.

Refer to the Mailman manual for more info.
'';
};

siteOwner = mkOption {
type = types.str;
example = "postmaster@example.org";
Expand Down Expand Up @@ -182,7 +196,7 @@ in {
pid_file = "/run/mailman/master.pid";
};

mta.configuration = lib.mkDefault "${mtaConfig}";
mta.configuration = lib.mkDefault (if cfg.enablePostfix then "${postfixMtaConfig}" else throw "When Mailman Postfix integration is disabled, set `services.mailman.settings.mta.configuration` to the path of the config file required to integrate with your MTA.");

"archiver.hyperkitty" = lib.mkIf cfg.hyperkitty.enable {
class = "mailman_hyperkitty.Archiver";
Expand Down Expand Up @@ -211,14 +225,22 @@ in {
See <https://mailman.readthedocs.io/en/latest/src/mailman/docs/mta.html>.
'';
};
in [
in (lib.optionals cfg.enablePostfix [
{ assertion = postfix.enable;
message = "Mailman requires Postfix";
message = ''
Mailman's default NixOS configuration requires Postfix to be enabled.

If you want to use another MTA, set services.mailman.enablePostfix
to false and configure settings in services.mailman.settings.mta.

Refer to <https://mailman.readthedocs.io/en/latest/src/mailman/docs/mta.html>
for more info.
'';
}
(requirePostfixHash [ "relayDomains" ] "postfix_domains")
(requirePostfixHash [ "config" "transport_maps" ] "postfix_lmtp")
(requirePostfixHash [ "config" "local_recipient_maps" ] "postfix_lmtp")
];
]);

users.users.mailman = {
description = "GNU Mailman";
Expand Down Expand Up @@ -275,7 +297,7 @@ in {
'';
}) ];

services.postfix = {
services.postfix = lib.mkIf cfg.enablePostfix {
recipientDelimiter = "+"; # bake recipient addresses in mail envelopes via VERP
config = {
owner_request_special = "no"; # Mailman handles -owner addresses on its own
Expand Down
39 changes: 37 additions & 2 deletions nixos/modules/services/mail/mailman.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
</para>

<section xml:id="module-services-mailman-basic-usage">
<title>Basic usage</title>
<title>Basic usage with Postfix</title>
<para>
For a basic configuration, the following settings are suggested:
For a basic configuration with Postfix as the MTA, the following settings are suggested:
<programlisting>{ config, ... }: {
services.postfix = {
enable = true;
Expand Down Expand Up @@ -56,4 +56,39 @@
necessary, but outside the scope of the Mailman module.
</para>
</section>
<section xml:id="module-services-mailman-other-mtas">
<title>Using with other MTAs</title>
<para>
Mailman also supports other MTA, though with a little bit more configuration. For example, to use Mailman with Exim, you can use the following settings:
<programlisting>{ config, ... }: {
services = {
mailman = {
enable = true;
siteOwner = "mailman@example.org";
<link linkend="opt-services.mailman.enablePostfix">enablePostfix</link> = false;
settings.mta = {
incoming = "mailman.mta.exim4.LMTP";
outgoing = "mailman.mta.deliver.deliver";
lmtp_host = "localhost";
lmtp_port = "8024";
smtp_host = "localhost";
smtp_port = "25";
configuration = "python:mailman.config.exim4";
};
};
exim = {
enable = true;
# You can configure Exim in a separate file to reduce configuration.nix clutter
config = builtins.readFile ./exim.conf;
};
};
}</programlisting>
</para>
<para>
The exim config needs some special additions to work with Mailman. Currently
NixOS can't manage Exim config with such granularity. Please refer to
<link xlink:href="https://mailman.readthedocs.io/en/latest/src/mailman/docs/mta.html">Mailman documentation</link>
for more info on configuring Mailman for working with Exim.
</para>
</section>
</chapter>