From 567bd7c6a61c0673cbc8e16a70a0b36f19dc8cbf Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Fri, 6 Sep 2024 20:38:58 +0200 Subject: [PATCH] autoPatchelfHook: expose script as top level package Signed-off-by: Sefa Eyeoglu --- .../setup-hooks/auto-patchelf.sh | 2 +- .../au/auto-patchelf}/auto-patchelf.py | 2 +- pkgs/by-name/au/auto-patchelf/package.nix | 41 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 6 +-- 4 files changed, 44 insertions(+), 7 deletions(-) rename pkgs/{build-support/setup-hooks => by-name/au/auto-patchelf}/auto-patchelf.py (99%) create mode 100644 pkgs/by-name/au/auto-patchelf/package.nix diff --git a/pkgs/build-support/setup-hooks/auto-patchelf.sh b/pkgs/build-support/setup-hooks/auto-patchelf.sh index 59b596d27172..dc83dee3246f 100644 --- a/pkgs/build-support/setup-hooks/auto-patchelf.sh +++ b/pkgs/build-support/setup-hooks/auto-patchelf.sh @@ -79,7 +79,7 @@ autoPatchelf() { fi done - @pythonInterpreter@ @autoPatchelfScript@ \ + auto-patchelf \ ${norecurse:+--no-recurse} \ --ignore-missing "${ignoreMissingDepsArray[@]}" \ --paths "$@" \ diff --git a/pkgs/build-support/setup-hooks/auto-patchelf.py b/pkgs/by-name/au/auto-patchelf/auto-patchelf.py similarity index 99% rename from pkgs/build-support/setup-hooks/auto-patchelf.py rename to pkgs/by-name/au/auto-patchelf/auto-patchelf.py index eca3007514de..938ea6310118 100644 --- a/pkgs/build-support/setup-hooks/auto-patchelf.py +++ b/pkgs/by-name/au/auto-patchelf/auto-patchelf.py @@ -425,7 +425,7 @@ interpreter_arch: str = None # type: ignore libc_lib: Path = None # type: ignore if __name__ == "__main__": - nix_support = Path(os.environ['NIX_BINTOOLS']) / 'nix-support' + nix_support = Path(os.environ.get('NIX_BINTOOLS', os.environ['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' diff --git a/pkgs/by-name/au/auto-patchelf/package.nix b/pkgs/by-name/au/auto-patchelf/package.nix new file mode 100644 index 000000000000..1e1880560adf --- /dev/null +++ b/pkgs/by-name/au/auto-patchelf/package.nix @@ -0,0 +1,41 @@ +{ + lib, + python3Packages, +}: + +python3Packages.buildPythonApplication { + pname = "auto-patchelf"; + version = "0-unstable-2024-08-14"; + pyproject = false; + + src = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + ./auto-patchelf.py + ]; + }; + + dependencies = with python3Packages; [ + pyelftools + ]; + + installPhase = '' + runHook preInstall + + install -Dm755 auto-patchelf.py $out/bin/auto-patchelf + + runHook postInstall + ''; + + makeWrapperArgs = [ + "--set DEFAULT_BINTOOLS $NIX_BINTOOLS" + ]; + + meta = { + description = "Automatically patch ELF binaries using patchelf"; + mainProgram = "auto-patchelf"; + license = lib.licenses.mit; + platforms = lib.platforms.unix; + maintainers = with lib.maintainers; [ Scrumplex ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 327073d55c7d..ddc585c7dbbf 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -188,11 +188,7 @@ with pkgs; autoPatchelfHook = makeSetupHook { name = "auto-patchelf-hook"; - propagatedBuildInputs = [ bintools ]; - substitutions = { - pythonInterpreter = "${python3.withPackages (ps: [ ps.pyelftools ])}/bin/python"; - autoPatchelfScript = ../build-support/setup-hooks/auto-patchelf.py; - }; + propagatedBuildInputs = [ auto-patchelf bintools ]; } ../build-support/setup-hooks/auto-patchelf.sh; tomato-c = callPackage ../applications/misc/tomato-c { };