1 { stdenv, lib, fetchurl, makeWrapper, gnused, db, openssl, cyrus_sasl, libnsl
2 , coreutils, findutils, gnugrep, gawk, icu, pcre2, m4
4 , buildPackages, nixosTests
5 , withLDAP ? true, openldap
6 , withPgSQL ? false, postgresql
7 , withMySQL ? false, libmysqlclient
8 , withSQLite ? false, sqlite
12 ccargs = lib.concatStringsSep " " ([
13 "-DUSE_TLS" "-DUSE_SASL_AUTH" "-DUSE_CYRUS_SASL" "-I${cyrus_sasl.dev}/include/sasl"
14 "-DHAS_DB_BYPASS_MAKEDEFS_CHECK"
15 ] ++ lib.optional withPgSQL "-DHAS_PGSQL"
16 ++ lib.optionals withMySQL [ "-DHAS_MYSQL" "-I${libmysqlclient.dev}/include/mysql" "-L${libmysqlclient}/lib/mysql" ]
17 ++ lib.optional withSQLite "-DHAS_SQLITE"
18 ++ lib.optionals withLDAP ["-DHAS_LDAP" "-DUSE_LDAP_SASL"]);
19 auxlibs = lib.concatStringsSep " " ([
20 "-ldb" "-lnsl" "-lresolv" "-lsasl2" "-lcrypto" "-lssl"
21 ] ++ lib.optional withPgSQL "-lpq"
22 ++ lib.optional withMySQL "-lmysqlclient"
23 ++ lib.optional withSQLite "-lsqlite3"
24 ++ lib.optional withLDAP "-lldap");
26 in stdenv.mkDerivation rec {
31 url = "https://de.postfix.org/ftpmirror/official/postfix-${version}.tar.gz";
32 hash = "sha256-VvXkIOfCVFWk6WwZtnL4D5oKNftb7MkkfJ49XcxhfzQ=";
35 nativeBuildInputs = [ makeWrapper m4 ];
36 buildInputs = [ db openssl cyrus_sasl icu libnsl pcre2 ]
37 ++ lib.optional withPgSQL postgresql
38 ++ lib.optional withMySQL libmysqlclient
39 ++ lib.optional withSQLite sqlite
40 ++ lib.optional withLDAP openldap;
42 hardeningDisable = [ "format" ];
43 hardeningEnable = [ "pie" ];
46 ./postfix-script-shell.patch
47 ./postfix-3.0-no-warnings.patch
48 ./post-install-script.patch
49 ./relative-symlinks.patch
53 url = "https://src.fedoraproject.org/rpms/postfix/raw/2f9d42453e67ebc43f786d98262a249037f80a77/f/postfix-3.6.2-glibc-234-build-fix.patch";
54 sha256 = "sha256-xRUL5gaoIt6HagGlhsGwvwrAfYvzMgydsltYMWvl9BI=";
58 postPatch = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
59 sed -e 's!bin/postconf!${buildPackages.postfix}/bin/postconf!' -i postfix-install
61 sed -e '/^PATH=/d' -i postfix-install
62 sed -e "s|@PACKAGE@|$out|" -i conf/post-install
64 # post-install need skip permissions check/set on all symlinks following to /nix/store
65 sed -e "s|@NIX_STORE@|$NIX_STORE|" -i conf/post-install
69 export command_directory=$out/sbin
70 export config_directory=/etc/postfix
71 export meta_directory=$out/etc/postfix
72 export daemon_directory=$out/libexec/postfix
73 export data_directory=/var/lib/postfix/data
74 export html_directory=$out/share/postfix/doc/html
75 export mailq_path=$out/bin/mailq
76 export manpage_directory=$out/share/man
77 export newaliases_path=$out/bin/newaliases
78 export queue_directory=/var/lib/postfix/queue
79 export readme_directory=$out/share/postfix/doc
80 export sendmail_path=$out/bin/sendmail
82 makeFlagsArray+=(AR=$AR _AR=$AR RANLIB=$RANLIB _RANLIB=$RANLIB)
84 make makefiles CCARGS='${ccargs}' AUXLIBS='${auxlibs}'
87 enableParallelBuilding = true;
89 NIX_LDFLAGS = lib.optionalString withLDAP "-llber";
91 installTargets = [ "non-interactive-package" ];
93 installFlags = [ "install_root=installdir" ];
97 mv -v installdir/$out/* $out/
98 cp -rv installdir/etc $out
99 sed -e '/^PATH=/d' -i $out/libexec/postfix/post-install
100 wrapProgram $out/libexec/postfix/post-install \
101 --prefix PATH ":" ${lib.makeBinPath [ coreutils findutils gnugrep ]}
102 wrapProgram $out/libexec/postfix/postfix-script \
103 --prefix PATH ":" ${lib.makeBinPath [ coreutils findutils gnugrep gawk gnused ]}
105 # Avoid dev-only outputs from being retained in final closure.
106 # `makedefs.out` is a documenttation-only file. It should be safe
107 # to store invalid store paths there.
108 sed -e "s|$NIX_STORE/[a-z0-9]\{32\}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" -i $out/etc/postfix/makedefs.out
112 tests = { inherit (nixosTests) postfix postfix-raise-smtpd-tls-security-level; };
114 updateScript = ./update.sh;
118 homepage = "http://www.postfix.org/";
119 changelog = "https://www.postfix.org/announcements/postfix-${version}.html";
120 description = "Fast, easy to administer, and secure mail server";
121 license = with licenses; [ ipl10 epl20 ];
122 platforms = platforms.linux;
123 maintainers = with maintainers; [ globin dotlambda lewo ];