What is the idiomatic way to get PostgreSQL support in Postfix?

The Postfix nixpkg does not enable PostgreSQL support by default there are no module options to enable it. The nixpkg start with the following code:

{ stdenv, lib, fetchurl, makeWrapper, gnused, db, openssl, cyrus_sasl, libnsl
, coreutils, findutils, gnugrep, gawk, icu, pcre2, m4
, fetchpatch
, buildPackages, nixosTests
, withLDAP ? true, openldap
, withPgSQL ? false, postgresql
, withMySQL ? false, libmysqlclient
, withSQLite ? false, sqlite
}:

let
  ccargs = lib.concatStringsSep " " ([
    "-DUSE_TLS" "-DUSE_SASL_AUTH" "-DUSE_CYRUS_SASL" "-I${cyrus_sasl.dev}/include/sasl"
    "-DHAS_DB_BYPASS_MAKEDEFS_CHECK"
   ] ++ lib.optional withPgSQL "-DHAS_PGSQL"
     ++ lib.optionals withMySQL [ "-DHAS_MYSQL" "-I${libmysqlclient.dev}/include/mysql" "-L${libmysqlclient}/lib/mysql" ]
     ++ lib.optional withSQLite "-DHAS_SQLITE"
     ++ lib.optionals withLDAP ["-DHAS_LDAP" "-DUSE_LDAP_SASL"]);
   auxlibs = lib.concatStringsSep " " ([
     "-ldb" "-lnsl" "-lresolv" "-lsasl2" "-lcrypto" "-lssl"
   ] ++ lib.optional withPgSQL "-lpq"
     ++ lib.optional withMySQL "-lmysqlclient"
     ++ lib.optional withSQLite "-lsqlite3"
     ++ lib.optional withLDAP "-lldap");

I made it work by adding

  nixpkgs.overlays = [                                                                        
     (self: super: {                       
       postfix = super.postfix.override { withPgSQL = true; };
     })                                             
   ]

to my configuration.nix.

Is this the idiomatic way to do this? Is there an easier way? I was expecting a simple option which I would set to true. Would it be desirable to have options for this in the module or would this be the wrong place because the module should not change the build/compilation? I am am not sure whether I should research and make a PR for Postfix to make enabling PostgreSQL easier of whether everything is already as it should be. I observed the same for Dovecot.

I think overlay would be an overkill in this case, you can just do:

services.postfix.package = pkgs.postfix.override { withPgSQL = true; };

related docs: Overriding | nixpkgs

1 Like