From 687371ab28358ca878a93f4ef4884bfecf0ac40c Mon Sep 17 00:00:00 2001 From: adisbladis Date: Sun, 3 Nov 2024 03:13:21 +0000 Subject: [PATCH] auto-patchelf: Don't use buildPythonApplication https://github.com/NixOS/nixpkgs/pull/340162 introduced `autoPatchelfHook` as it's own top-level attribute. This also made it use the Nixpkgs Python build infrastructure, which relies on dependency propagation, leaking Python as a dependency into many builds erroneously. This change uses a `withPackages` constructed environment instead, and manually patches the script shebangs, not triggering the `buildPython*` dependency propagation mechanism --- pkgs/by-name/au/auto-patchelf/package.nix | 27 ++++++++++++------- .../au/auto-patchelf/source/auto-patchelf.py | 5 +++- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/pkgs/by-name/au/auto-patchelf/package.nix b/pkgs/by-name/au/auto-patchelf/package.nix index 5096c4fcf56a..adff3a5e40c0 100644 --- a/pkgs/by-name/au/auto-patchelf/package.nix +++ b/pkgs/by-name/au/auto-patchelf/package.nix @@ -1,18 +1,29 @@ { + stdenv, + python3, lib, - python3Packages, }: -python3Packages.buildPythonApplication { +let + pythonEnv = python3.withPackages (ps: [ ps.pyelftools ]); + +in +# Note: Not using python3Packages.buildPythonApplication because of dependency propagation. +stdenv.mkDerivation { pname = "auto-patchelf"; version = "0-unstable-2024-08-14"; - pyproject = false; + + buildInputs = [ pythonEnv ]; src = ./source; - dependencies = with python3Packages; [ - pyelftools - ]; + buildPhase = '' + runHook preBuild + + substituteInPlace auto-patchelf.py --replace-fail "@defaultBintools@" "$NIX_BINTOOLS" + + runHook postBuild + ''; installPhase = '' runHook preInstall @@ -22,10 +33,6 @@ python3Packages.buildPythonApplication { runHook postInstall ''; - makeWrapperArgs = [ - "--set DEFAULT_BINTOOLS $NIX_BINTOOLS" - ]; - meta = { description = "Automatically patch ELF binaries using patchelf"; mainProgram = "auto-patchelf"; diff --git a/pkgs/by-name/au/auto-patchelf/source/auto-patchelf.py b/pkgs/by-name/au/auto-patchelf/source/auto-patchelf.py index 938ea6310118..2a1090302ee9 100644 --- a/pkgs/by-name/au/auto-patchelf/source/auto-patchelf.py +++ b/pkgs/by-name/au/auto-patchelf/source/auto-patchelf.py @@ -21,6 +21,9 @@ from elftools.elf.elffile import ELFFile # type: ignore from elftools.elf.enums import ENUM_E_TYPE, ENUM_EI_OSABI # type: ignore +DEFAULT_BINTOOLS = "@defaultBintools@" + + @contextmanager def open_elf(path: Path) -> Iterator[ELFFile]: with path.open('rb') as stream: @@ -425,7 +428,7 @@ interpreter_arch: str = None # type: ignore libc_lib: Path = None # type: ignore if __name__ == "__main__": - nix_support = Path(os.environ.get('NIX_BINTOOLS', os.environ['DEFAULT_BINTOOLS'])) / 'nix-support' + nix_support = Path(os.environ.get('NIX_BINTOOLS', DEFAULT_BINTOOLS)) / 'nix-support' interpreter_path = Path((nix_support / 'dynamic-linker').read_text().strip()) libc_lib = Path((nix_support / 'orig-libc').read_text().strip()) / 'lib'