1{ lib, stdenv, fetchFromGitHub, fetchpatch
2, cmake, pkg-config, which, makeWrapper
3, libpfm, zlib, python3Packages, procps, gdb, capnproto
4}:
5
6stdenv.mkDerivation rec {
7 version = "5.6.0";
8 pname = "rr";
9
10 src = fetchFromGitHub {
11 owner = "mozilla";
12 repo = "rr";
13 rev = version;
14 sha256 = "H39HPkAQGubXVQV3jCpH4Pz+7Q9n03PrS70utk7Tt2k=";
15 };
16
17 patches = [
18 (fetchpatch {
19 name = "fix-flexible-array-member.patch";
20 url = "https://github.com/rr-debugger/rr/commit/2979c60ef8bbf7c940afd90172ddc5d8863f766e.diff";
21 sha256 = "cmdCJetQr3ELPOyWl37h1fGfG/xvaiJpywxIAnqb5YY=";
22 })
23 ];
24
25 postPatch = ''
26 substituteInPlace src/Command.cc --replace '_BSD_SOURCE' '_DEFAULT_SOURCE'
27 sed '7i#include <math.h>' -i src/Scheduler.cc
28 sed '1i#include <ctime>' -i src/test-monitor/test-monitor.cc
29 patchShebangs .
30 '';
31
32 # With LTO enabled, linking fails with the following message:
33 #
34 # src/AddressSpace.cc:1666: undefined reference to `rr_syscall_addr'
35 # ld.bfd: bin/rr: hidden symbol `rr_syscall_addr' isn't defined
36 # ld.bfd: final link failed: bad value
37 # collect2: error: ld returned 1 exit status
38 #
39 # See also https://github.com/NixOS/nixpkgs/pull/110846
40 preConfigure = ''substituteInPlace CMakeLists.txt --replace "-flto" ""'';
41
42 nativeBuildInputs = [ cmake pkg-config which makeWrapper ];
43 buildInputs = [
44 libpfm zlib python3Packages.python python3Packages.pexpect procps gdb capnproto
45 libpfm zlib python3Packages.python python3Packages.pexpect procps capnproto
46 ];
47 cmakeFlags = [
48 "-Ddisable32bit=ON"
49 ];
50
51 # we turn on additional warnings due to hardening
52 env.NIX_CFLAGS_COMPILE = "-Wno-error";
53
54 hardeningDisable = [ "fortify" ];
55
56 # FIXME
57 #doCheck = true;
58
59 preCheck = "export HOME=$TMPDIR";
60
61 # needs GDB to replay programs at runtime
62 preFixup = ''
63 wrapProgram "$out/bin/rr" \
64 --prefix PATH ":" "${lib.makeBinPath [
65 gdb
66 ]}";
67 '';
68
69 meta = {
70 homepage = "https://rr-project.org/";
71 description = "Records nondeterministic executions and debugs them deterministically";
72 longDescription = ''
73 rr aspires to be your primary debugging tool, replacing -- well,
74 enhancing -- gdb. You record a failure once, then debug the
75 recording, deterministically, as many times as you want. Every
76 time the same execution is replayed.
77 '';
78
79 license = with lib.licenses; [ mit bsd2 ];
80 maintainers = with lib.maintainers; [ pierron thoughtpolice ];
81 platforms = [ "i686-linux" "x86_64-linux" "aarch64-linux" ];
82 };
83}