Skip to content

Commit

Permalink
various: replace substituteAll with replaceVars
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wolfgangwalther committed Dec 1, 2024
1 parent 217d313 commit ea0ada2
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 78 deletions.
8 changes: 4 additions & 4 deletions pkgs/applications/editors/emacs/make-emacs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
, recurseIntoAttrs
, sigtool
, sqlite
, substituteAll
, replaceVars
, systemd
, tree-sitter
, texinfo
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions pkgs/applications/kde/kdegraphics-thumbnailers/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
mkDerivation, lib, ghostscript, substituteAll,
mkDerivation, lib, ghostscript, replaceVars,
extra-cmake-modules, karchive, kio, libkexiv2, libkdcraw, kdegraphics-mobipocket
}:

Expand All @@ -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;
})
];
}
4 changes: 2 additions & 2 deletions pkgs/build-support/testers/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
runCommandWith,
stdenv,
stdenvNoCC,
substituteAll,
replaceVars,
testers,
}:
# Documentation is in doc/build-helpers/testers.chapter.md
Expand All @@ -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)];
});
Expand Down
18 changes: 9 additions & 9 deletions pkgs/by-name/hy/hylafaxplus/config.site
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
16 changes: 5 additions & 11 deletions pkgs/by-name/hy/hylafaxplus/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
, fakeroot
, fetchurl
, libfaketime
, substituteAll
, replaceVars
## runtime dependencies
, coreutils
, file
Expand Down Expand Up @@ -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
Expand All @@ -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;
};

Expand Down
5 changes: 2 additions & 3 deletions pkgs/by-name/li/libnvidia-container/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
rpcsvc-proto,
libtirpc,
makeWrapper,
substituteAll,
removeReferencesTo,
replaceVars,
go,
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkgs/by-name/ps/ps2eps/package.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ lib
, fetchFromGitHub
, perlPackages
, substituteAll
, replaceVars
, ghostscript
, installShellFiles
}:
Expand All @@ -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;
})
];

Expand Down
5 changes: 2 additions & 3 deletions pkgs/by-name/zo/zod/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
, makeWrapper
, coreutils
, scalingFactor ? 2 # this is to resize the fixed-size zod_launcher window
, substituteAll
, replaceVars
}:
let
name = "zod-engine";
Expand Down Expand Up @@ -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 = ''
Expand Down
15 changes: 7 additions & 8 deletions pkgs/development/compilers/llvm/common/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
preLibcCrossHeaders,
libxcrypt,
substitute,
substituteAll,
replaceVars,
fetchFromGitHub,
fetchpatch,
fetchpatch2,
Expand Down Expand Up @@ -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";
})
]
Expand Down Expand Up @@ -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"; })
Expand Down
10 changes: 5 additions & 5 deletions pkgs/development/python-modules/pysdl2/PySDL2-dll.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

23 changes: 7 additions & 16 deletions pkgs/development/python-modules/pysdl2/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
stdenv,
lib,
substituteAll,
replaceVars,
fetchPypi,
buildPythonPackage,
SDL2,
Expand Down Expand Up @@ -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;
}
))
];

Expand Down
8 changes: 4 additions & 4 deletions pkgs/development/tools/ocaml/merlin/4.x.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ lib
, substituteAll
, replaceVars
, fetchurl
, ocaml
, dune_3
Expand Down Expand Up @@ -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";
})
];
Expand Down
5 changes: 2 additions & 3 deletions pkgs/kde/gear/kdegraphics-thumbnailers/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
mkKdeDerivation,
substituteAll,
replaceVars,
ghostscript,
}:
mkKdeDerivation {
Expand All @@ -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;
})
];
}
6 changes: 3 additions & 3 deletions pkgs/os-specific/linux/lvm2/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
, coreutils
, libuuid
, libaio
, substituteAll
, replaceVars
, enableCmdlib ? false
, enableDmeventd ? false
, udevSupport ? !stdenv.hostPlatform.isStatic, udev
Expand Down Expand Up @@ -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
];
Expand Down

0 comments on commit ea0ada2

Please sign in to comment.