Merge pull request #329823 from ExpidusOS/fix/pkgsllvm/elfutils
[NixPkgs.git] / pkgs / by-name / bp / bpftrace / package.nix
blobf1dc1bb4fd7dc37c1a4e41edef69e2096b367511
1 { lib, stdenv, fetchFromGitHub
2 , llvmPackages, elfutils, bcc
3 , libbpf, libbfd, libopcodes, glibc
4 , cereal, asciidoctor
5 , cmake, pkg-config, flex, bison
6 , util-linux
7 , fetchpatch
8 , nixosTests
9 }:
11 stdenv.mkDerivation rec {
12   pname = "bpftrace";
13   version = "0.21.2";
15   src = fetchFromGitHub {
16     owner = "iovisor";
17     repo  = "bpftrace";
18     rev   = "v${version}";
19     hash  = "sha256-/2m+5iFE7R+ZEc/VcgWAhkLD/jEK88roUUOUyYODi0U=";
20   };
23   buildInputs = with llvmPackages; [
24     llvm libclang
25     elfutils bcc
26     libbpf libbfd libopcodes
27     cereal asciidoctor
28   ];
30   nativeBuildInputs = [
31     cmake pkg-config flex bison
32     llvmPackages.llvm.dev
33     util-linux
34   ];
36   # tests aren't built, due to gtest shenanigans. see:
37   #
38   #     https://github.com/iovisor/bpftrace/issues/161#issuecomment-453606728
39   #     https://github.com/iovisor/bpftrace/pull/363
40   #
41   cmakeFlags = [
42     "-DBUILD_TESTING=FALSE"
43     "-DLIBBCC_INCLUDE_DIRS=${bcc}/include"
44     "-DINSTALL_TOOL_DOCS=OFF"
45     "-DSYSTEM_INCLUDE_PATHS=${glibc.dev}/include"
46   ];
48   patches = [
49     (fetchpatch {
50       name = "runqlat-bt-no-includes.patch";
51       url = "https://github.com/bpftrace/bpftrace/pull/3262.patch";
52       hash = "sha256-9yqaZeG1Uf2cC9Aa40c2QUTQRl8n2NO1nq278hf9P4M=";
53     })
54     (fetchpatch {
55       name = "kheaders-not-found-message-only-on-error.patch";
56       url = "https://github.com/bpftrace/bpftrace/pull/3265.patch";
57       hash = "sha256-8AICMzwq5Evy9+hmZhFjccw/HmgZ9t+YIoHApjLv6Uc=";
58       excludes = [ "CHANGELOG.md" ];
59     })
60   ];
62   # Pull BPF scripts into $PATH (next to their bcc program equivalents), but do
63   # not move them to keep `${pkgs.bpftrace}/share/bpftrace/tools/...` working.
64   postInstall = ''
65     ln -sr $out/share/bpftrace/tools/*.bt $out/bin/
66     # do not use /usr/bin/env for shipped tools
67     # If someone can get patchShebangs to work here please fix.
68     sed -i -e "1s:#!/usr/bin/env bpftrace:#!$out/bin/bpftrace:" $out/share/bpftrace/tools/*.bt
69   '';
71   outputs = [ "out" "man" ];
73   passthru.tests = {
74     bpf = nixosTests.bpf;
75   };
77   meta = with lib; {
78     description = "High-level tracing language for Linux eBPF";
79     homepage    = "https://github.com/iovisor/bpftrace";
80     changelog   = "https://github.com/iovisor/bpftrace/releases/tag/v${version}";
81     mainProgram = "bpftrace";
82     license     = licenses.asl20;
83     maintainers = with maintainers; [ rvl thoughtpolice martinetd mfrw ];
84     platforms   = platforms.linux;
85   };