From 1c6126f7091988a345684098d0d21940e0e1a92e Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sat, 25 Jan 2025 20:59:09 +0100 Subject: [PATCH 1/2] various: replace substituteAll with replaceVars A few more interesting cases, separated from the big treewide for better visibility and testing. --- .../python-modules/mat2/default.nix | 21 +++++++-------- .../python-modules/triton/default.nix | 26 +++++++------------ .../tools/build-managers/gradle/default.nix | 7 +++-- .../tools/flatpak-builder/default.nix | 8 +++--- .../flatpak-builder/fix-test-paths.patch | 2 +- pkgs/servers/http/nginx/generic.nix | 17 ++++++------ pkgs/servers/http/openresty/default.nix | 4 +++ pkgs/servers/http/tengine/default.nix | 24 ++++++++--------- 8 files changed, 50 insertions(+), 59 deletions(-) diff --git a/pkgs/development/python-modules/mat2/default.nix b/pkgs/development/python-modules/mat2/default.nix index f942fadb403f..735c530dc01f 100644 --- a/pkgs/development/python-modules/mat2/default.nix +++ b/pkgs/development/python-modules/mat2/default.nix @@ -5,7 +5,7 @@ pytestCheckHook, pythonOlder, fetchFromGitLab, - substituteAll, + replaceVars, bubblewrap, exiftool, ffmpeg, @@ -40,22 +40,21 @@ buildPythonPackage rec { patches = [ # hardcode paths to some binaries - (substituteAll ( - { - src = ./paths.patch; - exiftool = "${exiftool}/bin/exiftool"; - ffmpeg = "${ffmpeg}/bin/ffmpeg"; - } - // lib.optionalAttrs dolphinIntegration { kdialog = "${plasma5Packages.kdialog}/bin/kdialog"; } - )) + (replaceVars ./paths.patch { + exiftool = "${exiftool}/bin/exiftool"; + ffmpeg = "${ffmpeg}/bin/ffmpeg"; + kdialog = if dolphinIntegration then "${plasma5Packages.kdialog}/bin/kdialog" else null; + # replaced in postPatch + mat2 = null; + mat2svg = null; + }) # the executable shouldn't be called .mat2-wrapped ./executable-name.patch # hardcode path to mat2 executable ./tests.patch ] ++ lib.optionals (stdenv.hostPlatform.isLinux) [ - (substituteAll { - src = ./bubblewrap-path.patch; + (replaceVars ./bubblewrap-path.patch { bwrap = "${bubblewrap}/bin/bwrap"; }) ]; diff --git a/pkgs/development/python-modules/triton/default.nix b/pkgs/development/python-modules/triton/default.nix index 69ddb4ad716c..2f8dcecc023a 100644 --- a/pkgs/development/python-modules/triton/default.nix +++ b/pkgs/development/python-modules/triton/default.nix @@ -17,7 +17,7 @@ python, pytestCheckHook, stdenv, - substituteAll, + replaceVars, setuptools, torchWithRocm, zlib, @@ -43,28 +43,20 @@ buildPythonPackage { patches = [ ./0001-setup.py-introduce-TRITON_OFFLINE_BUILD.patch - (substituteAll { - src = ./0001-_build-allow-extra-cc-flags.patch; + (replaceVars ./0001-_build-allow-extra-cc-flags.patch { ccCmdExtraFlags = "-Wl,-rpath,${addDriverRunpath.driverLink}/lib"; }) - (substituteAll ( - { - src = ./0002-nvidia-amd-driver-short-circuit-before-ldconfig.patch; - } - // lib.optionalAttrs rocmSupport { libhipDir = "${lib.getLib rocmPackages.clr}/lib"; } - // lib.optionalAttrs cudaSupport { - libcudaStubsDir = "${lib.getOutput "stubs" cudaPackages.cuda_cudart}/lib/stubs"; - ccCmdExtraFlags = "-Wl,-rpath,${addDriverRunpath.driverLink}/lib"; - } - )) + (replaceVars ./0002-nvidia-amd-driver-short-circuit-before-ldconfig.patch { + libhipDir = if rocmSupport then "${lib.getLib rocmPackages.clr}/lib" else null; + libcudaStubsDir = + if cudaSupport then "${lib.getOutput "stubs" cudaPackages.cuda_cudart}/lib/stubs" else null; + }) ] ++ lib.optionals cudaSupport [ - (substituteAll { - src = ./0003-nvidia-cudart-a-systempath.patch; + (replaceVars ./0003-nvidia-cudart-a-systempath.patch { cudaToolkitIncludeDirs = "${lib.getInclude cudaPackages.cuda_cudart}/include"; }) - (substituteAll { - src = ./0004-nvidia-allow-static-ptxas-path.patch; + (replaceVars ./0004-nvidia-allow-static-ptxas-path.patch { nixpkgsExtraBinaryPaths = lib.escapeShellArgs [ (lib.getExe' cudaPackages.cuda_nvcc "ptxas") ]; }) ]; diff --git a/pkgs/development/tools/build-managers/gradle/default.nix b/pkgs/development/tools/build-managers/gradle/default.nix index a38555846362..41882f2ecd42 100644 --- a/pkgs/development/tools/build-managers/gradle/default.nix +++ b/pkgs/development/tools/build-managers/gradle/default.nix @@ -244,7 +244,7 @@ rec { lib, callPackage, mitm-cache, - substituteAll, + replaceVars, symlinkJoin, concatTextFile, makeSetupHook, @@ -264,11 +264,10 @@ rec { name = "setup-hook.sh"; files = [ (mitm-cache.setupHook) - (substituteAll { - src = ./setup-hook.sh; + (replaceVars ./setup-hook.sh { # jdk used for keytool inherit (gradle) jdk; - init_script = ./init-build.gradle; + init_script = "${./init-build.gradle}"; }) ]; })) diff --git a/pkgs/development/tools/flatpak-builder/default.nix b/pkgs/development/tools/flatpak-builder/default.nix index 7bbeee4a1536..5c02e5e194e9 100644 --- a/pkgs/development/tools/flatpak-builder/default.nix +++ b/pkgs/development/tools/flatpak-builder/default.nix @@ -2,7 +2,7 @@ lib, stdenv, fetchurl, - substituteAll, + replaceVars, nixosTests, docbook_xml_dtd_45, @@ -65,8 +65,7 @@ stdenv.mkDerivation (finalAttrs: { ./respect-xml-catalog-files-var.patch # Hardcode paths - (substituteAll { - src = ./fix-paths.patch; + (replaceVars ./fix-paths.patch { brz = "${breezy}/bin/brz"; cp = "${coreutils}/bin/cp"; patch = "${patch}/bin/patch"; @@ -81,8 +80,7 @@ stdenv.mkDerivation (finalAttrs: { euelfcompress = "${elfutils}/bin/eu-elfcompress"; }) - (substituteAll { - src = ./fix-test-paths.patch; + (replaceVars ./fix-test-paths.patch { inherit glibcLocales; }) ./fix-test-prefix.patch diff --git a/pkgs/development/tools/flatpak-builder/fix-test-paths.patch b/pkgs/development/tools/flatpak-builder/fix-test-paths.patch index 96212a30fcf8..d107ef738d03 100644 --- a/pkgs/development/tools/flatpak-builder/fix-test-paths.patch +++ b/pkgs/development/tools/flatpak-builder/fix-test-paths.patch @@ -5,7 +5,7 @@ skip_without_python2 () { - if ! test -f /usr/bin/python2 || ! /usr/bin/python2 -c "import sys; sys.exit(0 if sys.version_info >= (2, 7) else 1)" ; then -+ if ! test -f @python2@/bin/python2 || ! @python2@/bin/python2 -c "import sys; sys.exit(0 if sys.version_info >= (2, 7) else 1)" ; then ++ if true ; then echo "1..0 # SKIP this test requires /usr/bin/python2 (2.7) support" exit 0 fi diff --git a/pkgs/servers/http/nginx/generic.nix b/pkgs/servers/http/nginx/generic.nix index 3f4933500f7b..3c0e87ab6c76 100644 --- a/pkgs/servers/http/nginx/generic.nix +++ b/pkgs/servers/http/nginx/generic.nix @@ -12,7 +12,7 @@ outer@{ nixosTests, installShellFiles, - substituteAll, + replaceVars, removeReferencesTo, gd, geoip, @@ -40,7 +40,7 @@ outer@{ buildInputs ? [ ], extraPatches ? [ ], fixPatch ? p: p, - postPatch ? "", + postPatch ? null, preConfigure ? "", preInstall ? "", postInstall ? "", @@ -214,12 +214,7 @@ stdenv.mkDerivation { patches = map fixPatch ( [ - (substituteAll { - src = ./nix-etag-1.15.4.patch; - preInstall = '' - export nixStoreDir="$NIX_STORE" nixStoreDirLen="''${#NIX_STORE}" - ''; - }) + ./nix-etag-1.15.4.patch ./nix-skip-check-logs-path.patch ] ++ @@ -255,7 +250,11 @@ stdenv.mkDerivation { ) ++ extraPatches; - inherit postPatch; + postPatch = lib.defaultTo '' + substituteInPlace src/http/ngx_http_core_module.c \ + --replace-fail '@nixStoreDir@' "$NIX_STORE" \ + --replace-fail '@nixStoreDirLen@' "''${#NIX_STORE}" + '' postPatch; hardeningEnable = lib.optional (!stdenv.hostPlatform.isDarwin) "pie"; diff --git a/pkgs/servers/http/openresty/default.nix b/pkgs/servers/http/openresty/default.nix index d40cb644cf4d..842762a0c2c1 100644 --- a/pkgs/servers/http/openresty/default.nix +++ b/pkgs/servers/http/openresty/default.nix @@ -39,6 +39,10 @@ callPackage ../nginx/generic.nix args rec { buildInputs = [ postgresql ]; postPatch = '' + substituteInPlace bundle/nginx-${nginxVersion}/src/http/ngx_http_core_module.c \ + --replace-fail '@nixStoreDir@' "$NIX_STORE" \ + --replace-fail '@nixStoreDirLen@' "''${#NIX_STORE}" + patchShebangs configure bundle/ ''; diff --git a/pkgs/servers/http/tengine/default.nix b/pkgs/servers/http/tengine/default.nix index 812784ebd394..d60b8ec7815b 100644 --- a/pkgs/servers/http/tengine/default.nix +++ b/pkgs/servers/http/tengine/default.nix @@ -8,7 +8,7 @@ libxcrypt, libxml2, libxslt, - substituteAll, + replaceVars, gd, geoip, gperftools, @@ -48,17 +48,17 @@ stdenv.mkDerivation rec { jemalloc ] ++ lib.concatMap (mod: mod.inputs or [ ]) modules; - patches = - lib.singleton (substituteAll { - src = ../nginx/nix-etag-1.15.4.patch; - preInstall = '' - export nixStoreDir="$NIX_STORE" nixStoreDirLen="''${#NIX_STORE}" - ''; - }) - ++ [ - ./check-resolv-conf.patch - ../nginx/nix-skip-check-logs-path.patch - ]; + patches = [ + ../nginx/nix-etag-1.15.4.patch + ./check-resolv-conf.patch + ../nginx/nix-skip-check-logs-path.patch + ]; + + postPatch = '' + substituteInPlace src/http/ngx_http_core_module.c \ + --replace-fail '@nixStoreDir@' "$NIX_STORE" \ + --replace-fail '@nixStoreDirLen@' "''${#NIX_STORE}" + ''; configureFlags = [ From 6cbf845dcb3e4bb42e53963095d8a00163a09a32 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sat, 25 Jan 2025 20:57:29 +0100 Subject: [PATCH 2/2] oh-my-fish: fix omf-install script Passing placeholder to substituteAll or replaceVars doesn't work as expected, it will use the substituteAll's out path instead of the "caller". --- pkgs/by-name/oh/oh-my-fish/package.nix | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkgs/by-name/oh/oh-my-fish/package.nix b/pkgs/by-name/oh/oh-my-fish/package.nix index b91a89c0beb1..b93eb00d7862 100644 --- a/pkgs/by-name/oh/oh-my-fish/package.nix +++ b/pkgs/by-name/oh/oh-my-fish/package.nix @@ -4,7 +4,7 @@ fetchFromGitHub, fish, runtimeShell, - substituteAll, + replaceVars, }: stdenv.mkDerivation (finalAttrs: { @@ -38,14 +38,16 @@ stdenv.mkDerivation (finalAttrs: { cp -vr * $out/share/oh-my-fish cp -v ${ - substituteAll { - name = "omf-install"; - src = ./omf-install; - omf = placeholder "out"; + replaceVars ./omf-install { inherit fish runtimeShell; + # replaced below + omf = null; } } $out/bin/omf-install + substituteInPlace $out/bin/omf-install \ + --replace-fail '@omf@' "$out" + chmod +x $out/bin/omf-install cat $out/bin/omf-install