Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib, stdenv, fetchFromGitHub, fetchurl, fetchpatch
2, ocaml, findlib, ocamlbuild, ocaml_oasis
3, bitstring, camlzip, cmdliner, core_kernel, ezjsonm, fileutils, mmap, lwt, ocamlgraph, ocurl, re, uri, zarith, piqi, piqi-ocaml, uuidm, llvm, frontc, ounit, ppx_jane, parsexp
4, utop, libxml2, ncurses
5, linenoise
6, ppx_bap
7, ppx_bitstring
8, yojson
9, which, makeWrapper, writeText
10, z3
11}:
12
13if lib.versionOlder ocaml.version "4.08"
14then throw "BAP is not available for OCaml ${ocaml.version}"
15else
16
17stdenv.mkDerivation rec {
18 pname = "ocaml${ocaml.version}-bap";
19 version = "2.5.0";
20 src = fetchFromGitHub {
21 owner = "BinaryAnalysisPlatform";
22 repo = "bap";
23 rev = "v${version}";
24 sha256 = "1c30zxn0zyi0wypvjmik3fd6n6a8xjcb102qfnccn1af052bvsrd";
25 };
26
27 sigs = fetchurl {
28 url = "https://github.com/BinaryAnalysisPlatform/bap/releases/download/v${version}/sigs.zip";
29 sha256 = "0d69jd28z4g64mglq94kj5imhmk5f6sgcsh9q2nij3b0arpcliwk";
30 };
31
32 createFindlibDestdir = true;
33
34 setupHook = writeText "setupHook.sh" ''
35 export CAML_LD_LIBRARY_PATH="''${CAML_LD_LIBRARY_PATH-}''${CAML_LD_LIBRARY_PATH:+:}''$1/lib/ocaml/${ocaml.version}/site-lib/ocaml${ocaml.version}-bap-${version}/"
36 export CAML_LD_LIBRARY_PATH="''${CAML_LD_LIBRARY_PATH-}''${CAML_LD_LIBRARY_PATH:+:}''$1/lib/ocaml/${ocaml.version}/site-lib/ocaml${ocaml.version}-bap-${version}-llvm-plugins/"
37 '';
38
39 nativeBuildInputs = [ which makeWrapper ocaml findlib ocamlbuild ocaml_oasis ];
40
41 buildInputs = [ ocamlbuild
42 linenoise
43 ounit
44 ppx_bitstring
45 z3
46 utop libxml2 ncurses ];
47
48 propagatedBuildInputs = [ bitstring camlzip cmdliner ppx_bap core_kernel ezjsonm fileutils mmap lwt ocamlgraph ocurl re uri zarith piqi parsexp
49 piqi-ocaml uuidm frontc yojson ];
50
51 installPhase = ''
52 runHook preInstall
53 export OCAMLPATH=$OCAMLPATH:$OCAMLFIND_DESTDIR;
54 export PATH=$PATH:$out/bin
55 export CAML_LD_LIBRARY_PATH=''${CAML_LD_LIBRARY_PATH-}''${CAML_LD_LIBRARY_PATH:+:}$OCAMLFIND_DESTDIR/bap-plugin-llvm/:$OCAMLFIND_DESTDIR/bap/
56 mkdir -p $out/lib/bap
57 make install
58 rm $out/bin/baptop
59 makeWrapper ${utop}/bin/utop $out/bin/baptop --prefix OCAMLPATH : $OCAMLPATH --prefix PATH : $PATH --add-flags "-ppx ppx-bap -short-paths -require \"bap.top\""
60 wrapProgram $out/bin/bapbuild --prefix OCAMLPATH : $OCAMLPATH --prefix PATH : $PATH
61 ln -s $sigs $out/share/bap/sigs.zip
62 runHook postInstall
63 '';
64
65 disableIda = "--disable-ida";
66 disableGhidra = "--disable-ghidra";
67
68 patches = [
69 ./curses_is_ncurses.patch
70 ];
71
72 preConfigure = ''
73 substituteInPlace oasis/elf-loader --replace bitstring.ppx ppx_bitstring
74 '';
75
76 configureFlags = [ "--enable-everything ${disableIda} ${disableGhidra}" "--with-llvm-config=${llvm.dev}/bin/llvm-config" ];
77
78 meta = with lib; {
79 description = "Platform for binary analysis. It is written in OCaml, but can be used from other languages.";
80 homepage = "https://github.com/BinaryAnalysisPlatform/bap/";
81 license = licenses.mit;
82 maintainers = [ maintainers.maurer ];
83 mainProgram = "bap";
84 };
85}