diff --git a/nixos/modules/services/mail/nullmailer.nix b/nixos/modules/services/mail/nullmailer.nix index b2c738ab6eb..59cb512c115 100644 --- a/nixos/modules/services/mail/nullmailer.nix +++ b/nixos/modules/services/mail/nullmailer.nix @@ -35,6 +35,18 @@ with lib; description = "Whether to set the system sendmail to nullmailer's."; }; + remotesFile = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + Path to the remotes control file. This file contains a + list of remote servers to which to send each message. + + See man 8 nullmailer-send for syntax and available + options. + ''; + }; + config = { adminaddr = mkOption { type = types.nullOr types.str; @@ -142,7 +154,16 @@ with lib; type = types.nullOr types.str; default = null; description = '' - If set, content will override the envelope sender on all messages. + A list of remote servers to which to send each message. Each line + contains a remote host name or address followed by an optional + protocol string, separated by white space. + + See man 8 nullmailer-send for syntax and available + options. + + WARNING: This is stored world-readable in the nix store. If you need + to specify any secret credentials here, consider using the + remotesFile option instead. ''; }; @@ -164,13 +185,19 @@ with lib; cfg = config.services.nullmailer; in mkIf cfg.enable { + assertions = [ + { assertion = cfg.config.remotes == null || cfg.remotesFile == null; + message = "Only one of `remotesFile` or `config.remotes` may be used at a time."; + } + ]; + environment = { systemPackages = [ pkgs.nullmailer ]; etc = let - getval = attr: builtins.getAttr attr cfg.config; - attrs = builtins.attrNames cfg.config; - attrs' = builtins.filter (attr: ! isNull (getval attr)) attrs; - in foldl' (as: attr: as // { "nullmailer/${attr}".text = getval attr; }) {} attrs'; + validAttrs = filterAttrs (name: value: value != null) cfg.config; + in + (foldl' (as: name: as // { "nullmailer/${name}".text = validAttrs.${name}; }) {} (attrNames validAttrs)) + // optionalAttrs (cfg.remotesFile != null) { "nullmailer/remotes".source = cfg.remotesFile; }; }; users = { @@ -192,7 +219,7 @@ with lib; preStart = '' mkdir -p /var/spool/nullmailer/{queue,tmp} - rm -f var/spool/nullmailer/trigger && mkfifo -m 660 /var/spool/nullmailer/trigger + rm -f /var/spool/nullmailer/trigger && mkfifo -m 660 /var/spool/nullmailer/trigger chown ${cfg.user} /var/spool/nullmailer/* '';