1{ lib, stdenv, fetchFromGitHub
2, makeWrapper, cmake, llvmPackages
3, flex, bison, elfutils, python, luajit, netperf, iperf, libelf
4, bash, libbpf, nixosTests
5, audit
6}:
7
8python.pkgs.buildPythonApplication rec {
9 pname = "bcc";
10 version = "0.24.0";
11
12 disabled = !stdenv.isLinux;
13
14 src = fetchFromGitHub {
15 owner = "iovisor";
16 repo = "bcc";
17 rev = "v${version}";
18 sha256 = "sha256-5Nq6LmphiyiiIyru/P2rCCmA25cwJIWn08oK1+eM3cQ=";
19 };
20 format = "other";
21
22 buildInputs = with llvmPackages; [
23 llvm llvm.dev libclang
24 elfutils luajit netperf iperf
25 flex bash libbpf
26 ];
27
28 patches = [
29 # This is needed until we fix
30 # https://github.com/NixOS/nixpkgs/issues/40427
31 ./fix-deadlock-detector-import.patch
32 ];
33
34 propagatedBuildInputs = [ python.pkgs.netaddr ];
35 nativeBuildInputs = [ makeWrapper cmake flex bison llvmPackages.llvm.dev ];
36
37 cmakeFlags = [
38 "-DBCC_KERNEL_MODULES_DIR=/run/booted-system/kernel-modules/lib/modules"
39 "-DREVISION=${version}"
40 "-DENABLE_USDT=ON"
41 "-DENABLE_CPP_API=ON"
42 "-DCMAKE_USE_LIBBPF_PACKAGE=ON"
43 ];
44
45 # to replace this executable path:
46 # https://github.com/iovisor/bcc/blob/master/src/python/bcc/syscall.py#L384
47 ausyscall = "${audit}/bin/ausyscall";
48
49 postPatch = ''
50 substituteAll ${./libbcc-path.patch} ./libbcc-path.patch
51 patch -p1 < libbcc-path.patch
52
53 substituteAll ${./absolute-ausyscall.patch} ./absolute-ausyscall.patch
54 patch -p1 < absolute-ausyscall.patch
55
56 # https://github.com/iovisor/bcc/issues/3996
57 substituteInPlace src/cc/libbcc.pc.in \
58 --replace '$'{exec_prefix}/@CMAKE_INSTALL_LIBDIR@ @CMAKE_INSTALL_FULL_LIBDIR@
59 '';
60
61 postInstall = ''
62 mkdir -p $out/bin $out/share
63 rm -r $out/share/bcc/tools/old
64 mv $out/share/bcc/tools/doc $out/share
65 mv $out/share/bcc/man $out/share/
66
67 find $out/share/bcc/tools -type f -executable -print0 | \
68 while IFS= read -r -d ''$'\0' f; do
69 bin=$out/bin/$(basename $f)
70 if [ ! -e $bin ]; then
71 ln -s $f $bin
72 fi
73 substituteInPlace "$f" \
74 --replace '$(dirname $0)/lib' "$out/share/bcc/tools/lib"
75 done
76
77 sed -i -e "s!lib=.*!lib=$out/bin!" $out/bin/{java,ruby,node,python}gc
78 '';
79
80 postFixup = ''
81 wrapPythonProgramsIn "$out/share/bcc/tools" "$out $pythonPath"
82 '';
83
84 outputs = [ "out" "man" ];
85
86 passthru.tests = {
87 bpf = nixosTests.bpf;
88 };
89
90 meta = with lib; {
91 description = "Dynamic Tracing Tools for Linux";
92 homepage = "https://iovisor.github.io/bcc/";
93 license = licenses.asl20;
94 maintainers = with maintainers; [ ragge mic92 thoughtpolice martinetd ];
95 };
96}