1{
2 lib,
3 stdenv,
4 linuxHeaders,
5 buildPackages,
6 libopcodes,
7 libopcodes_2_38,
8 libbfd,
9 libbfd_2_38,
10 elfutils,
11 readline,
12 zlib,
13 python3,
14 bison,
15 flex,
16}:
17
18stdenv.mkDerivation rec {
19 pname = "bpftools";
20
21 inherit (linuxHeaders) version src;
22
23 separateDebugInfo = true;
24
25 depsBuildBuild = [ buildPackages.stdenv.cc ];
26 nativeBuildInputs = [
27 python3
28 bison
29 flex
30 ];
31 buildInputs =
32 (
33 if (lib.versionAtLeast version "5.20") then
34 [
35 libopcodes
36 libbfd
37 ]
38 else
39 [
40 libopcodes_2_38
41 libbfd_2_38
42 ]
43 )
44 ++ [
45 elfutils
46 zlib
47 readline
48 ];
49
50 preConfigure = ''
51 patchShebangs scripts/bpf_doc.py
52
53 cd tools/bpf
54 substituteInPlace ./bpftool/Makefile \
55 --replace '/usr/local' "$out" \
56 --replace '/usr' "$out" \
57 --replace '/sbin' '/bin'
58 '';
59
60 buildFlags = [
61 "bpftool"
62 "bpf_asm"
63 "bpf_dbg"
64 ];
65
66 # needed for cross to riscv64
67 makeFlags = [ "ARCH=${stdenv.hostPlatform.linuxArch}" ];
68
69 installPhase = ''
70 make -C bpftool install
71 install -Dm755 -t $out/bin bpf_asm
72 install -Dm755 -t $out/bin bpf_dbg
73 '';
74
75 meta = with lib; {
76 homepage = "https://github.com/libbpf/bpftool";
77 description = "Debugging/program analysis tools for the eBPF subsystem";
78 license = [
79 licenses.gpl2Only
80 licenses.bsd2
81 ];
82 platforms = platforms.linux;
83 maintainers = with maintainers; [ thoughtpolice ];
84 };
85}