1 { lib, stdenv, fetchurl, makeWrapper, apr, expat, gnused
2 , sslSupport ? true, openssl
3 , bdbSupport ? true, db
4 , ldapSupport ? !stdenv.isCygwin, openldap
6 , cyrus_sasl, autoreconfHook
9 assert sslSupport -> openssl != null;
10 assert bdbSupport -> db != null;
11 assert ldapSupport -> openldap != null;
13 stdenv.mkDerivation rec {
18 url = "mirror://apache/apr/${pname}-${version}.tar.bz2";
19 sha256 = "sha256-pBB243EHRjJsOUUEKZStmk/KwM4Cd92P6gdv7DyXcrU=";
23 ./fix-libxcrypt-build.patch
24 # Fix incorrect Berkeley DB detection with newer versions of clang due to implicit `int` on main errors.
26 ] ++ lib.optional stdenv.isFreeBSD ./include-static-dependencies.patch;
28 NIX_CFLAGS_LINK = [ "-lcrypt" ];
30 outputs = [ "out" "dev" ];
33 nativeBuildInputs = [ makeWrapper autoreconfHook ];
35 configureFlags = [ "--with-apr=${apr.dev}" "--with-expat=${expat.dev}" ]
36 ++ lib.optional (!stdenv.isCygwin) "--with-crypto"
37 ++ lib.optional sslSupport "--with-openssl=${openssl.dev}"
38 ++ lib.optional bdbSupport "--with-berkeley-db=${db.dev}"
39 ++ lib.optional ldapSupport "--with-ldap=ldap"
40 ++ lib.optionals stdenv.isCygwin
41 [ "--without-pgsql" "--without-sqlite2" "--without-sqlite3"
42 "--without-freetds" "--without-berkeley-db" "--without-crypto" ]
46 echo '#define APR_HAVE_CRYPT_H 1' >> confdefs.h
48 # For some reason, db version 6.9 is selected when cross-compiling.
49 # It's unclear as to why, it requires someone with more autotools / configure knowledge to go deeper into that.
50 # Always replacing the link flag with a generic link flag seems to help though, so let's do that for now.
51 lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
52 substituteInPlace Makefile \
53 --replace "-ldb-6.9" "-ldb"
54 substituteInPlace apu-1-config \
55 --replace "-ldb-6.9" "-ldb"
58 propagatedBuildInputs = [ apr expat libiconv libxcrypt ]
59 ++ lib.optional sslSupport openssl
60 ++ lib.optional bdbSupport db
61 ++ lib.optional ldapSupport openldap
62 ++ lib.optional stdenv.isFreeBSD cyrus_sasl;
65 for f in $out/lib/*.la $out/lib/apr-util-1/*.la $dev/bin/apu-1-config; do
66 substituteInPlace $f \
67 --replace "${expat.dev}/lib" "${expat.out}/lib" \
68 --replace "${db.dev}/lib" "${db.out}/lib" \
69 --replace "${openssl.dev}/lib" "${lib.getLib openssl}/lib"
72 # Give apr1 access to sed for runtime invocations.
73 wrapProgram $dev/bin/apu-1-config --prefix PATH : "${gnused}/bin"
76 enableParallelBuilding = true;
79 inherit sslSupport bdbSupport ldapSupport;
83 homepage = "https://apr.apache.org/";
84 description = "A companion library to APR, the Apache Portable Runtime";
85 maintainers = [ maintainers.eelco ];
86 platforms = platforms.unix;
87 license = licenses.asl20;