about summary refs log tree commit diff
path: root/pkgs/by-name/pw
diff options
context:
space:
mode:
authorJörg Thalheim <joerg@thalheim.io>2024-04-29 08:42:36 +0200
committerJörg Thalheim <joerg@thalheim.io>2024-04-29 09:53:30 +0200
commit86c2fc34064f9ac1c04feaed011a1c34f50ec9a0 (patch)
tree43423698d88e1505555028f6a81cf2d14c0d8e51 /pkgs/by-name/pw
parentba1e6fdd89c3c2d88514c92188a52179a6dbe75c (diff)
pwngdb: make gdbinit.py self-contained
This avoids polluting child processes with PYTHONPATH (also PATH is
still propagated).
Also it makes it easier to load the resulting gdbinit.py in your own
.gdbinit.
Diffstat (limited to 'pkgs/by-name/pw')
-rw-r--r--pkgs/by-name/pw/pwndbg/package.nix22
1 files changed, 17 insertions, 5 deletions
diff --git a/pkgs/by-name/pw/pwndbg/package.nix b/pkgs/by-name/pw/pwndbg/package.nix
index 2967130b7fd10..473a401ce1c54 100644
--- a/pkgs/by-name/pw/pwndbg/package.nix
+++ b/pkgs/by-name/pw/pwndbg/package.nix
@@ -18,7 +18,7 @@ let
     python3.pkgs.ropgadget # ref: https://github.com/pwndbg/pwndbg/blob/2022.12.19/pwndbg/commands/rop.py#L32
   ]);
 in
-stdenv.mkDerivation rec {
+stdenv.mkDerivation {
   pname = "pwndbg";
   version = lib.getVersion pwndbg-py;
   format = "other";
@@ -31,20 +31,32 @@ stdenv.mkDerivation rec {
     runHook preInstall
 
     mkdir -p $out/share/pwndbg
-    cp gdbinit.py $out/share/pwndbg
+    cp gdbinit.py $out/share/pwndbg/gdbinit.py
     chmod +x $out/share/pwndbg/gdbinit.py
+    # First line is a import from future, so we need to append our imports after that
+    sed '2 i import sys, os
+    3 i [sys.path.append(p) for p in "${pythonPath}".split(":")]
+    4 i os.environ["PATH"] += ":${binPath}"' -i $out/share/pwndbg/gdbinit.py
 
     # Don't require an in-package venv
     touch $out/share/pwndbg/.skip-venv
 
     makeWrapper ${gdb}/bin/gdb $out/bin/pwndbg \
-      --add-flags "-q -x $out/share/pwndbg/gdbinit.py" \
-      --prefix PATH : ${binPath} \
-      --set PYTHONPATH ${pythonPath} \
+      --add-flags "-q -x $out/share/pwndbg/gdbinit.py"
 
     runHook postInstall
   '';
 
+  doInstallCheck = true;
+  installCheckPhase = ''
+    runHook preInstallCheck
+
+    # Check if pwndbg is installed correctly
+    HOME=$TMPDIR LC_CTYPE=C.UTF-8 $out/bin/pwndbg -ex exit
+
+    runHook postInstallCheck
+  '';
+
   meta = with lib; {
     description = "Exploit Development and Reverse Engineering with GDB Made Easy";
     mainProgram = "pwndbg";