From ea0ada2b61c7e929b5000d8bf0f117782958e629 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sat, 23 Nov 2024 13:45:07 +0100 Subject: [PATCH] various: replace substituteAll with replaceVars This deals with some special cases, i.e. where "null" is used to avoid replacing some values or where the syntax is not too easy to grep for for automated replacement. --- .../applications/editors/emacs/make-emacs.nix | 8 +++---- .../kde/kdegraphics-thumbnailers/default.nix | 5 ++-- pkgs/build-support/testers/default.nix | 4 ++-- pkgs/by-name/hy/hylafaxplus/config.site | 18 +++++++-------- pkgs/by-name/hy/hylafaxplus/package.nix | 16 ++++--------- .../li/libnvidia-container/package.nix | 5 ++-- pkgs/by-name/ps/ps2eps/package.nix | 8 +++---- pkgs/by-name/zo/zod/package.nix | 5 ++-- .../compilers/llvm/common/default.nix | 15 ++++++------ .../python-modules/pysdl2/PySDL2-dll.patch | 10 ++++---- .../python-modules/pysdl2/default.nix | 23 ++++++------------- pkgs/development/tools/ocaml/merlin/4.x.nix | 8 +++---- .../gear/kdegraphics-thumbnailers/default.nix | 5 ++-- pkgs/os-specific/linux/lvm2/common.nix | 6 ++--- 14 files changed, 58 insertions(+), 78 deletions(-) diff --git a/pkgs/applications/editors/emacs/make-emacs.nix b/pkgs/applications/editors/emacs/make-emacs.nix index 7bae78f35e70e..3305b674dac6e 100644 --- a/pkgs/applications/editors/emacs/make-emacs.nix +++ b/pkgs/applications/editors/emacs/make-emacs.nix @@ -51,7 +51,7 @@ , recurseIntoAttrs , sigtool , sqlite -, substituteAll +, replaceVars , systemd , tree-sitter , texinfo @@ -148,12 +148,12 @@ mkDerivation (finalAttrs: { inherit src; patches = patches fetchpatch ++ lib.optionals withNativeCompilation [ - (substituteAll { - src = if lib.versionOlder finalAttrs.version "29" + (replaceVars (if lib.versionOlder finalAttrs.version "29" then ./native-comp-driver-options-28.patch else if lib.versionOlder finalAttrs.version "30" then ./native-comp-driver-options.patch - else ./native-comp-driver-options-30.patch; + else ./native-comp-driver-options-30.patch) { + backendPath = (lib.concatStringsSep " " (builtins.map (x: ''"-B${x}"'') ([ # Paths necessary so the JIT compiler finds its libraries: diff --git a/pkgs/applications/kde/kdegraphics-thumbnailers/default.nix b/pkgs/applications/kde/kdegraphics-thumbnailers/default.nix index 6686f582d6d2b..a8711164926c1 100644 --- a/pkgs/applications/kde/kdegraphics-thumbnailers/default.nix +++ b/pkgs/applications/kde/kdegraphics-thumbnailers/default.nix @@ -1,5 +1,5 @@ { - mkDerivation, lib, ghostscript, substituteAll, + mkDerivation, lib, ghostscript, replaceVars, extra-cmake-modules, karchive, kio, libkexiv2, libkdcraw, kdegraphics-mobipocket }: @@ -15,9 +15,8 @@ mkDerivation { patches = [ # Hardcode patches to Ghostscript so PDF thumbnails work OOTB. # Intentionally not doing the same for dvips because TeX is big. - (substituteAll { + (replaceVars ./gs-paths.patch { gs = "${ghostscript}/bin/gs"; - src = ./gs-paths.patch; }) ]; } diff --git a/pkgs/build-support/testers/default.nix b/pkgs/build-support/testers/default.nix index ba605adeb9a04..92b248882e6f6 100644 --- a/pkgs/build-support/testers/default.nix +++ b/pkgs/build-support/testers/default.nix @@ -10,7 +10,7 @@ runCommandWith, stdenv, stdenvNoCC, - substituteAll, + replaceVars, testers, }: # Documentation is in doc/build-helpers/testers.chapter.md @@ -24,7 +24,7 @@ testBuildFailure = drv: drv.overrideAttrs (orig: { builder = buildPackages.bash; args = [ - (substituteAll { coreutils = buildPackages.coreutils; src = ./expect-failure.sh; }) + (replaceVars ./expect-failure.sh { coreutils = buildPackages.coreutils; }) orig.realBuilder or stdenv.shell ] ++ orig.args or ["-e" (orig.builder or ../../stdenv/generic/default-builder.sh)]; }); diff --git a/pkgs/by-name/hy/hylafaxplus/config.site b/pkgs/by-name/hy/hylafaxplus/config.site index 7c8014449216b..aa66fad916b7c 100644 --- a/pkgs/by-name/hy/hylafaxplus/config.site +++ b/pkgs/by-name/hy/hylafaxplus/config.site @@ -1,16 +1,16 @@ @config_maxgid@ -DIR_BIN="@out_@/bin" -DIR_FONTMAP="@out_@/share/ghostscript/@ghostscript_version@" -DIR_LIB="@out_@/lib" -DIR_LIBDATA="@out_@/spool/etc" -DIR_LIBEXEC="@out_@/spool/bin" +DIR_BIN="@out@/bin" +DIR_FONTMAP="@out@/share/ghostscript/@ghostscript_version@" +DIR_LIB="@out@/lib" +DIR_LIBDATA="@out@/spool/etc" +DIR_LIBEXEC="@out@/spool/bin" DIR_LOCKS=/var/lock -DIR_MAN="@out_@/share/man" -DIR_SBIN="@out_@/spool/bin" -DIR_SPOOL="@out_@/spool" +DIR_MAN="@out@/share/man" +DIR_SBIN="@out@/spool/bin" +DIR_SPOOL="@out@/spool" FONTMAP="@ghostscript@/share/ghostscript/@ghostscript_version@" PATH_AFM="@ghostscript@/share/ghostscript/fonts" -PATH_DPSRIP="@out_@/spool/bin/ps2fax" +PATH_DPSRIP="@out@/spool/bin/ps2fax" PATH_EGETTY="@coreutils@/bin/false" PATH_GSRIP="@ghostscript@/bin/gs" PATH_IMPRIP="@coreutils@/bin/false" diff --git a/pkgs/by-name/hy/hylafaxplus/package.nix b/pkgs/by-name/hy/hylafaxplus/package.nix index 3c66ce8129f34..c2c6045ecc4b6 100644 --- a/pkgs/by-name/hy/hylafaxplus/package.nix +++ b/pkgs/by-name/hy/hylafaxplus/package.nix @@ -3,7 +3,7 @@ , fakeroot , fetchurl , libfaketime -, substituteAll +, replaceVars ## runtime dependencies , coreutils , file @@ -35,18 +35,14 @@ let version = "7.0.9"; hash = "sha512-3OJwM4vFC9pzPozPobFLiNNx/Qnkl8BpNNziRUpJNBDLBxjtg/eDm3GnprS2hpt7VUoV4PCsFvp1hxhNnhlUwQ=="; - configSite = substituteAll { - name = "${pname}-config.site"; - src = ./config.site; + configSite = replaceVars ./config.site { config_maxgid = lib.optionalString (maxgid!=null) ''CONFIG_MAXGID=${builtins.toString maxgid}''; ghostscript_version = ghostscript.version; - out_ = "@out@"; # "out" will be resolved in post-install.sh + out = null; # "out" will be resolved in post-install.sh inherit coreutils ghostscript libtiff; }; - postPatch = substituteAll { - name = "${pname}-post-patch.sh"; - src = ./post-patch.sh; + postPatch = replaceVars ./post-patch.sh { inherit configSite; maxuid = lib.optionalString (maxuid!=null) (builtins.toString maxuid); faxcover_binpath = lib.makeBinPath @@ -55,9 +51,7 @@ let [stdenv.shellPackage coreutils findutils gnused gnugrep gawk]; }; - postInstall = substituteAll { - name = "${pname}-post-install.sh"; - src = ./post-install.sh; + postInstall = replaceVars ./post-install.sh { inherit fakeroot libfaketime; }; diff --git a/pkgs/by-name/li/libnvidia-container/package.nix b/pkgs/by-name/li/libnvidia-container/package.nix index 9b3023813c3fb..703943bc2d20f 100644 --- a/pkgs/by-name/li/libnvidia-container/package.nix +++ b/pkgs/by-name/li/libnvidia-container/package.nix @@ -10,7 +10,6 @@ rpcsvc-proto, libtirpc, makeWrapper, - substituteAll, removeReferencesTo, replaceVars, go, @@ -23,8 +22,8 @@ let rev = modprobeVersion; sha256 = "sha256-iBRMkvOXacs/llTtvc/ZC5i/q9gc8lMuUHxMbu8A+Kg="; }; - modprobePatch = substituteAll { - src = ./modprobe.patch; + modprobePatch = replaceVars ./modprobe.patch { + inherit modprobeVersion; }; in diff --git a/pkgs/by-name/ps/ps2eps/package.nix b/pkgs/by-name/ps/ps2eps/package.nix index c8f558889c60e..88d295b03c669 100644 --- a/pkgs/by-name/ps/ps2eps/package.nix +++ b/pkgs/by-name/ps/ps2eps/package.nix @@ -1,7 +1,7 @@ { lib , fetchFromGitHub , perlPackages -, substituteAll +, replaceVars , ghostscript , installShellFiles }: @@ -18,11 +18,11 @@ perlPackages.buildPerlPackage rec { hash = "sha256-SPLwsGKLVhANoqSQ/GJ938cYjbjMbUOXkNn9so3aJTA="; }; patches = [ - (substituteAll { - src = ./hardcode-deps.patch; + (replaceVars ./hardcode-deps.patch { gs = "${ghostscript}/bin/gs"; - # bbox cannot be substituted here because substituteAll doesn't know what + # bbox cannot be substituted here because replaceVars doesn't know what # will be the $out path of the main derivation + bbox = null; }) ]; diff --git a/pkgs/by-name/zo/zod/package.nix b/pkgs/by-name/zo/zod/package.nix index e0c2031dde250..7a992251c9a55 100644 --- a/pkgs/by-name/zo/zod/package.nix +++ b/pkgs/by-name/zo/zod/package.nix @@ -13,7 +13,7 @@ , makeWrapper , coreutils , scalingFactor ? 2 # this is to resize the fixed-size zod_launcher window -, substituteAll +, replaceVars }: let name = "zod-engine"; @@ -70,9 +70,8 @@ let # 2,3,4 look acceptable on my 4k monitor and 1 is unreadable. # also the ./ in the run command is removed to have easier time starting the game patches = [ - (substituteAll { + (replaceVars ./0002-add-scaling-factor-to-source.patch { inherit scalingFactor; - src=./0002-add-scaling-factor-to-source.patch; }) ]; postPatch = '' diff --git a/pkgs/development/compilers/llvm/common/default.nix b/pkgs/development/compilers/llvm/common/default.nix index 707bb91b875de..fd697cb568383 100644 --- a/pkgs/development/compilers/llvm/common/default.nix +++ b/pkgs/development/compilers/llvm/common/default.nix @@ -7,7 +7,7 @@ preLibcCrossHeaders, libxcrypt, substitute, - substituteAll, + replaceVars, fetchFromGitHub, fetchpatch, fetchpatch2, @@ -547,12 +547,11 @@ let !args.stdenv.hostPlatform.isDarwin || !args.stdenv.targetPlatform.isDarwin ) ./clang/add-nostdlibinc-flag.patch ++ [ - (substituteAll { - src = - if (lib.versionOlder metadata.release_version "16") then + (replaceVars + (if (lib.versionOlder metadata.release_version "16") then ./clang/clang-11-15-LLVMgold-path.patch else - ./clang/clang-at-least-16-LLVMgold-path.patch; + ./clang/clang-at-least-16-LLVMgold-path.patch) { libllvmLibdir = "${tools.libllvm.lib}/lib"; }) ] @@ -662,9 +661,9 @@ let patches = let resourceDirPatch = callPackage ( - { substituteAll, libclang }: - (substituteAll { - src = metadata.getVersionFile "lldb/resource-dir.patch"; + { replaceVars, libclang }: + (replaceVars (metadata.getVersionFile "lldb/resource-dir.patch") { + clangLibDir = "${lib.getLib libclang}/lib"; }).overrideAttrs (_: _: { name = "resource-dir.patch"; }) diff --git a/pkgs/development/python-modules/pysdl2/PySDL2-dll.patch b/pkgs/development/python-modules/pysdl2/PySDL2-dll.patch index 9b8374a0f0516..792c8bcd28e2d 100644 --- a/pkgs/development/python-modules/pysdl2/PySDL2-dll.patch +++ b/pkgs/development/python-modules/pysdl2/PySDL2-dll.patch @@ -39,7 +39,7 @@ index 2413329..f460bf6 100644 try: - dll = DLL("SDL2", ["SDL2", "SDL2-2.0", "SDL2-2.0.0"], os.getenv("PYSDL2_DLL_PATH")) -+ dll = DLL("SDL2", "@sdl2@") ++ dll = DLL("SDL2", "@SDL2@") except RuntimeError as exc: raise ImportError(exc) @@ -53,7 +53,7 @@ index 015eeaf..d6ce52f 100644 try: - dll = DLL("SDL2_gfx", ["SDL2_gfx", "SDL2_gfx-1.0"], - os.getenv("PYSDL2_DLL_PATH")) -+ dll = DLL("SDL2_gfx", "@sdl2_gfx@") ++ dll = DLL("SDL2_gfx", "@SDL2_gfx@") except RuntimeError as exc: raise ImportError(exc) @@ -68,7 +68,7 @@ index a702136..dcdea51 100644 - dll = DLL( - "SDL2_image", ["SDL2_image", "SDL2_image-2.0"], os.getenv("PYSDL2_DLL_PATH") - ) -+ dll = DLL("SDL2_image", "@sdl2_image@") ++ dll = DLL("SDL2_image", "@SDL2_image@") except RuntimeError as exc: raise ImportError(exc) @@ -82,7 +82,7 @@ index 5f2163c..23d95b0 100644 try: - dll = DLL("SDL2_mixer", ["SDL2_mixer", "SDL2_mixer-2.0"], - os.getenv("PYSDL2_DLL_PATH")) -+ dll = DLL("SDL2_mixer", "@sdl2_mixer@") ++ dll = DLL("SDL2_mixer", "@SDL2_mixer@") except RuntimeError as exc: raise ImportError(exc) @@ -96,7 +96,7 @@ index 7c5f7db..61814cd 100644 try: - dll = DLL("SDL2_ttf", ["SDL2_ttf", "SDL2_ttf-2.0"], - os.getenv("PYSDL2_DLL_PATH")) -+ dll = DLL("SDL2_ttf", "@sdl2_ttf@") ++ dll = DLL("SDL2_ttf", "@SDL2_ttf@") except RuntimeError as exc: raise ImportError(exc) diff --git a/pkgs/development/python-modules/pysdl2/default.nix b/pkgs/development/python-modules/pysdl2/default.nix index 7854f24654320..7c2cfa8959861 100644 --- a/pkgs/development/python-modules/pysdl2/default.nix +++ b/pkgs/development/python-modules/pysdl2/default.nix @@ -1,7 +1,7 @@ { stdenv, lib, - substituteAll, + replaceVars, fetchPypi, buildPythonPackage, SDL2, @@ -38,21 +38,12 @@ buildPythonPackage rec { ]; propagatedBuildInputs = [ SDL2 ]; patches = [ - (substituteAll ( - { - src = ./PySDL2-dll.patch; - } - // - builtins.mapAttrs - (_: pkg: "${pkg}/lib/lib${pkg.pname}${stdenv.hostPlatform.extensions.sharedLibrary}") - { - # substituteAll keys must start lowercase - sdl2 = SDL2; - sdl2_ttf = SDL2_ttf; - sdl2_image = SDL2_image; - sdl2_gfx = SDL2_gfx; - sdl2_mixer = SDL2_mixer; - } + (replaceVars ./PySDL2-dll.patch ( + builtins.mapAttrs + (_: pkg: "${pkg}/lib/lib${pkg.pname}${stdenv.hostPlatform.extensions.sharedLibrary}") + { + inherit SDL2 SDL2_ttf SDL2_image SDL2_gfx SDL2_mixer; + } )) ]; diff --git a/pkgs/development/tools/ocaml/merlin/4.x.nix b/pkgs/development/tools/ocaml/merlin/4.x.nix index b156682694943..45698a4b9654d 100644 --- a/pkgs/development/tools/ocaml/merlin/4.x.nix +++ b/pkgs/development/tools/ocaml/merlin/4.x.nix @@ -1,5 +1,5 @@ { lib -, substituteAll +, replaceVars , fetchurl , ocaml , dune_3 @@ -56,9 +56,9 @@ buildDunePackage { old-patch = lib.versionOlder version "4.17"; in [ - (substituteAll { - src = if old-patch then ./fix-paths.patch else ./fix-paths2.patch; - dot_merlin_reader = "${dot-merlin-reader}/bin/dot-merlin-reader"; + (replaceVars (if old-patch then ./fix-paths.patch else ./fix-paths2.patch) { + + dot-merlin-reader = "${dot-merlin-reader}/bin/dot-merlin-reader"; dune = "${dune_3}/bin/dune"; }) ]; diff --git a/pkgs/kde/gear/kdegraphics-thumbnailers/default.nix b/pkgs/kde/gear/kdegraphics-thumbnailers/default.nix index bfb3ba1fc850f..79ae5c8b30a96 100644 --- a/pkgs/kde/gear/kdegraphics-thumbnailers/default.nix +++ b/pkgs/kde/gear/kdegraphics-thumbnailers/default.nix @@ -1,6 +1,6 @@ { mkKdeDerivation, - substituteAll, + replaceVars, ghostscript, }: mkKdeDerivation { @@ -9,9 +9,8 @@ mkKdeDerivation { patches = [ # Hardcode patches to Ghostscript so PDF thumbnails work OOTB. # Intentionally not doing the same for dvips because TeX is big. - (substituteAll { + (replaceVars ./gs-paths.patch { gs = "${ghostscript}/bin/gs"; - src = ./gs-paths.patch; }) ]; } diff --git a/pkgs/os-specific/linux/lvm2/common.nix b/pkgs/os-specific/linux/lvm2/common.nix index b690a19de29fe..830464053a050 100644 --- a/pkgs/os-specific/linux/lvm2/common.nix +++ b/pkgs/os-specific/linux/lvm2/common.nix @@ -6,7 +6,7 @@ , coreutils , libuuid , libaio -, substituteAll +, replaceVars , enableCmdlib ? false , enableDmeventd ? false , udevSupport ? !stdenv.hostPlatform.isStatic, udev @@ -91,15 +91,15 @@ stdenv.mkDerivation rec { patches = [ # fixes paths to and checks for tools - (substituteAll (let + (replaceVars ./fix-blkdeactivate.patch (let optionalTool = cond: pkg: if cond then pkg else "/run/current-system/sw"; in { - src = ./fix-blkdeactivate.patch; inherit coreutils; util_linux = optionalTool enableUtilLinux util-linux; mdadm = optionalTool enableMdadm mdadm; multipath_tools = optionalTool enableMultipath multipath-tools; vdo = optionalTool enableVDO vdo; + SBINDIR = null; # part of original source code in the patch's context })) ./fix-stdio-usage.patch ];