1{ lib, stdenv, fetchurl
2, libopcodes, libopcodes_2_38
3, libbfd, libbfd_2_38
4, elfutils, readline
5, zlib
6, python3, bison, flex
7}:
8
9stdenv.mkDerivation rec {
10 pname = "bpftools";
11 version = "5.19.12";
12
13 src = fetchurl {
14 url = "mirror://kernel/linux/kernel/v5.x/linux-${version}.tar.xz";
15 sha256 = "sha256-xDalSMcxLOb8WjRyy+rYle749ShB++fHH9jki9/isLo=";
16 };
17
18 patches = [
19 ./strip-binary-name.patch
20 # fix unknown type name '__vector128' on ppc64le
21 ./include-asm-types-for-ppc64le.patch
22 ];
23
24 nativeBuildInputs = [ python3 bison flex ];
25 buildInputs = (if (lib.versionAtLeast version "5.20")
26 then [ libopcodes libbfd ]
27 else [ libopcodes_2_38 libbfd_2_38 ])
28 ++ [ elfutils zlib readline ];
29
30 preConfigure = ''
31 patchShebangs scripts/bpf_doc.py
32
33 cd tools/bpf
34 substituteInPlace ./bpftool/Makefile \
35 --replace '/usr/local' "$out" \
36 --replace '/usr' "$out" \
37 --replace '/sbin' '/bin'
38 '';
39
40 buildFlags = [ "bpftool" "bpf_asm" "bpf_dbg" ];
41
42 installPhase = ''
43 make -C bpftool install
44 install -Dm755 -t $out/bin bpf_asm
45 install -Dm755 -t $out/bin bpf_dbg
46 '';
47
48 meta = with lib; {
49 description = "Debugging/program analysis tools for the eBPF subsystem";
50 license = [ licenses.gpl2 licenses.bsd2 ];
51 platforms = platforms.linux;
52 maintainers = with maintainers; [ thoughtpolice ];
53 };
54}