1{
2 lib,
3 stdenv,
4 fetchurl,
5 fetchpatch2,
6 perl,
7 zlib,
8 apr,
9 aprutil,
10 pcre2,
11 libiconv,
12 lynx,
13 which,
14 libxcrypt,
15 buildPackages,
16 pkgsCross,
17 runCommand,
18 nixosTests,
19 proxySupport ? true,
20 sslSupport ? true,
21 openssl,
22 http2Support ? true,
23 nghttp2,
24 ldapSupport ? true,
25 openldap,
26 libxml2Support ? true,
27 libxml2,
28 brotliSupport ? true,
29 brotli,
30 luaSupport ? false,
31 lua5,
32}:
33
34stdenv.mkDerivation rec {
35 pname = "apache-httpd";
36 version = "2.4.65";
37
38 src = fetchurl {
39 url = "mirror://apache/httpd/httpd-${version}.tar.bz2";
40 hash = "sha256-WLi+l9mUDsF/dlbAxrn0G2GKrEaLiUtTQUjjKWxTuLM=";
41 };
42
43 patches = [
44 # Fix cross-compilation by using CC_FOR_BUILD for generator program
45 # https://issues.apache.org/bugzilla/show_bug.cgi?id=51257#c6
46 (fetchpatch2 {
47 name = "apache-httpd-cross-compile.patch";
48 url = "https://gitlab.com/buildroot.org/buildroot/-/raw/5dae8cddeecf16c791f3c138542ec51c4e627d75/package/apache/0001-cross-compile.patch";
49 hash = "sha256-KGnAa6euOt6dkZQwURyVITcfqTkDkSR8zpE97DywUUw=";
50 })
51 ];
52
53 # FIXME: -dev depends on -doc
54 outputs = [
55 "out"
56 "dev"
57 "man"
58 "doc"
59 ];
60 setOutputFlags = false; # it would move $out/modules, etc.
61
62 depsBuildBuild = [ buildPackages.stdenv.cc ];
63
64 nativeBuildInputs = [
65 perl
66 which
67 ];
68
69 buildInputs = [
70 perl
71 libxcrypt
72 zlib
73 ]
74 ++ lib.optional brotliSupport brotli
75 ++ lib.optional sslSupport openssl
76 ++ lib.optional ldapSupport openldap
77 # there is no --with-ldap flag
78 ++ lib.optional libxml2Support libxml2
79 ++ lib.optional http2Support nghttp2
80 ++ lib.optional stdenv.hostPlatform.isDarwin libiconv;
81
82 postPatch = ''
83 sed -i config.layout -e "s|installbuilddir:.*|installbuilddir: $dev/share/build|"
84 sed -i configure -e 's|perlbin=.*|perlbin="/usr/bin/env perl"|'
85 sed -i support/apachectl.in -e 's|@LYNX_PATH@|${lynx}/bin/lynx|'
86 '';
87
88 # Required for ‘pthread_cancel’.
89 NIX_LDFLAGS = lib.optionalString (!stdenv.hostPlatform.isDarwin) "-lgcc_s";
90
91 configureFlags = [
92 "--with-apr=${apr.dev}"
93 "--with-apr-util=${aprutil.dev}"
94 "--with-z=${zlib.dev}"
95 "--with-pcre=${pcre2.dev}/bin/pcre2-config"
96 "--disable-maintainer-mode"
97 "--disable-debugger-mode"
98 "--enable-mods-shared=all"
99 "--enable-mpms-shared=all"
100 "--enable-cern-meta"
101 "--enable-imagemap"
102 "--enable-cgi"
103 "--includedir=${placeholder "dev"}/include"
104 (lib.enableFeature proxySupport "proxy")
105 (lib.enableFeature sslSupport "ssl")
106 (lib.withFeatureAs libxml2Support "libxml2" "${libxml2.dev}/include/libxml2")
107 "--docdir=$(doc)/share/doc"
108
109 (lib.enableFeature brotliSupport "brotli")
110 (lib.withFeatureAs brotliSupport "brotli" brotli)
111
112 (lib.enableFeature http2Support "http2")
113 (lib.withFeature http2Support "nghttp2")
114
115 (lib.enableFeature luaSupport "lua")
116 (lib.withFeatureAs luaSupport "lua" lua5)
117 ]
118 ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
119 # skip bad config check when cross compiling
120 # https://gitlab.com/buildroot.org/buildroot/-/blob/5dae8cddeecf16c791f3c138542ec51c4e627d75/package/apache/apache.mk#L23
121 "ap_cv_void_ptr_lt_long=no"
122 ];
123
124 enableParallelBuilding = true;
125
126 stripDebugList = [
127 "lib"
128 "modules"
129 "bin"
130 ];
131
132 postInstall = ''
133 mkdir -p $doc/share/doc/httpd
134 mv $out/manual $doc/share/doc/httpd
135 mkdir -p $dev/bin
136 mv $out/bin/apxs $dev/bin/apxs
137 '';
138
139 passthru = {
140 inherit
141 apr
142 aprutil
143 sslSupport
144 proxySupport
145 ldapSupport
146 luaSupport
147 lua5
148 ;
149 tests = {
150 acme-integration = nixosTests.acme.httpd;
151 proxy = nixosTests.proxy;
152 php = nixosTests.php.httpd;
153 cross = runCommand "apacheHttpd-test-cross" { } ''
154 ${pkgsCross.aarch64-multiplatform.apacheHttpd.dev}/bin/apxs -q -n INCLUDE | grep CC=aarch64-unknown-linux-gnu-gcc > $out
155 head -n1 ${pkgsCross.aarch64-multiplatform.apacheHttpd}/bin/dbmmanage | grep '^#!${pkgsCross.aarch64-multiplatform.perl}/bin/perl$' >> $out
156 '';
157 };
158 };
159
160 meta = with lib; {
161 description = "Apache HTTPD, the world's most popular web server";
162 homepage = "https://httpd.apache.org/";
163 license = licenses.asl20;
164 platforms = platforms.linux ++ platforms.darwin;
165 maintainers = with maintainers; [ lovek323 ];
166 };
167}