Merge pull request #256525 from K900/auto-patchelf-flags

autoPatchelfHook: add `patchelfFlags` option

authored by K900 and committed by GitHub 03fddbfb 3bf47679

+20 -23
+3 -16
pkgs/applications/networking/browsers/firefox-bin/default.nix
··· 20 20 , runtimeShell 21 21 , systemLocale ? config.i18n.defaultLocale or "en_US" 22 22 , patchelfUnstable # have to use patchelfUnstable to support --no-clobber-old-sections 23 - , makeWrapper 24 23 }: 25 24 26 25 let ··· 58 57 source = lib.findFirst (sourceMatches mozLocale) defaultSource sources; 59 58 60 59 pname = "firefox-${channel}-bin-unwrapped"; 61 - 62 - # FIXME: workaround for not being able to pass flags to patchelf 63 - # Remove after https://github.com/NixOS/nixpkgs/pull/256525 64 - wrappedPatchelf = stdenv.mkDerivation { 65 - pname = "patchelf-wrapped"; 66 - inherit (patchelfUnstable) version; 67 - 68 - nativeBuildInputs = [ makeWrapper ]; 69 - 70 - buildCommand = '' 71 - mkdir -p $out/bin 72 - makeWrapper ${patchelfUnstable}/bin/patchelf $out/bin/patchelf --append-flags "--no-clobber-old-sections" 73 - ''; 74 - }; 75 60 in 76 61 77 62 stdenv.mkDerivation { ··· 79 64 80 65 src = fetchurl { inherit (source) url sha256; }; 81 66 82 - nativeBuildInputs = [ wrapGAppsHook autoPatchelfHook wrappedPatchelf ]; 67 + nativeBuildInputs = [ wrapGAppsHook autoPatchelfHook patchelfUnstable ]; 83 68 buildInputs = [ 84 69 gtk3 85 70 adwaita-icon-theme ··· 95 80 appendRunpaths = [ 96 81 "${pipewire.lib}/lib" 97 82 ]; 83 + # Firefox uses "relrhack" to manually process relocations from a fixed offset 84 + patchelfFlags = [ "--no-clobber-old-sections" ]; 98 85 99 86 installPhase = 100 87 ''
+14 -6
pkgs/build-support/setup-hooks/auto-patchelf.py
··· 174 174 found: bool = False # Whether it was found somewhere 175 175 176 176 177 - def auto_patchelf_file(path: Path, runtime_deps: list[Path], append_rpaths: List[Path] = []) -> list[Dependency]: 177 + def auto_patchelf_file(path: Path, runtime_deps: list[Path], append_rpaths: List[Path] = [], extra_args: List[str] = []) -> list[Dependency]: 178 178 try: 179 179 with open_elf(path) as elf: 180 180 ··· 213 213 if file_is_dynamic_executable: 214 214 print("setting interpreter of", path) 215 215 subprocess.run( 216 - ["patchelf", "--set-interpreter", interpreter_path.as_posix(), path.as_posix()], 216 + ["patchelf", "--set-interpreter", interpreter_path.as_posix(), path.as_posix()] + extra_args, 217 217 check=True) 218 218 rpath += runtime_deps 219 219 ··· 250 250 if rpath: 251 251 print("setting RPATH to:", rpath_str) 252 252 subprocess.run( 253 - ["patchelf", "--set-rpath", rpath_str, path.as_posix()], 253 + ["patchelf", "--set-rpath", rpath_str, path.as_posix()] + extra_args, 254 254 check=True) 255 255 256 256 return dependencies ··· 262 262 runtime_deps: List[Path], 263 263 recursive: bool = True, 264 264 ignore_missing: List[str] = [], 265 - append_rpaths: List[Path] = []) -> None: 265 + append_rpaths: List[Path] = [], 266 + extra_args: List[str] = []) -> None: 266 267 267 268 if not paths_to_patch: 268 269 sys.exit("No paths to patch, stopping.") ··· 275 276 dependencies = [] 276 277 for path in chain.from_iterable(glob(p, '*', recursive) for p in paths_to_patch): 277 278 if not path.is_symlink() and path.is_file(): 278 - dependencies += auto_patchelf_file(path, runtime_deps, append_rpaths) 279 + dependencies += auto_patchelf_file(path, runtime_deps, append_rpaths, extra_args) 279 280 280 281 missing = [dep for dep in dependencies if not dep.found] 281 282 ··· 333 334 type=Path, 334 335 help="Paths to append to all runtime paths unconditionally", 335 336 ) 337 + parser.add_argument( 338 + "--extra-args", 339 + nargs="*", 340 + type=str, 341 + help="Extra arguments to pass to patchelf" 342 + ) 336 343 337 344 print("automatically fixing dependencies for ELF files") 338 345 args = parser.parse_args() ··· 344 351 args.runtime_dependencies, 345 352 args.recursive, 346 353 args.ignore_missing, 347 - append_rpaths=args.append_rpaths) 354 + append_rpaths=args.append_rpaths, 355 + extra_args=args.extra_args) 348 356 349 357 350 358 interpreter_path: Path = None # type: ignore
+3 -1
pkgs/build-support/setup-hooks/auto-patchelf.sh
··· 63 63 64 64 local appendRunpathsArray=($appendRunpaths) 65 65 local runtimeDependenciesArray=($runtimeDependencies) 66 + local patchelfFlagsArray=($patchelfFlags) 66 67 @pythonInterpreter@ @autoPatchelfScript@ \ 67 68 ${norecurse:+--no-recurse} \ 68 69 --ignore-missing "${ignoreMissingDepsArray[@]}" \ ··· 70 71 --libs "${autoPatchelfLibs[@]}" \ 71 72 "${extraAutoPatchelfLibs[@]}" \ 72 73 --runtime-dependencies "${runtimeDependenciesArray[@]/%//lib}" \ 73 - --append-rpaths "${appendRunpathsArray[@]}" 74 + --append-rpaths "${appendRunpathsArray[@]}" \ 75 + --extra-args "${patchelfFlagsArray[@]}" 74 76 } 75 77 76 78 # XXX: This should ultimately use fixupOutputHooks but we currently don't have