diff --git a/flake.nix b/flake.nix index 626eb4aa0..be42bc459 100644 --- a/flake.nix +++ b/flake.nix @@ -86,39 +86,9 @@ inherit system; overlays = [ (final: prev: { - pwndbg_gdb = prev.gdb; - pwndbg_lldb = prev.lldb_20; libffi_portable = null; }) - (final: prev: { - # Dynamic libiconv causes issues with our portable build. - # It reads /some-path/lib/gconv/gconv-modules.d/gconv-modules-extra.conf, - # then loads /some-path/lib/gconv/UTF-32.so dynamically. - pwndbg_gdb = - let - libiconv = prev.pkgsStatic.libiconvReal; - in - (prev.pwndbg_gdb.override { - inherit libiconv; - }).overrideAttrs - (old: { - buildInputs = old.buildInputs ++ [ libiconv ]; - }); - }) - ( - final: prev: - nixpkgs.lib.optionalAttrs - (prev.stdenv.targetPlatform.isPower64 && prev.stdenv.targetPlatform.isLittleEndian) - { - # new boost is broken: https://github.com/NixOS/nixpkgs/issues/382179 - boost = prev.boost183; - } - ) overlayDarwin - (final: prev: { - pwndbg_gdb = import ./nix/overlay/gdb.nix { prev = prev; }; - pwndbg_lldb = import ./nix/overlay/lldb.nix { prev = prev; }; - }) ]; } ); @@ -171,10 +141,12 @@ pwndbg = import ./nix/pwndbg.nix { pkgs = pkgsBySystem.${system}; inputs = inputs; + groups = [ "gdb" ]; }; pwndbg-dev = import ./nix/pwndbg.nix { pkgs = pkgsBySystem.${system}; inputs = inputs; + groups = [ "gdb" ]; isDev = true; }; } @@ -184,13 +156,13 @@ pwndbg-lldb = import ./nix/pwndbg.nix { pkgs = pkgsBySystem.${system}; inputs = inputs; - isLLDB = true; + groups = [ "lldb" ]; }; pwndbg-lldb-dev = import ./nix/pwndbg.nix { pkgs = pkgsBySystem.${system}; inputs = inputs; + groups = [ "lldb" ]; isDev = true; - isLLDB = true; }; } ); @@ -198,7 +170,7 @@ system: cross: attrs: (pkgUtil.${system}.buildPackageTarball { drv = ( - import ./nix/portable.nix { + (import ./nix/portable.nix { pkgs = pkgsBySystem.${system}.pkgsCross.${crossNames.${cross}}; pwndbg = ( import ./nix/pwndbg.nix ( @@ -209,7 +181,7 @@ // attrs ) ); - } + }) ); }); crossDrvs = @@ -217,11 +189,11 @@ nixpkgs.lib.optionalAttrs pkgsBySystem.${system}.stdenv.isLinux ( (nixpkgs.lib.attrsets.mapAttrs' (cross: value: { name = "pwndbg-gdb-cross-${cross}-tarball"; - value = tarballCrossDrv system cross { }; + value = tarballCrossDrv system cross { groups = [ "gdb" ]; }; }) crossNames) // (nixpkgs.lib.attrsets.mapAttrs' (cross: value: { name = "pwndbg-lldb-cross-${cross}-tarball"; - value = tarballCrossDrv system cross { isLLDB = true; }; + value = tarballCrossDrv system cross { groups = [ "lldb" ]; }; }) crossNames) ); in @@ -243,7 +215,6 @@ import ./nix/devshell.nix { pkgs = pkgsBySystem.${system}; inputs = inputs; - isLLDB = true; } ); formatter = forAllSystems (system: pkgsBySystem.${system}.nixfmt-tree); diff --git a/nix/bundle/bundle.py b/nix/bundle/bundle.py index 7b871a95b..e5b859101 100755 --- a/nix/bundle/bundle.py +++ b/nix/bundle/bundle.py @@ -365,7 +365,7 @@ def bundle_library(binary_path: Path, root_dst: Path, *, is_exe: bool, dst_path: def bundle_python_venv(src_lib_dir: Path, out_lib_dir: Path, root_dst: Path): - bundle_binaries = set() + bundle_libs = set() for _, files in iter_dir_recursive(src_lib_dir): for src_file_path in files: # search for so files: @@ -379,9 +379,9 @@ def bundle_python_venv(src_lib_dir: Path, out_lib_dir: Path, root_dst: Path): real_file = copy_with_symlink_normal(src_file_path, src_lib_dir, out_lib_dir, is_so=is_so) if is_so and real_file: - bundle_binaries.add(real_file) + bundle_libs.add(real_file) - for file in bundle_binaries: + for file in bundle_libs: bundle_library(file, root_dst, is_exe=False) diff --git a/nix/devshell.nix b/nix/devshell.nix index bbb235ff1..f1a5597dc 100644 --- a/nix/devshell.nix +++ b/nix/devshell.nix @@ -11,7 +11,6 @@ import nixpkgs { overlays = [ ]; }, python3 ? pkgs.python3, inputs ? null, - isLLDB ? false, ... }: let @@ -22,10 +21,13 @@ let lib python3 inputs - isLLDB ; isDev = true; isEditable = true; + groups = [ + "lldb" + "gdb" + ]; }; jemalloc-static = pkgs.jemalloc.overrideAttrs ( finalAttrs: previousAttrs: { @@ -74,11 +76,7 @@ in } ++ [ jemalloc-static - pkgs.gdb pyEnv - ] - ++ pkgs.lib.optionals isLLDB [ - pkgs.lldb_20 ]; shellHook = '' # lldb looks for the `debugserver` binary in `DEVELOPER_DIR`, diff --git a/nix/overlay/gdb-fix-cross-python.patch b/nix/overlay/gdb-fix-cross-python.patch deleted file mode 100644 index 9dec2104d..000000000 --- a/nix/overlay/gdb-fix-cross-python.patch +++ /dev/null @@ -1,55 +0,0 @@ ---- a/gdb/python/python-config.py (revision fa93e88f754e10dfb60dd4c9bf9cef858d4c7e4a) -+++ b/gdb/python/python-config.py (revision 1605cab3f0f578a75778efdc4c380bbb8463ad6f) -@@ -1,6 +1,15 @@ - # Program to fetch python compilation parameters. - # Copied from python-config of the 2.7 release. - -+# In this script, we should only use the following to retrieve configuration values: -+# - `sysconfig.get_config_var` -+# - `sysconfig.get_platform` -+# This is because certain variables may return invalid data during cross-compilation, for example: -+# - sys.prefix -> Use sysconfig.get_config_var("prefix") instead. -+# - sysconfig.get_path("include") -> Don't use, it may return paths for native python, not our target python -+# - os.name -> Use sysconfig.get_platform() for platform detection. -+ -+ - import getopt - import os - import sys -@@ -26,7 +35,7 @@ - - pyver = sysconfig.get_config_var("VERSION") - getvar = sysconfig.get_config_var --abiflags = getattr(sys, "abiflags", "") -+abiflags = getvar("ABIFLAGS") - - opt_flags = [flag for (flag, val) in opts] - -@@ -49,15 +58,14 @@ - - for opt in opt_flags: - if opt == "--prefix": -- print(to_unix_path(os.path.normpath(sys.prefix))) -+ print(to_unix_path(os.path.normpath(getvar("prefix")))) - - elif opt == "--exec-prefix": -- print(to_unix_path(os.path.normpath(sys.exec_prefix))) -+ print(to_unix_path(os.path.normpath(getvar("exec_prefix")))) - - elif opt in ("--includes", "--cflags"): - flags = [ -- "-I" + sysconfig.get_path("include"), -- "-I" + sysconfig.get_path("platinclude"), -+ "-I" + getvar("INCLUDEPY"), - ] - if opt == "--cflags": - flags.extend(getvar("CFLAGS").split()) -@@ -76,7 +84,7 @@ - if getvar("LIBPL") is not None: - libs.insert(0, "-L" + getvar("LIBPL")) - elif os.name == "nt": -- libs.insert(0, "-L" + os.path.normpath(sys.prefix) + "/libs") -+ libs.insert(0, "-L" + os.path.normpath(getvar("prefix")) + "/libs") - if getvar("LINKFORSHARED") is not None: - libs.extend(getvar("LINKFORSHARED").split()) - print(to_unix_path(" ".join(libs))) \ No newline at end of file diff --git a/nix/overlay/gdb.nix b/nix/overlay/gdb.nix deleted file mode 100644 index 0cdf7b22e..000000000 --- a/nix/overlay/gdb.nix +++ /dev/null @@ -1,22 +0,0 @@ -{ - prev, - ... -}: -let - # Copied from: https://github.com/NixOS/nixpkgs/pull/275731 - isCross = prev.stdenv.hostPlatform != prev.stdenv.buildPlatform; - - drv = - if !isCross then - prev.pwndbg_gdb - else - (prev.pwndbg_gdb.override { pythonSupport = true; }).overrideAttrs (old: { - patches = (old.patches or [ ]) ++ [ - ./gdb-fix-cross-python.patch - ]; - configureFlags = (old.configureFlags ++ [ ]) ++ [ - "--with-python=${prev.python3.pythonOnBuildForHost.interpreter}" - ]; - }); -in -drv diff --git a/nix/overlay/lldb-fix-cross-python.patch b/nix/overlay/lldb-fix-cross-python.patch deleted file mode 100644 index 343e3c210..000000000 --- a/nix/overlay/lldb-fix-cross-python.patch +++ /dev/null @@ -1,107 +0,0 @@ -Subject: [PATCH] test1 ---- -Index: lldb/CMakeLists.txt -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -=================================================================== -diff --git a/CMakeLists.txt b/CMakeLists.txt ---- a/CMakeLists.txt (revision 4740e097031d231cd39680c16a31771d22fe84c9) -+++ b/CMakeLists.txt (date 1739005831013) -@@ -60,7 +60,7 @@ - "Filename extension for native code python modules") - - foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH LLDB_PYTHON_EXT_SUFFIX) -- if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING) -+ if(NOT DEFINED ${var}) - execute_process( - COMMAND ${Python3_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/get-python-config.py -Index: lldb/bindings/python/get-python-config.py -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -=================================================================== -diff --git a/bindings/python/get-python-config.py b/bindings/python/get-python-config.py ---- a/bindings/python/get-python-config.py (revision 4740e097031d231cd39680c16a31771d22fe84c9) -+++ b/bindings/python/get-python-config.py (date 1738953843941) -@@ -1,5 +1,14 @@ - #!/usr/bin/env python3 - -+# In this script, we should only use the following to retrieve configuration values: -+# - `sysconfig.get_config_var` -+# - `sysconfig.get_platform` -+# - `sysconfig.get_path` -+# This is because certain variables may return invalid data during cross-compilation, for example: -+# - sys.prefix -> Use sysconfig.get_config_var("prefix") instead. -+# - sys.executable -> Use sysconfig.get_config_var("EXENAME") instead. -+# - os.name -> Use sysconfig.get_platform() for platform detection. -+ - import os - import sys - import argparse -@@ -32,20 +41,25 @@ - # If not, you'll have to use lldb -P or lldb -print-script-interpreter-info - # to figure out where it is. - try: -- print(relpath_nodots(sysconfig.get_path("platlib"), sys.prefix)) -+ print(relpath_nodots(sysconfig.get_path("platlib"), sysconfig.get_config_var("prefix"))) - except ValueError: - # Try to fall back to something reasonable if sysconfig's platlib - # is outside of sys.prefix - if os.name == "posix": -- print("lib/python%d.%d/site-packages" % sys.version_info[:2]) -+ print("lib/python%s/site-packages" % sysconfig.get_config_var("VERSION")) - elif os.name == "nt": - print("Lib\\site-packages") - else: - raise - elif args.variable_name == "LLDB_PYTHON_EXE_RELATIVE_PATH": - tried = list() -- exe = sys.executable -- prefix = os.path.realpath(sys.prefix) -+ exe = sysconfig.get_config_var("EXENAME") -+ if not exe: -+ # Fallback: 'EXENAME' is not available on Windows -+ exe_name = "python" + sysconfig.get_config_var("VERSION") + sysconfig.get_config_var("EXE") -+ exe = os.path.join(sysconfig.get_config_var("BINDIR"), exe_name) -+ -+ prefix = os.path.realpath(sysconfig.get_config_var("prefix")) - while True: - try: - print(relpath_nodots(exe, prefix)) -@@ -59,13 +73,13 @@ - continue - else: - print( -- "Could not find a relative path to sys.executable under sys.prefix", -+ "Could not find a relative path to sysconfig.get_config_var(\"EXENAME\") under sysconfig.get_config_var(\"prefix\")", - file=sys.stderr, - ) - for e in tried: - print("tried:", e, file=sys.stderr) -- print("realpath(sys.prefix):", prefix, file=sys.stderr) -- print("sys.prefix:", sys.prefix, file=sys.stderr) -+ print("realpath(sysconfig.get_config_var(\"prefix\")):", prefix, file=sys.stderr) -+ print("sysconfig.get_config_var(\"prefix\"):", sysconfig.get_config_var("prefix"), file=sys.stderr) - sys.exit(1) - elif args.variable_name == "LLDB_PYTHON_EXT_SUFFIX": - print(sysconfig.get_config_var("EXT_SUFFIX")) -Index: lldb/cmake/modules/FindPythonAndSwig.cmake -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -=================================================================== -diff --git a/cmake/modules/FindPythonAndSwig.cmake b/cmake/modules/FindPythonAndSwig.cmake ---- a/cmake/modules/FindPythonAndSwig.cmake (revision 4740e097031d231cd39680c16a31771d22fe84c9) -+++ b/cmake/modules/FindPythonAndSwig.cmake (date 1739019752496) -@@ -8,6 +8,9 @@ - # Use PYTHON_HOME as a hint to find Python 3. - set(Python3_ROOT_DIR "${PYTHON_HOME}") - find_package(Python3 COMPONENTS Interpreter Development) -+ if (DEFINED Python3_EXECUTABLE_NATIVE) -+ set(Python3_EXECUTABLE "${Python3_EXECUTABLE_NATIVE}" CACHE STRING "Native Python3 executable" FORCE) -+ endif() - if(Python3_FOUND AND Python3_Interpreter_FOUND) - - # The install name for the Python 3 framework in Xcode is relative to diff --git a/nix/overlay/lldb.nix b/nix/overlay/lldb.nix deleted file mode 100644 index 61d04ef19..000000000 --- a/nix/overlay/lldb.nix +++ /dev/null @@ -1,65 +0,0 @@ -{ - prev, - ... -}: -let - # Copied from: https://github.com/NixOS/nixpkgs/pull/375484 - isCross = prev.stdenv.hostPlatform != prev.stdenv.buildPlatform; - lib = prev.lib; - - tblgen = prev.pkgsBuildHost.callPackage ./tblgen.nix { - release_version = builtins.elemAt (lib.strings.splitString "." prev.pwndbg_lldb.version) 0; - version = prev.pwndbg_lldb.version; - monorepoSrc = prev.pwndbg_lldb.passthru.monorepoSrc; - }; - - drv = - if !isCross then - prev.pwndbg_lldb - else - prev.callPackage ( - { - llvmPackages, - llvmPackages_20, - cmake, - which, - swig, - lit, - makeWrapper, - ninja, - python3, - lua5_3, - }: - (prev.pwndbg_lldb.override { - stdenv = llvmPackages.stdenv; - # Out-of-memory when building with debuginfo enabled.. build use more than 32gb+ ram - libclang = llvmPackages_20.libclang.overrideAttrs (old: { - separateDebugInfo = false; - }); - }).overrideAttrs - (old: { - patches = (old.patches or [ ]) ++ [ - ./lldb-fix-cross-python.patch - ]; - nativeBuildInputs = [ - cmake - which - swig - makeWrapper - ninja - ]; - buildInputs = (old.buildInputs ++ [ ]) ++ [ - python3 - lua5_3 - ]; - cmakeFlags = (old.cmakeFlags ++ [ ]) ++ [ - "-DPYTHON_HOME=${python3}" - "-DPython3_EXECUTABLE_NATIVE=${python3.pythonOnBuildForHost.interpreter}" - "-DLLVM_TABLEGEN=${tblgen}/bin/llvm-tblgen" - "-DCLANG_TABLEGEN=${tblgen}/bin/clang-tblgen" - "-DLLDB_TABLEGEN_EXE=${tblgen}/bin/lldb-tblgen" - ]; - }) - ) { }; -in -drv diff --git a/nix/overlay/tblgen.nix b/nix/overlay/tblgen.nix deleted file mode 100644 index 7063896bd..000000000 --- a/nix/overlay/tblgen.nix +++ /dev/null @@ -1,134 +0,0 @@ -# Copied from: https://github.com/NixOS/nixpkgs/pull/377225 -{ - cmake, - devExtraCmakeFlags ? [ ], - lib, - monorepoSrc ? null, - ninja, - patches ? [ ], - python3, - release_version, - runCommand, - src ? null, - stdenv, - version, - clangPatches ? [ ], -}: - -let - # This is a synthetic package which is not an official part of the llvm-project. - # See https://github.com/NixOS/nixpkgs/pull/362384 for discussion. - # - # LLVM has tools that run at build time. In native builds, these are - # built as a part of the usual build, but in cross builds they need to - # come from buildPackages. - # - # In many scenarios this is a small problem because LLVM from - # buildPackages is already available as a build; but if cross building a - # version of LLVM which is not available (e.g. a new git commit of LLVM) - # this results in two builds of LLVM and clang, one native and one for the - # cross. - # - # Full builds of LLVM are expensive; and unnecessary in this scenario. We - # don't need a native LLVM, only a native copy of the tools which run at - # build time. This is only tablegen and related tooling, which are cheap - # to build. - pname = "llvm-tblgen"; - - src' = - if monorepoSrc != null then - runCommand "${pname}-src-${version}" { } ( - '' - mkdir -p "$out" - '' - + lib.optionalString (lib.versionAtLeast release_version "14") '' - cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/third-party "$out" - '' - + '' - cp -r ${monorepoSrc}/llvm "$out" - cp -r ${monorepoSrc}/clang "$out" - cp -r ${monorepoSrc}/clang-tools-extra "$out" - cp -r ${monorepoSrc}/mlir "$out" - cp -r ${monorepoSrc}/lldb "$out" - '' - ) - else - src; - - self = stdenv.mkDerivation (finalAttrs: rec { - inherit pname version patches; - - src = src'; - sourceRoot = "${src.name}/llvm"; - - postPatch = '' - ( - cd ../clang - chmod u+rwX -R . - for p in ${toString clangPatches} - do - patch -p1 < $p - done - ) - ''; - - nativeBuildInputs = [ - cmake - ninja - python3 - ]; - - cmakeFlags = [ - # Projects with tablegen-like tools. - "-DLLVM_ENABLE_PROJECTS=${ - lib.concatStringsSep ";" ( - [ - "llvm" - "clang" - "clang-tools-extra" - "lldb" - ] - ++ lib.optionals (lib.versionAtLeast release_version "16") [ - "mlir" - ] - ) - }" - ] - # LLDB test suite requires libc++ on darwin, but we need compile only lldb-tblgen - # These flags are needed only for evaluating the CMake file. - ++ lib.optionals stdenv.hostPlatform.isDarwin [ - "-DLLDB_INCLUDE_TESTS=OFF" - "-DLIBXML2_INCLUDE_DIR=/non-existent" - ] - ++ devExtraCmakeFlags; - - # List of tablegen targets. - ninjaFlags = [ - "clang-tblgen" - "llvm-tblgen" - "lldb-tblgen" - ] - ++ lib.optionals (lib.versionAtLeast release_version "15") [ - "clang-tidy-confusable-chars-gen" - ] - ++ lib.optionals (lib.versionAtLeast release_version "16") [ - "mlir-tblgen" - ] - ++ - lib.optionals ((lib.versionAtLeast release_version "15") && (lib.versionOlder release_version "20")) - [ - "clang-pseudo-gen" # Removed in LLVM 20 @ ed8f78827895050442f544edef2933a60d4a7935. - ]; - - installPhase = '' - mkdir -p $out - - # Remove useless files - rm -f bin/{lldb-dotest,lldb-repro,llvm-lit,update_core_linalg_named_ops.sh} - - cp -ar bin $out/bin - ''; - }); -in -self diff --git a/nix/portable.nix b/nix/portable.nix index 04619b0ab..107ea80c1 100644 --- a/nix/portable.nix +++ b/nix/portable.nix @@ -8,9 +8,7 @@ let lib = pkgs.lib; isLLDB = pwndbg.meta.isLLDB; - lldb = pwndbg.meta.lldb; - gdb = pwndbg.meta.gdb; - python3 = pwndbg.meta.python3; + python3 = pwndbg.meta.pwndbgVenv.meta.python3; pwndbgVenv = pwndbg.meta.pwndbgVenv; bundler = arg: (pkgsNative.callPackage ./bundle { } arg); @@ -94,25 +92,7 @@ let "${lib.getLib pkgs.libffi_portable}/lib/" "lib/" ]) - ++ - # Darwin don't have gdbserver - (lib.optionals (!pkgs.stdenv.isDarwin) [ - "${lib.getBin gdb}/bin/gdbserver" - "exe/gdbserver" - - "${wrapperBin "exe/gdbserver"}" - "bin/gdbserver" - ]) ++ [ - "${lib.getBin gdb}/bin/gdb" - "exe/gdb" - - "${wrapperBin "exe/gdb"}" - "bin/gdb" - - "${gdb}/share/gdb/" - "share/gdb/" - "${python3}/bin/python3" "exe/python3" @@ -125,8 +105,20 @@ let "${pwndbgVenv}/bin/pwndbg" "exe/pwndbg" + "${pwndbgVenv}/bin/gdb" + "exe/gdb" + + "${pwndbgVenv}/bin/gdbserver" + "exe/gdbserver" + "${wrapperBinPy "exe/pwndbg"}" "bin/pwndbg" + + "${wrapperBinPy "exe/gdb"}" + "bin/gdb" + + "${wrapperBinPy "exe/gdbserver"}" + "bin/gdbserver" ] ); @@ -136,15 +128,6 @@ let "lib/" ]) ++ [ - "${lib.getBin lldb}/bin/.lldb-wrapped" - "exe/lldb" - - "${lib.getBin lldb}/bin/lldb-server" - "exe/lldb-server" - - "${lib.getLib lldb}/lib/" - "lib/" - "${pwndbgVenv}/lib/" "lib/" @@ -154,17 +137,23 @@ let "${python3}/bin/python3" "exe/python3" - "${wrapperBin "exe/lldb-server"}" - "bin/lldb-server" - - "${wrapperBin "exe/lldb"}" - "bin/lldb" - "${pwndbgVenv}/bin/pwndbg-lldb" "exe/pwndbg-lldb" + "${pwndbgVenv}/bin/lldb" + "exe/lldb" + + "${pwndbgVenv}/bin/lldb-server" + "exe/lldb-server" + "${wrapperBinPy "exe/pwndbg-lldb"}" "bin/pwndbg-lldb" + + "${wrapperBinPy "exe/lldb"}" + "bin/lldb" + + "${wrapperBinPy "exe/lldb-server"}" + "bin/lldb-server" ] ); pwndbgBundled = if isLLDB then pwndbgLldbBundled else pwndbgGdbBundled; @@ -175,8 +164,7 @@ let meta = { name = pwndbg.name; version = pwndbg.version; - architecture = - if isLLDB then lldb.stdenv.targetPlatform.system else gdb.stdenv.targetPlatform.system; + architecture = pwndbgVenv.stdenv.targetPlatform.system; }; } '' @@ -187,6 +175,17 @@ let # writable out chmod -R +w $out + # fix lldb/gdb in bundle + ${ + if pwndbgVenv.stdenv.targetPlatform.isLinux then + '' + ${pkgsNative.patchelf}/bin/patchelf --set-rpath '$ORIGIN/../../../../../../lib' $out/pwndbg/lib/${python3.libPrefix}/site-packages/gdb_for_pwndbg/_vendor/bin/gdbserver || true + ${pkgsNative.patchelf}/bin/patchelf --set-rpath '$ORIGIN/../../../../../../lib' $out/pwndbg/lib/${python3.libPrefix}/site-packages/lldb_for_pwndbg/_vendor/bin/lldb-server || true + '' + else + "" + } + # remove unneeded dirs rm -rf $out/pwndbg/lib/pkgconfig find $out/pwndbg/lib/${python3.libPrefix}/ -type d -name "__pycache__" -exec rm -rf {} + diff --git a/nix/pwndbg.nix b/nix/pwndbg.nix index 74e9cfec5..244b4c883 100644 --- a/nix/pwndbg.nix +++ b/nix/pwndbg.nix @@ -2,10 +2,8 @@ pkgs, inputs, python3 ? pkgs.python3, - gdb ? pkgs.pwndbg_gdb, - lldb ? pkgs.pwndbg_lldb, isDev ? false, - isLLDB ? false, + groups, ... }: let @@ -22,8 +20,8 @@ let pkgs inputs python3 + groups isDev - isLLDB ; }; @@ -35,38 +33,37 @@ let in version; - pwndbg_gdb = - pkgs.runCommand "pwndbg" - { - version = pwndbgVersion; - nativeBuildInputs = [ pkgs.pkgsBuildHost.makeWrapper ]; - } - '' - mkdir -p $out/bin/ - makeWrapper ${pyEnv}/bin/pwndbg $out/bin/pwndbg \ - --prefix PATH : ${lib.makeBinPath ([ gdb ] ++ extraPackags)} - ''; + mainProgram = + if groups == [ "lldb" ] then + "pwndbg-lldb" + else if groups == [ "gdb" ] then + "pwndbg" + else + "pwndbg-any"; - pwndbg_lldb = - pkgs.runCommand "pwndbg-lldb" + pwndbg_any = + pkgs.runCommand mainProgram { version = pwndbgVersion; nativeBuildInputs = [ pkgs.pkgsBuildHost.makeWrapper ]; + meta = { + pwndbgVenv = pyEnv; + isLLDB = groups == [ "lldb" ]; + mainProgram = mainProgram; + }; } '' mkdir -p $out/bin/ - makeWrapper ${pyEnv}/bin/pwndbg-lldb $out/bin/pwndbg-lldb \ - --prefix PATH : ${lib.makeBinPath ([ lldb ] ++ extraPackags)} - ''; - pwndbg_final = (if isLLDB then pwndbg_lldb else pwndbg_gdb) // { - meta = { - pwndbgVenv = pyEnv; - python3 = python3; - gdb = gdb; - lldb = lldb; - isLLDB = isLLDB; - }; - }; + if [ -e "${pyEnv}/bin/gdb" ]; then + makeWrapper ${pyEnv}/bin/pwndbg $out/bin/pwndbg \ + --prefix PATH : ${lib.makeBinPath extraPackags} + fi + + if [ -e "${pyEnv}/bin/lldb" ]; then + makeWrapper ${pyEnv}/bin/pwndbg-lldb $out/bin/pwndbg-lldb \ + --prefix PATH : ${lib.makeBinPath extraPackags} + fi + ''; in -pwndbg_final +pwndbg_any diff --git a/nix/pyenv.nix b/nix/pyenv.nix index 6d4c674fe..0db29c662 100644 --- a/nix/pyenv.nix +++ b/nix/pyenv.nix @@ -3,8 +3,8 @@ inputs, python3 ? pkgs.python3, isDev ? false, - isLLDB ? false, isEditable ? false, + groups, ... }: let @@ -133,8 +133,6 @@ let paramiko = dummy; pip = dummy; uv = dummy; - gdb-for-pwndbg = dummy; - lldb-for-pwndbg = dummy; # ziglang is only supported on few platforms ziglang = @@ -267,6 +265,32 @@ let ]; }) ) { }; + + gdb-for-pwndbg = pkgs.callPackage ( + { python3, autoPatchelfHook }: + prev.gdb-for-pwndbg.overrideAttrs (old: { + nativeBuildInputs = builtins.filter (x: x != autoPatchelfHook) old.nativeBuildInputs; + postFixup = '' + for f in ${python3}/lib/libpython*; do + name=$(basename "$f") + ln -s "$f" "$out/lib/$name"; + done + ''; + }) + ) { }; + + lldb-for-pwndbg = pkgs.callPackage ( + { python3, autoPatchelfHook }: + prev.lldb-for-pwndbg.overrideAttrs (old: { + nativeBuildInputs = builtins.filter (x: x != autoPatchelfHook) old.nativeBuildInputs; + postFixup = '' + for f in ${python3}/lib/libpython*; do + name=$(basename "$f") + ln -s "$f" "$out/lib/$name"; + done + ''; + }) + ) { }; }; overlays = lib.composeManyExtensions [ @@ -321,30 +345,29 @@ let pyenv = pythonSet.mkVirtualEnv "pwndbg-env" { pwndbg = [ ] - ++ lib.optionals isLLDB [ - "lldb" - ] ++ lib.optionals isDev [ "dev" "tests" # We don't need linters in "dev" build # "lint" - ]; + ] + ++ groups; }; pyenvEditable = editablePythonSet.mkVirtualEnv "pwndbg-editable-env" { pwndbg = [ ] - ++ lib.optionals isLLDB [ - "lldb" - ] - ++ lib.optionals (!isLLDB) [ - "gdb" - ] ++ lib.optionals isDev [ "dev" "tests" - ]; + ] + ++ groups; }; + + final = (if isEditable then pyenvEditable else pyenv).overrideAttrs (old: { + meta = { + python3 = python3; + }; + }); in -if isEditable then pyenvEditable else pyenv +final