about summary refs log tree commit diff
path: root/pkgs/development/tools/profiling/systemtap/default.nix
blob: a16bdbc539a9108fe915d7fe60ce1e7e713c1c35 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{ fetchgit, pkgconfig, gettext, runCommand, makeWrapper
, elfutils, kernel, gnumake, python2, pythonPackages, binutils }:
let
  ## fetchgit info
  url = git://sourceware.org/git/systemtap.git;
  rev = "276ed27a3cc64531542ab73bb36bb04784e79bbc";
  sha256 = "11967dx3cjs96v3ncfljw0h7blsgg9wm8g9z2270q9a90988g2c2";
  version = "2017-02-04";

  inherit (kernel) stdenv;
  inherit (stdenv) lib;

  ## stap binaries
  stapBuild = stdenv.mkDerivation {
    name = "systemtap-${version}";
    src = fetchgit { inherit url rev sha256; };
    buildInputs = [ elfutils pkgconfig gettext python2 pythonPackages.setuptools ];
    # FIXME: Workaround for bug in kbuild, where quoted -I"/foo" flags would get mangled in out-of-tree kbuild dirs
    postPatch = ''
      substituteInPlace buildrun.cxx --replace \
        'o << "EXTRA_CFLAGS += -I\"" << s.runtime_path << "\"" << endl;' \
        'o << "EXTRA_CFLAGS += -I" << s.runtime_path << endl;'
    '';
    enableParallelBuilding = true;
  };

  ## a kernel build dir as expected by systemtap
  kernelBuildDir = runCommand "kbuild-${kernel.version}-merged" { } ''
    mkdir -p $out
    for f in \
        ${kernel}/System.map \
        ${kernel.dev}/vmlinux \
        ${kernel.dev}/lib/modules/${kernel.modDirVersion}/build/{*,.*}
    do
      ln -s $(readlink -f $f) $out
    done
  '';

in runCommand "systemtap-${kernel.version}-${version}" {
  inherit stapBuild kernelBuildDir;
  buildInputs = [ makeWrapper ];
  meta = {
    homepage = https://sourceware.org/systemtap/;
    repositories.git = url;
    description = "Provides a scripting language for instrumentation on a live kernel plus user-space";
    license = lib.licenses.gpl2;
    platforms = lib.platforms.linux;
  };
} ''
  mkdir -p $out/bin
  for bin in $stapBuild/bin/*; do # hello emacs */
    ln -s $bin $out/bin
  done
  rm $out/bin/stap
  makeWrapper $stapBuild/bin/stap $out/bin/stap \
    --add-flags "-r $kernelBuildDir" \
    --prefix PATH : ${lib.makeBinPath [ stdenv.cc.cc binutils elfutils gnumake ]}
''