1{
2 lib,
3 stdenv,
4 fetchzip,
5 autoreconfHook,
6 makeWrapper,
7 nixosTests,
8 pkg-config,
9 file,
10 linuxHeaders,
11 openssl,
12 pcre,
13 perlPackages,
14 python3,
15 # recommended dependencies
16 withHwloc ? true,
17 hwloc,
18 withCurl ? true,
19 curl,
20 withCurses ? true,
21 ncurses,
22 withCap ? stdenv.hostPlatform.isLinux,
23 libcap,
24 withUnwind ? stdenv.hostPlatform.isLinux,
25 libunwind,
26 # optional dependencies
27 withBrotli ? false,
28 brotli,
29 withCjose ? false,
30 cjose,
31 withGeoIP ? false,
32 geoip,
33 withHiredis ? false,
34 hiredis,
35 withImageMagick ? false,
36 imagemagick,
37 withJansson ? false,
38 jansson,
39 withKyotoCabinet ? false,
40 kyotocabinet,
41 withLuaJIT ? false,
42 luajit,
43 withMaxmindDB ? false,
44 libmaxminddb,
45 # optional features
46 enableWCCP ? false,
47}:
48
49stdenv.mkDerivation rec {
50 pname = "trafficserver";
51 version = "9.2.11";
52
53 src = fetchzip {
54 url = "mirror://apache/trafficserver/trafficserver-${version}.tar.bz2";
55 hash = "sha256-WFABr7+JsUbQagLFK0OXZ20t4QCuYrozeaV4fKO/c2s=";
56 };
57
58 # NOTE: The upstream README indicates that flex is needed for some features,
59 # but it actually seems to be unnecessary as of this commit[1]. The detection
60 # logic for bison and flex is still present in the build script[2], but no
61 # other code seems to depend on it. This situation is susceptible to change
62 # though, so it's a good idea to inspect the build scripts periodically.
63 #
64 # [1]: https://github.com/apache/trafficserver/pull/5617
65 # [2]: https://github.com/apache/trafficserver/blob/3fd2c60/configure.ac#L742-L788
66 nativeBuildInputs = [
67 autoreconfHook
68 makeWrapper
69 pkg-config
70 file
71 python3
72 ]
73 ++ (with perlPackages; [
74 perl
75 ExtUtilsMakeMaker
76 ])
77 ++ lib.optionals stdenv.hostPlatform.isLinux [ linuxHeaders ];
78
79 buildInputs = [
80 openssl
81 pcre
82 perlPackages.perl
83 ]
84 ++ lib.optional withBrotli brotli
85 ++ lib.optional withCap libcap
86 ++ lib.optional withCjose cjose
87 ++ lib.optional withCurl curl
88 ++ lib.optional withGeoIP geoip
89 ++ lib.optional withHiredis hiredis
90 ++ lib.optional withHwloc hwloc
91 ++ lib.optional withImageMagick imagemagick
92 ++ lib.optional withJansson jansson
93 ++ lib.optional withKyotoCabinet kyotocabinet
94 ++ lib.optional withCurses ncurses
95 ++ lib.optional withLuaJIT luajit
96 ++ lib.optional withUnwind libunwind
97 ++ lib.optional withMaxmindDB libmaxminddb;
98
99 outputs = [
100 "out"
101 "man"
102 ];
103
104 postPatch = ''
105 patchShebangs \
106 iocore/aio/test_AIO.sample \
107 src/traffic_via/test_traffic_via \
108 src/traffic_logstats/tests \
109 tools/check-unused-dependencies
110 ''
111 + lib.optionalString stdenv.hostPlatform.isLinux ''
112 substituteInPlace configure.ac \
113 --replace-fail '/usr/include/linux' '${linuxHeaders}/include/linux'
114 ''
115 + lib.optionalString stdenv.hostPlatform.isDarwin ''
116 # 'xcrun leaks' probably requires non-free XCode
117 substituteInPlace iocore/net/test_certlookup.cc \
118 --replace-fail 'xcrun leaks' 'true'
119 '';
120
121 configureFlags = [
122 "--enable-layout=NixOS"
123 "--enable-experimental-plugins"
124 (lib.enableFeature enableWCCP "wccp")
125
126 (lib.withFeatureAs withHiredis "hiredis" hiredis)
127 ];
128
129 installFlags = [
130 "pkgsysconfdir=${placeholder "out"}/etc/trafficserver"
131
132 # replace runtime directories with an install-time placeholder directory
133 "pkgcachedir=${placeholder "out"}/.install-trafficserver"
134 "pkglocalstatedir=${placeholder "out"}/.install-trafficserver"
135 "pkglogdir=${placeholder "out"}/.install-trafficserver"
136 "pkgruntimedir=${placeholder "out"}/.install-trafficserver"
137 ];
138
139 postInstall = ''
140 install -Dm644 rc/trafficserver.service $out/lib/systemd/system/trafficserver.service
141
142 wrapProgram $out/bin/tspush \
143 --set PERL5LIB '${with perlPackages; makePerlPath [ URI ]}' \
144 --prefix PATH : "${lib.makeBinPath [ file ]}"
145
146 find "$out" -name '*.la' -delete
147
148 # ensure no files actually exist in this directory
149 rmdir $out/.install-trafficserver
150 '';
151
152 installCheckPhase =
153 let
154 expected = ''
155 Via header is [uScMsEf p eC:t cCMp sF], Length is 22
156 Via Header Details:
157 Request headers received from client :simple request (not conditional)
158 Result of Traffic Server cache lookup for URL :miss (a cache "MISS")
159 Response information received from origin server :error in response
160 Result of document write-to-cache: :no cache write performed
161 Proxy operation result :unknown
162 Error codes (if any) :connection to server failed
163 Tunnel info :no tunneling
164 Cache Type :cache
165 Cache Lookup Result :cache miss (url not in cache)
166 Parent proxy connection status :no parent proxy or unknown
167 Origin server connection status :connection open failed
168 '';
169 in
170 ''
171 runHook preInstallCheck
172 diff -Naur <($out/bin/traffic_via '[uScMsEf p eC:t cCMp sF]') - <<EOF
173 ${lib.removeSuffix "\n" expected}
174 EOF
175 runHook postInstallCheck
176 '';
177
178 doCheck = true;
179 doInstallCheck = true;
180 enableParallelBuilding = true;
181
182 passthru.tests = { inherit (nixosTests) trafficserver; };
183
184 meta = {
185 homepage = "https://trafficserver.apache.org";
186 changelog = "https://raw.githubusercontent.com/apache/trafficserver/${version}/CHANGELOG-${version}";
187 description = "Fast, scalable, and extensible HTTP caching proxy server";
188 longDescription = ''
189 Apache Traffic Server is a high-performance web proxy cache that improves
190 network efficiency and performance by caching frequently-accessed
191 information at the edge of the network. This brings content physically
192 closer to end users, while enabling faster delivery and reduced bandwidth
193 use. Traffic Server is designed to improve content delivery for
194 enterprises, Internet service providers (ISPs), backbone providers, and
195 large intranets by maximizing existing and available bandwidth.
196 '';
197 license = lib.licenses.asl20;
198 maintainers = with lib.maintainers; [ midchildan ];
199 platforms = lib.platforms.unix;
200 };
201}