Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / development / libraries / hnswlib / default.nix
blob9033d9f5ff4db01b1c2430bcd6df21e3d7c79482
1 { lib
2 , stdenv
3 , fetchFromGitHub
4 , fetchpatch
5 , cmake
6 , python3
7 }:
8 let
9   python = python3.withPackages(ps: with ps; [
10     numpy
11   ]);
14 stdenv.mkDerivation (finalAttrs: {
15   pname = "hnswlib";
16   version = "0.7.0";
18   src = fetchFromGitHub {
19     owner = "nmslib";
20     repo = "hnswlib";
21     rev = "refs/tags/v${finalAttrs.version}";
22     hash = "sha256-XXz0NIQ5dCGwcX2HtbK5NFTalP0TjLO6ll6TmH3oflI=";
23   };
25   patches = [
26     (fetchpatch {
27       name = "CVE-2023-37365.patch";
28       url = "https://github.com/nmslib/hnswlib/commit/f6d170ce0b41f9e75ace473b09df6e7872590757.patch";
29       hash = "sha256-28nakC0rh6kx6yYjv7m6r9/yJ+lWQuooRFyYYQN2rX8=";
30     })
31   ];
33   # this is a header-only library, so we don't need to build it
34   # we need `cmake` only to run tests
35   nativeBuildInputs = lib.optionals finalAttrs.doCheck [
36     cmake
37     python
38   ];
40   # we only want to run buildPhase when we run tests
41   dontBuild = !finalAttrs.doCheck;
43   installPhase = ''
44     runHook preInstall
46     install -Dm644 $src/hnswlib/*.h -t $out/include/hnswlib
48     runHook postInstall
49   '';
51   doCheck = true;
53   preCheck = ''
54     pushd ../tests/cpp
55     ${python.interpreter} update_gen_data.py
56     popd
57   '';
59   checkPhase = ''
60     runHook preCheck
62     ./test_updates
64     runHook postCheck
65   '';
67   meta = with lib; {
68     description = "Header-only C++/python library for fast approximate nearest neighbors";
69     homepage = "https://github.com/nmslib/hnswlib";
70     changelog = "https://github.com/nmslib/hnswlib/releases/tag/${finalAttrs.src.rev}";
71     license = licenses.asl20;
72     maintainers = with maintainers; [ natsukium ];
73     platforms = platforms.unix;
74   };