1{ useLua ? true
2, usePcre ? true
3, withPrometheusExporter ? true
4, stdenv, lib, fetchurl, nixosTests
5, openssl, zlib, libxcrypt
6, lua5_3 ? null, pcre ? null, systemd ? null
7}:
8
9assert useLua -> lua5_3 != null;
10assert usePcre -> pcre != null;
11
12stdenv.mkDerivation rec {
13 pname = "haproxy";
14 version = "2.8.0";
15
16 src = fetchurl {
17 url = "https://www.haproxy.org/download/${lib.versions.majorMinor version}/src/${pname}-${version}.tar.gz";
18 sha256 = "sha256-Yc2vtdt+kXTQdXuOS83pODUjBvt8yP8rX1XCbdSKbPc=";
19 };
20
21 buildInputs = [ openssl zlib libxcrypt ]
22 ++ lib.optional useLua lua5_3
23 ++ lib.optional usePcre pcre
24 ++ lib.optional stdenv.isLinux systemd;
25
26 # TODO: make it work on bsd as well
27 makeFlags = [
28 "PREFIX=${placeholder "out"}"
29 ("TARGET=" + (if stdenv.isSunOS then "solaris"
30 else if stdenv.isLinux then "linux-glibc"
31 else if stdenv.isDarwin then "osx"
32 else "generic"))
33 ];
34
35 buildFlags = [
36 "USE_OPENSSL=yes"
37 "USE_ZLIB=yes"
38 ] ++ lib.optionals usePcre [
39 "USE_PCRE=yes"
40 "USE_PCRE_JIT=yes"
41 ] ++ lib.optionals useLua [
42 "USE_LUA=yes"
43 "LUA_LIB_NAME=lua"
44 "LUA_LIB=${lua5_3}/lib"
45 "LUA_INC=${lua5_3}/include"
46 ] ++ lib.optionals stdenv.isLinux [
47 "USE_SYSTEMD=yes"
48 "USE_GETADDRINFO=1"
49 ] ++ lib.optionals withPrometheusExporter [
50 "USE_PROMEX=yes"
51 ] ++ [ "CC=${stdenv.cc.targetPrefix}cc" ];
52
53 enableParallelBuilding = true;
54
55 passthru.tests.haproxy = nixosTests.haproxy;
56
57 meta = with lib; {
58 description = "Reliable, high performance TCP/HTTP load balancer";
59 longDescription = ''
60 HAProxy is a free, very fast and reliable solution offering high
61 availability, load balancing, and proxying for TCP and HTTP-based
62 applications. It is particularly suited for web sites crawling under very
63 high loads while needing persistence or Layer7 processing. Supporting
64 tens of thousands of connections is clearly realistic with todays
65 hardware.
66 '';
67 homepage = "https://haproxy.org";
68 changelog = "https://www.haproxy.org/download/${lib.versions.majorMinor version}/src/CHANGELOG";
69 license = with licenses; [ gpl2Plus lgpl21Only ];
70 maintainers = with maintainers; [ ];
71 platforms = with platforms; linux ++ darwin;
72 };
73}