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
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user