[Solved] Overwrite default values in configuration.nix / Postfix + postscreen?

I’m trying to setup postscreen in Postfix. Since there are no Nix options for this, I have to modify the Postfix-master.cf.

How can I do this?
I’ve tried several ways, but none worked:

  1. services.postfix.masterConfig. = … can only (a) add entries or (b) add parameters to existing entries. If I try to overwrite an already existing parameter in an entry, I get the error:

    error: The unique option services.postfix.masterConfig.smtp_inet.command' is defined multiple times, in /etc/nixos/configuration.nix’ and `/nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/services/mail/postfix.nix’.

    So, how can I overwrite/modify this entry? Or remove the original entry?
    (In detail, I would like to:
    masterConfig.smtp_inet = { maxproc=1; chroot=false; command="postscreen"; };

  2. Setting service.postfix.masterConfig also only adds values, but cannot replace the default ones.
    (And adding an additional smtp-postscreen-entry does not work.)

  3. services.extraMasterConfig also can only add entries, but not modify others.

  4. Using a custom master.cf: Seems impossible.

So, is there any way? Or would I have to fix the Postfix package??

You can use lib.mkForce to replace the value or even lib.mkBefore/lib.mkAfter to insert entries before/after the existing definition(s).

Ok, thanks :). I’ve now achieved it with:

masterConfig.smtp_inet = pkgs.lib.mkOverride 10 { ... };

Is there any documentation that tells me that I have to prepend “pkgs.”?
(Because otherwise, I only get “undefined variable”-errors.)

You don’t have to prepend pkgs., however I don’t know your configuration so I can only guess that lib is missing in your module arguments, so you need to add it like so:

{ lib, pkgs, ... }:

{
  # ...
  services.postfix.masterConfig.smtp_inet = lib.mkOverride 10 { ... };
}

Btw. using pkgs.lib is also something I’d avoid, because it can easily lead to infinite recursions, consider this:

{ pkgs, ... }:

{
  imports = pkgs.lib.singleton /some/file.nix;
}

This will lead to an infinite recursion error, because the pkgs module argument actually is a configuration option itself (_module.args.pkgs) which can only be resolved once all modules are determined. In this case it can’t do so because importing the /some/file.nix module would depend on that option (which could even be redefined in /some/file.nix).

1 Like

Ok, thanks, then I’ll replace the default { config, pkgs, ... }: by { config, pkgs, lib, ... }: at the top of /etc/nixos/configuration.nix. NixOS unfortunately does not include this by default.

sorry for kicking an old topic, but it is still a bit of a hassle to setup postscreen. This is where a NixOs option would really be advantageous.

There is this abandoned PR nixos/postfix: Add the option to use the postscreen daemon in front of smtpd by shirenn · Pull Request #170899 · NixOS/nixpkgs · GitHub that should make it easy.
What is holding us back from reviving/merging it?