18 stdenv.mkDerivation rec {
22 src = fetchFromGitHub {
26 hash = "sha256-Y2ceE0F7q5tP64Mtvkc7JHOZQN30MDVCPHfiWDnfTSQ=";
27 fetchSubmodules = true;
30 # LD_PRELOAD wrappers need to be statically linked to work against all kinds
31 # of games -- so it's fine to use e.g. bundled snappy.
32 buildInputs = [ libX11 procps python3 libdwarf qtbase gtest brotli ];
34 nativeBuildInputs = [ cmake pkg-config wrapQtAppsHook ];
36 # Don't automatically wrap all binaries, I prefer to explicitly only wrap
38 dontWrapQtApps = true;
42 # Since https://github.com/NixOS/nixpkgs/pull/60985, we add `/run-opengl-driver[-32]`
43 # to the `RUNPATH` of dispatcher libraries `dlopen()` ing OpenGL drivers.
44 # `RUNPATH` doesn't propagate throughout the whole application, but only
45 # from the module performing the `dlopen()`.
47 # Apitrace wraps programs by running them with `LD_PRELOAD` pointing to `.so`
48 # files in $out/lib/apitrace/wrappers.
50 # Theses wrappers effectively wrap the `dlopen()` calls from `libglvnd`
51 # and other dispatcher libraries, and run `dlopen()` by themselves.
53 # As `RUNPATH` doesn't propagate through the whole library, and they're now the
54 # library doing the real `dlopen()`, they also need to have
55 # `/run-opengl-driver[-32]` added to their `RUNPATH`.
57 # To stay simple, we add paths for 32 and 64 bits unconditionally.
58 # This doesn't have an impact on closure size, and if the 32 bit drivers
59 # are not available, that folder is ignored.
60 for i in $out/lib/apitrace/wrappers/*.so
62 echo "Patching OpenGL driver path for $i"
63 patchelf --set-rpath "/run/opengl-driver/lib:/run/opengl-driver-32/lib:$(patchelf --print-rpath $i)" $i
66 # Theses open the OpenGL driver at runtime, but it is not listed as NEEDED libraries. They need
67 # a reference to libglvnd.
68 for i in $out/bin/eglretrace $out/bin/glretrace
70 echo "Patching RPath for $i"
71 patchelf --set-rpath "${lib.makeLibraryPath [libglvnd]}:$(patchelf --print-rpath $i)" $i
74 wrapQtApp $out/bin/qapitrace
78 homepage = "https://apitrace.github.io";
79 description = "Tools to trace OpenGL, OpenGL ES, Direct3D, and DirectDraw APIs";
80 license = licenses.mit;
81 platforms = platforms.linux;