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.
This commit is contained in:
Wolfgang Walther 2024-11-23 13:45:07 +01:00
parent 217d3132cf
commit 4423b0746c
No known key found for this signature in database
GPG Key ID: B39893FA5F65CAE1
14 changed files with 69 additions and 79 deletions

View File

@ -51,7 +51,7 @@
, recurseIntoAttrs , recurseIntoAttrs
, sigtool , sigtool
, sqlite , sqlite
, substituteAll , replaceVars
, systemd , systemd
, tree-sitter , tree-sitter
, texinfo , texinfo
@ -148,12 +148,12 @@ mkDerivation (finalAttrs: {
inherit src; inherit src;
patches = patches fetchpatch ++ lib.optionals withNativeCompilation [ patches = patches fetchpatch ++ lib.optionals withNativeCompilation [
(substituteAll { (replaceVars (if lib.versionOlder finalAttrs.version "29"
src = if lib.versionOlder finalAttrs.version "29"
then ./native-comp-driver-options-28.patch then ./native-comp-driver-options-28.patch
else if lib.versionOlder finalAttrs.version "30" else if lib.versionOlder finalAttrs.version "30"
then ./native-comp-driver-options.patch then ./native-comp-driver-options.patch
else ./native-comp-driver-options-30.patch; else ./native-comp-driver-options-30.patch) {
backendPath = (lib.concatStringsSep " " backendPath = (lib.concatStringsSep " "
(builtins.map (x: ''"-B${x}"'') ([ (builtins.map (x: ''"-B${x}"'') ([
# Paths necessary so the JIT compiler finds its libraries: # Paths necessary so the JIT compiler finds its libraries:

View File

@ -1,5 +1,5 @@
{ {
mkDerivation, lib, ghostscript, substituteAll, mkDerivation, lib, ghostscript, replaceVars,
extra-cmake-modules, karchive, kio, libkexiv2, libkdcraw, kdegraphics-mobipocket extra-cmake-modules, karchive, kio, libkexiv2, libkdcraw, kdegraphics-mobipocket
}: }:
@ -15,9 +15,8 @@ mkDerivation {
patches = [ patches = [
# Hardcode patches to Ghostscript so PDF thumbnails work OOTB. # Hardcode patches to Ghostscript so PDF thumbnails work OOTB.
# Intentionally not doing the same for dvips because TeX is big. # Intentionally not doing the same for dvips because TeX is big.
(substituteAll { (replaceVars ./gs-paths.patch {
gs = "${ghostscript}/bin/gs"; gs = "${ghostscript}/bin/gs";
src = ./gs-paths.patch;
}) })
]; ];
} }

View File

@ -10,7 +10,7 @@
runCommandWith, runCommandWith,
stdenv, stdenv,
stdenvNoCC, stdenvNoCC,
substituteAll, replaceVars,
testers, testers,
}: }:
# Documentation is in doc/build-helpers/testers.chapter.md # Documentation is in doc/build-helpers/testers.chapter.md
@ -24,7 +24,7 @@
testBuildFailure = drv: drv.overrideAttrs (orig: { testBuildFailure = drv: drv.overrideAttrs (orig: {
builder = buildPackages.bash; builder = buildPackages.bash;
args = [ args = [
(substituteAll { coreutils = buildPackages.coreutils; src = ./expect-failure.sh; }) (replaceVars ./expect-failure.sh { coreutils = buildPackages.coreutils; })
orig.realBuilder or stdenv.shell orig.realBuilder or stdenv.shell
] ++ orig.args or ["-e" (orig.builder or ../../stdenv/generic/default-builder.sh)]; ] ++ orig.args or ["-e" (orig.builder or ../../stdenv/generic/default-builder.sh)];
}); });

View File

@ -1,16 +1,16 @@
@config_maxgid@ @config_maxgid@
DIR_BIN="@out_@/bin" DIR_BIN="@out@/bin"
DIR_FONTMAP="@out_@/share/ghostscript/@ghostscript_version@" DIR_FONTMAP="@out@/share/ghostscript/@ghostscript_version@"
DIR_LIB="@out_@/lib" DIR_LIB="@out@/lib"
DIR_LIBDATA="@out_@/spool/etc" DIR_LIBDATA="@out@/spool/etc"
DIR_LIBEXEC="@out_@/spool/bin" DIR_LIBEXEC="@out@/spool/bin"
DIR_LOCKS=/var/lock DIR_LOCKS=/var/lock
DIR_MAN="@out_@/share/man" DIR_MAN="@out@/share/man"
DIR_SBIN="@out_@/spool/bin" DIR_SBIN="@out@/spool/bin"
DIR_SPOOL="@out_@/spool" DIR_SPOOL="@out@/spool"
FONTMAP="@ghostscript@/share/ghostscript/@ghostscript_version@" FONTMAP="@ghostscript@/share/ghostscript/@ghostscript_version@"
PATH_AFM="@ghostscript@/share/ghostscript/fonts" PATH_AFM="@ghostscript@/share/ghostscript/fonts"
PATH_DPSRIP="@out_@/spool/bin/ps2fax" PATH_DPSRIP="@out@/spool/bin/ps2fax"
PATH_EGETTY="@coreutils@/bin/false" PATH_EGETTY="@coreutils@/bin/false"
PATH_GSRIP="@ghostscript@/bin/gs" PATH_GSRIP="@ghostscript@/bin/gs"
PATH_IMPRIP="@coreutils@/bin/false" PATH_IMPRIP="@coreutils@/bin/false"

View File

@ -3,7 +3,7 @@
, fakeroot , fakeroot
, fetchurl , fetchurl
, libfaketime , libfaketime
, substituteAll , replaceVars
## runtime dependencies ## runtime dependencies
, coreutils , coreutils
, file , file
@ -35,18 +35,14 @@ let
version = "7.0.9"; version = "7.0.9";
hash = "sha512-3OJwM4vFC9pzPozPobFLiNNx/Qnkl8BpNNziRUpJNBDLBxjtg/eDm3GnprS2hpt7VUoV4PCsFvp1hxhNnhlUwQ=="; hash = "sha512-3OJwM4vFC9pzPozPobFLiNNx/Qnkl8BpNNziRUpJNBDLBxjtg/eDm3GnprS2hpt7VUoV4PCsFvp1hxhNnhlUwQ==";
configSite = substituteAll { configSite = replaceVars ./config.site {
name = "${pname}-config.site";
src = ./config.site;
config_maxgid = lib.optionalString (maxgid!=null) ''CONFIG_MAXGID=${builtins.toString maxgid}''; config_maxgid = lib.optionalString (maxgid!=null) ''CONFIG_MAXGID=${builtins.toString maxgid}'';
ghostscript_version = ghostscript.version; 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; inherit coreutils ghostscript libtiff;
}; };
postPatch = substituteAll { postPatch = replaceVars ./post-patch.sh {
name = "${pname}-post-patch.sh";
src = ./post-patch.sh;
inherit configSite; inherit configSite;
maxuid = lib.optionalString (maxuid!=null) (builtins.toString maxuid); maxuid = lib.optionalString (maxuid!=null) (builtins.toString maxuid);
faxcover_binpath = lib.makeBinPath faxcover_binpath = lib.makeBinPath
@ -55,9 +51,7 @@ let
[stdenv.shellPackage coreutils findutils gnused gnugrep gawk]; [stdenv.shellPackage coreutils findutils gnused gnugrep gawk];
}; };
postInstall = substituteAll { postInstall = replaceVars ./post-install.sh {
name = "${pname}-post-install.sh";
src = ./post-install.sh;
inherit fakeroot libfaketime; inherit fakeroot libfaketime;
}; };

View File

@ -10,7 +10,6 @@
rpcsvc-proto, rpcsvc-proto,
libtirpc, libtirpc,
makeWrapper, makeWrapper,
substituteAll,
removeReferencesTo, removeReferencesTo,
replaceVars, replaceVars,
go, go,
@ -23,8 +22,8 @@ let
rev = modprobeVersion; rev = modprobeVersion;
sha256 = "sha256-iBRMkvOXacs/llTtvc/ZC5i/q9gc8lMuUHxMbu8A+Kg="; sha256 = "sha256-iBRMkvOXacs/llTtvc/ZC5i/q9gc8lMuUHxMbu8A+Kg=";
}; };
modprobePatch = substituteAll { modprobePatch = replaceVars ./modprobe.patch {
src = ./modprobe.patch;
inherit modprobeVersion; inherit modprobeVersion;
}; };
in in

View File

@ -1,7 +1,7 @@
{ lib { lib
, fetchFromGitHub , fetchFromGitHub
, perlPackages , perlPackages
, substituteAll , replaceVars
, ghostscript , ghostscript
, installShellFiles , installShellFiles
}: }:
@ -18,11 +18,11 @@ perlPackages.buildPerlPackage rec {
hash = "sha256-SPLwsGKLVhANoqSQ/GJ938cYjbjMbUOXkNn9so3aJTA="; hash = "sha256-SPLwsGKLVhANoqSQ/GJ938cYjbjMbUOXkNn9so3aJTA=";
}; };
patches = [ patches = [
(substituteAll { (replaceVars ./hardcode-deps.patch {
src = ./hardcode-deps.patch;
gs = "${ghostscript}/bin/gs"; 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 # will be the $out path of the main derivation
bbox = null;
}) })
]; ];

View File

@ -13,7 +13,7 @@
, makeWrapper , makeWrapper
, coreutils , coreutils
, scalingFactor ? 2 # this is to resize the fixed-size zod_launcher window , scalingFactor ? 2 # this is to resize the fixed-size zod_launcher window
, substituteAll , replaceVars
}: }:
let let
name = "zod-engine"; name = "zod-engine";
@ -70,9 +70,8 @@ let
# 2,3,4 look acceptable on my 4k monitor and 1 is unreadable. # 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 # also the ./ in the run command is removed to have easier time starting the game
patches = [ patches = [
(substituteAll { (replaceVars ./0002-add-scaling-factor-to-source.patch {
inherit scalingFactor; inherit scalingFactor;
src=./0002-add-scaling-factor-to-source.patch;
}) })
]; ];
postPatch = '' postPatch = ''

View File

@ -7,7 +7,7 @@
preLibcCrossHeaders, preLibcCrossHeaders,
libxcrypt, libxcrypt,
substitute, substitute,
substituteAll, replaceVars,
fetchFromGitHub, fetchFromGitHub,
fetchpatch, fetchpatch,
fetchpatch2, fetchpatch2,
@ -547,14 +547,17 @@ let
!args.stdenv.hostPlatform.isDarwin || !args.stdenv.targetPlatform.isDarwin !args.stdenv.hostPlatform.isDarwin || !args.stdenv.targetPlatform.isDarwin
) ./clang/add-nostdlibinc-flag.patch ) ./clang/add-nostdlibinc-flag.patch
++ [ ++ [
(substituteAll { (replaceVars
src = (
if (lib.versionOlder metadata.release_version "16") then if (lib.versionOlder metadata.release_version "16") then
./clang/clang-11-15-LLVMgold-path.patch ./clang/clang-11-15-LLVMgold-path.patch
else else
./clang/clang-at-least-16-LLVMgold-path.patch; ./clang/clang-at-least-16-LLVMgold-path.patch
libllvmLibdir = "${tools.libllvm.lib}/lib"; )
}) {
libllvmLibdir = "${tools.libllvm.lib}/lib";
}
)
] ]
# Backport version logic from Clang 16. This is needed by the following patch. # Backport version logic from Clang 16. This is needed by the following patch.
++ lib.optional (lib.versions.major metadata.release_version == "15") (fetchpatch { ++ lib.optional (lib.versions.major metadata.release_version == "15") (fetchpatch {
@ -662,9 +665,9 @@ let
patches = patches =
let let
resourceDirPatch = callPackage ( resourceDirPatch = callPackage (
{ substituteAll, libclang }: { replaceVars, libclang }:
(substituteAll { (replaceVars (metadata.getVersionFile "lldb/resource-dir.patch") {
src = metadata.getVersionFile "lldb/resource-dir.patch";
clangLibDir = "${lib.getLib libclang}/lib"; clangLibDir = "${lib.getLib libclang}/lib";
}).overrideAttrs }).overrideAttrs
(_: _: { name = "resource-dir.patch"; }) (_: _: { name = "resource-dir.patch"; })

View File

@ -39,7 +39,7 @@ index 2413329..f460bf6 100644
try: try:
- dll = DLL("SDL2", ["SDL2", "SDL2-2.0", "SDL2-2.0.0"], os.getenv("PYSDL2_DLL_PATH")) - 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: except RuntimeError as exc:
raise ImportError(exc) raise ImportError(exc)
@ -53,7 +53,7 @@ index 015eeaf..d6ce52f 100644
try: try:
- dll = DLL("SDL2_gfx", ["SDL2_gfx", "SDL2_gfx-1.0"], - dll = DLL("SDL2_gfx", ["SDL2_gfx", "SDL2_gfx-1.0"],
- os.getenv("PYSDL2_DLL_PATH")) - os.getenv("PYSDL2_DLL_PATH"))
+ dll = DLL("SDL2_gfx", "@sdl2_gfx@") + dll = DLL("SDL2_gfx", "@SDL2_gfx@")
except RuntimeError as exc: except RuntimeError as exc:
raise ImportError(exc) raise ImportError(exc)
@ -68,7 +68,7 @@ index a702136..dcdea51 100644
- dll = DLL( - dll = DLL(
- "SDL2_image", ["SDL2_image", "SDL2_image-2.0"], os.getenv("PYSDL2_DLL_PATH") - "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: except RuntimeError as exc:
raise ImportError(exc) raise ImportError(exc)
@ -82,7 +82,7 @@ index 5f2163c..23d95b0 100644
try: try:
- dll = DLL("SDL2_mixer", ["SDL2_mixer", "SDL2_mixer-2.0"], - dll = DLL("SDL2_mixer", ["SDL2_mixer", "SDL2_mixer-2.0"],
- os.getenv("PYSDL2_DLL_PATH")) - os.getenv("PYSDL2_DLL_PATH"))
+ dll = DLL("SDL2_mixer", "@sdl2_mixer@") + dll = DLL("SDL2_mixer", "@SDL2_mixer@")
except RuntimeError as exc: except RuntimeError as exc:
raise ImportError(exc) raise ImportError(exc)
@ -96,7 +96,7 @@ index 7c5f7db..61814cd 100644
try: try:
- dll = DLL("SDL2_ttf", ["SDL2_ttf", "SDL2_ttf-2.0"], - dll = DLL("SDL2_ttf", ["SDL2_ttf", "SDL2_ttf-2.0"],
- os.getenv("PYSDL2_DLL_PATH")) - os.getenv("PYSDL2_DLL_PATH"))
+ dll = DLL("SDL2_ttf", "@sdl2_ttf@") + dll = DLL("SDL2_ttf", "@SDL2_ttf@")
except RuntimeError as exc: except RuntimeError as exc:
raise ImportError(exc) raise ImportError(exc)

View File

@ -1,7 +1,7 @@
{ {
stdenv, stdenv,
lib, lib,
substituteAll, replaceVars,
fetchPypi, fetchPypi,
buildPythonPackage, buildPythonPackage,
SDL2, SDL2,
@ -38,21 +38,18 @@ buildPythonPackage rec {
]; ];
propagatedBuildInputs = [ SDL2 ]; propagatedBuildInputs = [ SDL2 ];
patches = [ patches = [
(substituteAll ( (replaceVars ./PySDL2-dll.patch (
{ builtins.mapAttrs
src = ./PySDL2-dll.patch; (_: pkg: "${pkg}/lib/lib${pkg.pname}${stdenv.hostPlatform.extensions.sharedLibrary}")
} {
// inherit
builtins.mapAttrs SDL2
(_: pkg: "${pkg}/lib/lib${pkg.pname}${stdenv.hostPlatform.extensions.sharedLibrary}") SDL2_ttf
{ SDL2_image
# substituteAll keys must start lowercase SDL2_gfx
sdl2 = SDL2; SDL2_mixer
sdl2_ttf = SDL2_ttf; ;
sdl2_image = SDL2_image; }
sdl2_gfx = SDL2_gfx;
sdl2_mixer = SDL2_mixer;
}
)) ))
]; ];

View File

@ -1,5 +1,5 @@
{ lib { lib
, substituteAll , replaceVars
, fetchurl , fetchurl
, ocaml , ocaml
, dune_3 , dune_3
@ -56,9 +56,9 @@ buildDunePackage {
old-patch = lib.versionOlder version "4.17"; old-patch = lib.versionOlder version "4.17";
in in
[ [
(substituteAll { (replaceVars (if old-patch then ./fix-paths.patch else ./fix-paths2.patch) {
src = if old-patch then ./fix-paths.patch else ./fix-paths2.patch;
dot_merlin_reader = "${dot-merlin-reader}/bin/dot-merlin-reader"; dot-merlin-reader = "${dot-merlin-reader}/bin/dot-merlin-reader";
dune = "${dune_3}/bin/dune"; dune = "${dune_3}/bin/dune";
}) })
]; ];

View File

@ -1,6 +1,6 @@
{ {
mkKdeDerivation, mkKdeDerivation,
substituteAll, replaceVars,
ghostscript, ghostscript,
}: }:
mkKdeDerivation { mkKdeDerivation {
@ -9,9 +9,8 @@ mkKdeDerivation {
patches = [ patches = [
# Hardcode patches to Ghostscript so PDF thumbnails work OOTB. # Hardcode patches to Ghostscript so PDF thumbnails work OOTB.
# Intentionally not doing the same for dvips because TeX is big. # Intentionally not doing the same for dvips because TeX is big.
(substituteAll { (replaceVars ./gs-paths.patch {
gs = "${ghostscript}/bin/gs"; gs = "${ghostscript}/bin/gs";
src = ./gs-paths.patch;
}) })
]; ];
} }

View File

@ -6,7 +6,7 @@
, coreutils , coreutils
, libuuid , libuuid
, libaio , libaio
, substituteAll , replaceVars
, enableCmdlib ? false , enableCmdlib ? false
, enableDmeventd ? false , enableDmeventd ? false
, udevSupport ? !stdenv.hostPlatform.isStatic, udev , udevSupport ? !stdenv.hostPlatform.isStatic, udev
@ -91,15 +91,15 @@ stdenv.mkDerivation rec {
patches = [ patches = [
# fixes paths to and checks for tools # 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"; optionalTool = cond: pkg: if cond then pkg else "/run/current-system/sw";
in { in {
src = ./fix-blkdeactivate.patch;
inherit coreutils; inherit coreutils;
util_linux = optionalTool enableUtilLinux util-linux; util_linux = optionalTool enableUtilLinux util-linux;
mdadm = optionalTool enableMdadm mdadm; mdadm = optionalTool enableMdadm mdadm;
multipath_tools = optionalTool enableMultipath multipath-tools; multipath_tools = optionalTool enableMultipath multipath-tools;
vdo = optionalTool enableVDO vdo; vdo = optionalTool enableVDO vdo;
SBINDIR = null; # part of original source code in the patch's context
})) }))
./fix-stdio-usage.patch ./fix-stdio-usage.patch
]; ];