summaryrefslogtreecommitdiff
path: root/pkgs/by-name/ng/nghttp2/package.nix
blob: 057aa9e93affff34609e1839050ac82dcb41abde (about) (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
{
  lib,
  stdenv,
  fetchurl,
  installShellFiles,
  pkg-config,

  # Optional dependencies
  enableApp ? with stdenv.hostPlatform; !isWindows && !isStatic,
  c-aresMinimal,
  libev,
  openssl,
  zlib,
  enableGetAssets ? false,
  libxml2,
  enableHpack ? false,
  jansson,
  enableHttp3 ? false,
  ngtcp2,
  nghttp3,
  quictls,
  enableJemalloc ? false,
  jemalloc,
  enablePython ? false,
  python3,
  ncurses,

  # Unit tests ; we have to set TZDIR, which is a GNUism.
  enableTests ? stdenv.hostPlatform.isGnu,
  cunit,
  tzdata,

  # downstream dependencies, for testing
  curl,
  libsoup_3,
}:

# Note: this package is used for bootstrapping fetchurl, and thus cannot use fetchpatch!
# All mutable patches (generated by GitHub or cgit) that are needed here
# should be included directly in Nixpkgs as files.

assert enableGetAssets -> enableApp;
assert enableHpack -> enableApp;
assert enableHttp3 -> enableApp;
assert enableJemalloc -> enableApp;

stdenv.mkDerivation rec {
  pname = "nghttp2";
  version = "1.65.0";

  src = fetchurl {
    url = "https://github.com/${pname}/${pname}/releases/download/v${version}/${pname}-${version}.tar.bz2";
    sha256 = "sha256-C9u3jcIYcEhP1URJBnZXtg47G3Im4RdM9WQBbG0zB/U=";
  };

  outputs = [
    "out"
    "dev"
    "lib"
    "doc"
    "man"
  ];

  nativeBuildInputs = [ pkg-config ] ++ lib.optionals (enableApp) [ installShellFiles ];

  buildInputs =
    lib.optionals enableApp [
      c-aresMinimal
      libev
      zlib
    ]
    ++ lib.optionals (enableApp && !enableHttp3) [ openssl ]
    ++ lib.optionals (enableGetAssets) [ libxml2 ]
    ++ lib.optionals (enableHpack) [ jansson ]
    ++ lib.optionals (enableJemalloc) [ jemalloc ]
    ++ lib.optionals (enableHttp3) [
      ngtcp2
      nghttp3
      quictls
    ]
    ++ lib.optionals (enablePython) [ python3 ];

  enableParallelBuilding = true;

  configureFlags = [
    "--disable-examples"
    (lib.enableFeature enableApp "app")
    (lib.enableFeature enableHttp3 "http3")
  ];

  # Unit tests require CUnit and setting TZDIR environment variable
  doCheck = enableTests;
  nativeCheckInputs = lib.optionals (enableTests) [
    cunit
    tzdata
  ];
  preCheck = lib.optionalString (enableTests) ''
    export TZDIR=${tzdata}/share/zoneinfo
  '';

  # this could be accomplished by updateAutotoolsGnuConfigScriptsHook, but that causes infinite recursion
  # necessary for FreeBSD code path in configure
  postPatch = ''
    substituteInPlace ./config.guess --replace-fail /usr/bin/uname uname
  '';

  postInstall =
    lib.optionalString (enableApp) ''
      installShellCompletion --bash doc/bash_completion/{h2load,nghttp,nghttpd,nghttpx}
    ''
    + lib.optionalString (!enableApp) ''
      rm -r $out/bin
    ''
    + lib.optionalString (enablePython) ''
      patchShebangs $out/share/nghttp2
    ''
    + lib.optionalString (!enablePython) ''
      rm -r $out/share
    '';

  passthru.tests = {
    inherit curl libsoup_3;
  };

  meta = with lib; {
    description = "HTTP/2 C library and tools";
    longDescription = ''
      nghttp2 is an implementation of the HyperText Transfer Protocol version 2 in C.
      The framing layer of HTTP/2 is implemented as a reusable C library. On top of that,
      we have implemented an HTTP/2 client, server and proxy. We have also developed
      load test and benchmarking tools for HTTP/2.
      An HPACK encoder and decoder are available as a public API.
      We have Python bindings of this library, but we do not have full code coverage yet.
      An experimental high level C++ library is also available.
    '';

    homepage = "https://nghttp2.org/";
    changelog = "https://github.com/nghttp2/nghttp2/releases/tag/v${version}";
    # News articles with changes summary can be found here: https://nghttp2.org/blog/archives/
    license = licenses.mit;
    maintainers = with maintainers; [ c0bw3b ];
    platforms = platforms.all;
  };
}