1{ fetchgit, pkgconfig, gettext, runCommand, makeWrapper
2, elfutils, kernel, gnumake, python2, python2Packages
3}:
4
5let
6 ## fetchgit info
7 url = git://sourceware.org/git/systemtap.git;
8 rev = "4051c70c9318c837981384cbb23f3e9eb1bd0892";
9 sha256 = "0sd8n3j3rishks3gyqj2jyqhps7hmlfjyz8i0w8v98cczhhh04rq";
10 version = "2017.10.18";
11
12 inherit (kernel) stdenv;
13 inherit (stdenv) lib;
14
15 ## stap binaries
16 stapBuild = stdenv.mkDerivation {
17 name = "systemtap-${version}";
18 src = fetchgit { inherit url rev sha256; };
19 nativeBuildInputs = [ pkgconfig ];
20 buildInputs = [ elfutils gettext python2 python2Packages.setuptools ];
21 # FIXME: Workaround for bug in kbuild, where quoted -I"/foo" flags would get mangled in out-of-tree kbuild dirs
22 postPatch = ''
23 substituteInPlace buildrun.cxx --replace \
24 'o << "EXTRA_CFLAGS += -I\"" << s.runtime_path << "\"" << endl;' \
25 'o << "EXTRA_CFLAGS += -I" << s.runtime_path << endl;'
26 '';
27 enableParallelBuilding = true;
28 };
29
30 ## a kernel build dir as expected by systemtap
31 kernelBuildDir = runCommand "kbuild-${kernel.version}-merged" { } ''
32 mkdir -p $out
33 for f in \
34 ${kernel}/System.map \
35 ${kernel.dev}/vmlinux \
36 ${kernel.dev}/lib/modules/${kernel.modDirVersion}/build/{*,.*}
37 do
38 ln -s $(readlink -f $f) $out
39 done
40 '';
41
42 pypkgs = with python2Packages; makePythonPath [ pyparsing ];
43
44in runCommand "systemtap-${kernel.version}-${version}" {
45 inherit stapBuild kernelBuildDir;
46 buildInputs = [ makeWrapper ];
47 meta = {
48 homepage = https://sourceware.org/systemtap/;
49 repositories.git = url;
50 description = "Provides a scripting language for instrumentation on a live kernel plus user-space";
51 license = lib.licenses.gpl2;
52 platforms = lib.platforms.linux;
53 };
54} ''
55 mkdir -p $out/bin
56 for bin in $stapBuild/bin/*; do # hello emacs */
57 ln -s $bin $out/bin
58 done
59 rm $out/bin/stap $out/bin/dtrace
60 makeWrapper $stapBuild/bin/stap $out/bin/stap \
61 --add-flags "-r $kernelBuildDir" \
62 --prefix PATH : ${lib.makeBinPath [ stdenv.cc.cc stdenv.cc.bintools elfutils gnumake ]}
63 makeWrapper $stapBuild/bin/dtrace $out/bin/dtrace \
64 --prefix PYTHONPATH : ${pypkgs}
65''