1{
2 audit,
3 bash,
4 bison,
5 cmake,
6 elfutils,
7 fetchFromGitHub,
8 flex,
9 iperf,
10 lib,
11 libbpf,
12 llvmPackages,
13 luajit,
14 makeWrapper,
15 netperf,
16 nixosTests,
17 python3Packages,
18 readline,
19 replaceVars,
20 zip,
21}:
22
23python3Packages.buildPythonApplication rec {
24 pname = "bcc";
25 version = "0.35.0";
26 pyproject = false;
27
28 src = fetchFromGitHub {
29 owner = "iovisor";
30 repo = "bcc";
31 tag = "v${version}";
32 hash = "sha256-eP/VEq7cPALi2oDKAZFQGQ3NExdmcBKyi6ddRZiYmbI=";
33 };
34
35 patches = [
36 # This is needed until we fix
37 # https://github.com/NixOS/nixpkgs/issues/40427
38 ./fix-deadlock-detector-import.patch
39 # Quick & dirty fix for bashreadline
40 # https://github.com/NixOS/nixpkgs/issues/328743
41 ./bashreadline.py-remove-dependency-on-elftools.patch
42
43 (replaceVars ./absolute-ausyscall.patch {
44 ausyscall = lib.getExe' audit "ausyscall";
45 })
46 ];
47
48 build-system = [ python3Packages.setuptools ];
49
50 dependencies = [ python3Packages.netaddr ];
51
52 nativeBuildInputs = [
53 bison
54 cmake
55 flex
56 llvmPackages.llvm
57 makeWrapper
58 zip
59 ];
60
61 buildInputs = [
62 llvmPackages.llvm
63 llvmPackages.libclang
64 elfutils
65 luajit
66 netperf
67 iperf
68 flex
69 bash
70 libbpf
71 ];
72
73 cmakeFlags = [
74 (lib.cmakeFeature "BCC_KERNEL_MODULES_DIR" "/run/booted-system/kernel-modules/lib/modules")
75 (lib.cmakeFeature "REVISION" version)
76 (lib.cmakeBool "ENABLE_USDT" true)
77 (lib.cmakeBool "ENABLE_CPP_API" true)
78 (lib.cmakeBool "CMAKE_USE_LIBBPF_PACKAGE" true)
79 (lib.cmakeBool "ENABLE_LIBDEBUGINFOD" false)
80 ];
81
82 postPatch = ''
83 substituteInPlace src/python/bcc/libbcc.py \
84 --replace-fail "libbcc.so.0" "$out/lib/libbcc.so.0"
85
86 # https://github.com/iovisor/bcc/issues/3996
87 substituteInPlace src/cc/libbcc.pc.in \
88 --replace-fail '$'{exec_prefix}/@CMAKE_INSTALL_LIBDIR@ @CMAKE_INSTALL_FULL_LIBDIR@
89
90 substituteInPlace tools/bashreadline.py \
91 --replace-fail '/bin/bash' '${readline}/lib/libreadline.so'
92 '';
93
94 postInstall = ''
95 mkdir -p $out/bin $out/share
96 rm -r $out/share/bcc/tools/old
97 mv $out/share/bcc/tools/doc $out/share
98 mv $out/share/bcc/man $out/share/
99
100 find $out/share/bcc/tools -type f -executable -print0 | \
101 while IFS= read -r -d ''$'\0' f; do
102 bin=$out/bin/$(basename $f)
103 if [ ! -e $bin ]; then
104 ln -s $f $bin
105 fi
106 substituteInPlace "$f" \
107 --replace-quiet '$(dirname $0)/lib' "$out/share/bcc/tools/lib"
108 done
109 '';
110
111 pythonImportsCheck = [ "bcc" ];
112
113 postFixup = ''
114 wrapPythonProgramsIn "$out/share/bcc/tools" "$out $pythonPath"
115 '';
116
117 outputs = [
118 "out"
119 "man"
120 ];
121
122 passthru.tests = {
123 bpf = nixosTests.bpf;
124 };
125
126 meta = with lib; {
127 description = "Dynamic Tracing Tools for Linux";
128 homepage = "https://iovisor.github.io/bcc/";
129 license = licenses.asl20;
130 maintainers = with maintainers; [
131 ragge
132 mic92
133 thoughtpolice
134 martinetd
135 ryan4yin
136 ];
137 platforms = platforms.linux;
138 };
139}