1{
2 lib,
3 runCommand,
4 makeWrapper,
5 systemtap-unwrapped,
6 elfutils,
7 kernel,
8 gnumake,
9 python3,
10 nixosTests,
11 withStap ? true, # avoid cyclic dependency with glib, reduce closure size substantially
12}:
13
14let
15 inherit (kernel) stdenv;
16
17 ## symlink farm for --sysroot flag
18 sysroot = runCommand "systemtap-sysroot-${kernel.version}" { } ''
19 mkdir -p $out/boot $out/usr/lib/debug
20 ln -s ${kernel.dev}/vmlinux ${kernel.dev}/lib $out
21 ln -s ${kernel.dev}/vmlinux $out/usr/lib/debug
22 ln -s ${kernel}/System.map $out/boot/System.map-${kernel.version}
23 '';
24
25 pypkgs = with python3.pkgs; makePythonPath [ pyparsing ];
26
27in
28runCommand "systemtap-${systemtap-unwrapped.version}"
29 {
30 stapBuild = systemtap-unwrapped;
31 nativeBuildInputs = [ makeWrapper ];
32 passthru.tests = { inherit (nixosTests.systemtap) linux_default linux_latest; };
33 inherit (systemtap-unwrapped) meta;
34 }
35 (
36 ''
37 mkdir -p $out/bin
38 for bin in $stapBuild/bin/*; do
39 ln -s $bin $out/bin
40 done
41 rm $out/bin/stap $out/bin/dtrace
42 makeWrapper $stapBuild/bin/dtrace $out/bin/dtrace \
43 --prefix PYTHONPATH : ${pypkgs}
44 ''
45 + lib.optionalString withStap ''
46 makeWrapper $stapBuild/bin/stap $out/bin/stap \
47 --add-flags "--sysroot ${sysroot}" \
48 --prefix PATH : ${
49 lib.makeBinPath [
50 stdenv.cc.cc
51 stdenv.cc.bintools
52 elfutils
53 gnumake
54 ]
55 }
56 ''
57 )