summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/ha/haproxy/package.nix
blob: 91ae06d87ad2ae7ddc3629f6dad655cedc7a568b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
{
  useLua ? true,
  usePcre ? true,
  withPrometheusExporter ? true,
  sslLibrary ? "openssl",
  stdenv,
  lib,
  fetchurl,
  nixosTests,
  zlib,
  libxcrypt,
  aws-lc,
  libressl,
  openssl,
  lua5_4,
  pcre2,
}:

assert lib.assertOneOf "sslLibrary" sslLibrary [
  "aws-lc"
  "libressl"
  "openssl"
];
let
  sslPkgs = {
    inherit
      aws-lc
      libressl
      openssl
      ;
  };
  sslPkg = sslPkgs.${sslLibrary};
in
stdenv.mkDerivation (finalAttrs: {
  pname = "haproxy";
  version = "3.4.4";

  src = fetchurl {
    url = "https://www.haproxy.org/download/${lib.versions.majorMinor finalAttrs.version}/src/haproxy-${finalAttrs.version}.tar.gz";
    hash = "sha256-sMUFPE1GhA7N7jklc2/po95kclWbQ8aRg9cOWT2RM98=";
  };

  buildInputs = [
    sslPkg
    zlib
    libxcrypt
  ]
  ++ lib.optional useLua lua5_4
  ++ lib.optional usePcre pcre2;

  # TODO: make it work on bsd as well
  makeFlags = [
    "PREFIX=${placeholder "out"}"
    (
      "TARGET="
      + (
        if stdenv.hostPlatform.isSunOS then
          "solaris"
        else if stdenv.hostPlatform.isLinux then
          "linux-glibc"
        else if stdenv.hostPlatform.isDarwin then
          "osx"
        else
          "generic"
      )
    )
  ];

  buildFlags = [
    "USE_ZLIB=yes"
    "USE_OPENSSL=yes"
    "SSL_INC=${lib.getDev sslPkg}/include"
    "SSL_LIB=${lib.getDev sslPkg}/lib"
    "USE_QUIC=yes"
  ]
  ++ lib.optionals (sslLibrary == "aws-lc") [
    "USE_OPENSSL_AWSLC=true"
  ]
  ++ lib.optionals (sslLibrary == "openssl" && lib.versionOlder openssl.version "3.5.2") [
    "USE_QUIC_OPENSSL_COMPAT=yes"
  ]
  ++ lib.optionals usePcre [
    "USE_PCRE2=yes"
    "USE_PCRE2_JIT=yes"
  ]
  ++ lib.optionals useLua [
    "USE_LUA=yes"
    "LUA_LIB_NAME=lua"
    "LUA_LIB=${lua5_4}/lib"
    "LUA_INC=${lua5_4}/include"
  ]
  ++ lib.optionals stdenv.hostPlatform.isLinux [
    "USE_GETADDRINFO=1"
  ]
  ++ lib.optionals withPrometheusExporter [
    "USE_PROMEX=yes"
  ]
  ++ [ "CC=${stdenv.cc.targetPrefix}cc" ];

  enableParallelBuilding = true;

  passthru.tests.haproxy = nixosTests.haproxy;

  meta = {
    changelog = "https://www.haproxy.org/download/${lib.versions.majorMinor finalAttrs.version}/src/CHANGELOG";
    description = "Reliable, high performance TCP/HTTP load balancer";
    homepage = "https://haproxy.org";
    license = with lib.licenses; [
      gpl2Plus
      lgpl21Only
    ];
    longDescription = ''
      HAProxy is a free, very fast and reliable solution offering high
      availability, load balancing, and proxying for TCP and HTTP-based
      applications. It is particularly suited for web sites crawling under very
      high loads while needing persistence or Layer7 processing. Supporting
      tens of thousands of connections is clearly realistic with todays
      hardware.
    '';
    maintainers = with lib.maintainers; [ vifino ];
    platforms = with lib.platforms; linux ++ darwin;
    mainProgram = "haproxy";
  };
})