various: replace substituteAll with replaceVarsWith

This covers cases which need to use replaceVarsWith because the use
isExecutable = true.
This commit is contained in:
Wolfgang Walther 2024-11-30 20:00:23 +01:00
parent 321bd31b60
commit e58e0c158e
No known key found for this signature in database
GPG key ID: B39893FA5F65CAE1
20 changed files with 175 additions and 147 deletions

View file

@ -12,16 +12,18 @@
let let
cfg = config.programs.command-not-found; cfg = config.programs.command-not-found;
commandNotFound = pkgs.substituteAll { commandNotFound = pkgs.replaceVarsWith {
name = "command-not-found"; name = "command-not-found";
dir = "bin"; dir = "bin";
src = ./command-not-found.pl; src = ./command-not-found.pl;
isExecutable = true; isExecutable = true;
inherit (cfg) dbPath; replacements = {
perl = pkgs.perl.withPackages (p: [ inherit (cfg) dbPath;
p.DBDSQLite perl = pkgs.perl.withPackages (p: [
p.StringShellQuote p.DBDSQLite
]); p.StringShellQuote
]);
};
}; };
in in

View file

@ -49,27 +49,31 @@ let
preferLocalBuild = true; preferLocalBuild = true;
} ''mkdir --parents "$out/" ${concatStringsSep "\n" (mapModems mkLine)}''; } ''mkdir --parents "$out/" ${concatStringsSep "\n" (mapModems mkLine)}'';
setupSpoolScript = pkgs.substituteAll { setupSpoolScript = pkgs.replaceVarsWith {
name = "hylafax-setup-spool.sh"; name = "hylafax-setup-spool.sh";
src = ./spool.sh; src = ./spool.sh;
isExecutable = true; isExecutable = true;
faxuser = "uucp"; replacements = {
faxgroup = "uucp"; faxuser = "uucp";
lockPath = "/var/lock"; faxgroup = "uucp";
inherit globalConfigPath modemConfigPath; lockPath = "/var/lock";
inherit (cfg) sendmailPath spoolAreaPath userAccessFile; inherit globalConfigPath modemConfigPath;
inherit (pkgs) hylafaxplus runtimeShell; inherit (cfg) spoolAreaPath userAccessFile;
inherit (pkgs) hylafaxplus runtimeShell;
};
}; };
waitFaxqScript = pkgs.substituteAll { waitFaxqScript = pkgs.replaceVarsWith {
# This script checks the modems status files # This script checks the modems status files
# and waits until all modems report readiness. # and waits until all modems report readiness.
name = "hylafax-faxq-wait-start.sh"; name = "hylafax-faxq-wait-start.sh";
src = ./faxq-wait.sh; src = ./faxq-wait.sh;
isExecutable = true; isExecutable = true;
timeoutSec = toString 10; replacements = {
inherit (cfg) spoolAreaPath; timeoutSec = toString 10;
inherit (pkgs) runtimeShell; inherit (cfg) spoolAreaPath;
inherit (pkgs) runtimeShell;
};
}; };
sockets.hylafax-hfaxd = { sockets.hylafax-hfaxd = {

View file

@ -140,31 +140,33 @@ in
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
TimeoutStartSec = 300; TimeoutStartSec = 300;
ExecStart = pkgs.substituteAll { ExecStart = pkgs.replaceVarsWith {
src = ./initialize_kasmweb.sh; src = ./initialize_kasmweb.sh;
isExecutable = true; isExecutable = true;
binPath = lib.makeBinPath [ replacements = {
pkgs.docker binPath = lib.makeBinPath [
pkgs.openssl pkgs.docker
pkgs.gnused pkgs.openssl
pkgs.yq-go pkgs.gnused
]; pkgs.yq-go
runtimeShell = pkgs.runtimeShell; ];
kasmweb = pkgs.kasmweb; runtimeShell = pkgs.runtimeShell;
postgresUser = "postgres"; kasmweb = pkgs.kasmweb;
postgresPassword = "postgres"; postgresUser = "postgres";
inherit (cfg) postgresPassword = "postgres";
datastorePath inherit (cfg)
sslCertificate datastorePath
sslCertificateKey sslCertificate
redisPassword sslCertificateKey
networkSubnet redisPassword
defaultUserPassword networkSubnet
defaultAdminPassword defaultUserPassword
defaultManagerToken defaultAdminPassword
defaultRegistrationToken defaultManagerToken
defaultGuacToken defaultRegistrationToken
; defaultGuacToken
;
};
}; };
}; };
}; };

View file

@ -2,8 +2,7 @@
shopt -s nullglob shopt -s nullglob
export PATH=/empty export PATH=/empty:@path@
for i in @path@; do PATH=$PATH:$i/bin; done
default=$1 default=$1
if test -z "$1"; then if test -z "$1"; then

View file

@ -4,12 +4,14 @@ with lib;
let let
generationsDirBuilder = pkgs.substituteAll { generationsDirBuilder = pkgs.replaceVarsWith {
src = ./generations-dir-builder.sh; src = ./generations-dir-builder.sh;
isExecutable = true; isExecutable = true;
inherit (pkgs) bash; replacements = {
path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep]; inherit (pkgs) bash;
inherit (config.boot.loader.generationsDir) copyKernels; path = lib.makeBinPath [pkgs.coreutils pkgs.gnused pkgs.gnugrep];
inherit (config.boot.loader.generationsDir) copyKernels;
};
}; };
in in

View file

@ -1,8 +1,10 @@
{ pkgs }: { lib, pkgs }:
pkgs.substituteAll { pkgs.replaceVarsWith {
src = ./extlinux-conf-builder.sh; src = ./extlinux-conf-builder.sh;
isExecutable = true; isExecutable = true;
path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep]; replacements = {
inherit (pkgs) bash; path = lib.makeBinPath [pkgs.coreutils pkgs.gnused pkgs.gnugrep];
inherit (pkgs) bash;
};
} }

View file

@ -2,8 +2,7 @@
shopt -s nullglob shopt -s nullglob
export PATH=/empty export PATH=/empty:@path@
for i in @path@; do PATH=$PATH:$i/bin; done
usage() { usage() {
echo "usage: $0 -t <timeout> -c <path-to-default-configuration> [-d <boot-dir>] [-g <num-generations>] [-n <dtbName>] [-r]" >&2 echo "usage: $0 -t <timeout> -c <path-to-default-configuration> [-d <boot-dir>] [-g <num-generations>] [-n <dtbName>] [-r]" >&2

View file

@ -2,8 +2,7 @@
shopt -s nullglob shopt -s nullglob
export PATH=/empty export PATH=/empty:@path@
for i in @path@; do PATH=$PATH:$i/bin; done
if test $# -ne 1; then if test $# -ne 1; then
echo "Usage: init-script-builder.sh DEFAULT-CONFIG" echo "Usage: init-script-builder.sh DEFAULT-CONFIG"

View file

@ -9,16 +9,18 @@ with lib;
let let
initScriptBuilder = pkgs.substituteAll { initScriptBuilder = pkgs.replaceVarsWith {
src = ./init-script-builder.sh; src = ./init-script-builder.sh;
isExecutable = true; isExecutable = true;
inherit (pkgs) bash; replacements = {
inherit (config.system.nixos) distroName; inherit (pkgs) bash;
path = [ inherit (config.system.nixos) distroName;
pkgs.coreutils path = lib.makeBinPath [
pkgs.gnused pkgs.coreutils
pkgs.gnugrep pkgs.gnused
]; pkgs.gnugrep
];
};
}; };
in in

View file

@ -289,11 +289,8 @@ let
# The init script of boot stage 1 (loading kernel modules for # The init script of boot stage 1 (loading kernel modules for
# mounting the root FS). # mounting the root FS).
bootStage1 = pkgs.substituteAll { bootStage1 = pkgs.replaceVarsWith {
src = ./stage-1-init.sh; src = ./stage-1-init.sh;
shell = "${extraUtils}/bin/ash";
isExecutable = true; isExecutable = true;
postInstall = '' postInstall = ''
@ -304,35 +301,39 @@ let
${pkgs.buildPackages.busybox}/bin/ash -n $target ${pkgs.buildPackages.busybox}/bin/ash -n $target
''; '';
inherit linkUnits udevRules extraUtils; replacements = {
shell = "${extraUtils}/bin/ash";
inherit (config.boot) resumeDevice; inherit linkUnits udevRules extraUtils;
inherit (config.system.nixos) distroName; inherit (config.boot) resumeDevice;
inherit (config.system.build) earlyMountScript; inherit (config.system.nixos) distroName;
inherit (config.boot.initrd) checkJournalingFS verbose inherit (config.system.build) earlyMountScript;
preLVMCommands preDeviceCommands postDeviceCommands postResumeCommands postMountCommands preFailCommands kernelModules;
resumeDevices = map (sd: if sd ? device then sd.device else "/dev/disk/by-label/${sd.label}") inherit (config.boot.initrd) checkJournalingFS verbose
(filter (sd: hasPrefix "/dev/" sd.device && !sd.randomEncryption.enable preLVMCommands preDeviceCommands postDeviceCommands postResumeCommands postMountCommands preFailCommands kernelModules;
# Don't include zram devices
&& !(hasPrefix "/dev/zram" sd.device)
) config.swapDevices);
fsInfo = resumeDevices = map (sd: if sd ? device then sd.device else "/dev/disk/by-label/${sd.label}")
let f = fs: [ fs.mountPoint (if fs.device != null then fs.device else "/dev/disk/by-label/${fs.label}") fs.fsType (builtins.concatStringsSep "," fs.options) ]; (filter (sd: hasPrefix "/dev/" sd.device && !sd.randomEncryption.enable
in pkgs.writeText "initrd-fsinfo" (concatStringsSep "\n" (concatMap f fileSystems)); # Don't include zram devices
&& !(hasPrefix "/dev/zram" sd.device)
) config.swapDevices);
setHostId = optionalString (config.networking.hostId != null) '' fsInfo =
hi="${config.networking.hostId}" let f = fs: [ fs.mountPoint (if fs.device != null then fs.device else "/dev/disk/by-label/${fs.label}") fs.fsType (builtins.concatStringsSep "," fs.options) ];
${if pkgs.stdenv.hostPlatform.isBigEndian then '' in pkgs.writeText "initrd-fsinfo" (concatStringsSep "\n" (concatMap f fileSystems));
echo -ne "\x''${hi:0:2}\x''${hi:2:2}\x''${hi:4:2}\x''${hi:6:2}" > /etc/hostid
'' else '' setHostId = optionalString (config.networking.hostId != null) ''
echo -ne "\x''${hi:6:2}\x''${hi:4:2}\x''${hi:2:2}\x''${hi:0:2}" > /etc/hostid hi="${config.networking.hostId}"
''} ${if pkgs.stdenv.hostPlatform.isBigEndian then ''
''; echo -ne "\x''${hi:0:2}\x''${hi:2:2}\x''${hi:4:2}\x''${hi:6:2}" > /etc/hostid
'' else ''
echo -ne "\x''${hi:6:2}\x''${hi:4:2}\x''${hi:2:2}\x''${hi:0:2}" > /etc/hostid
''}
'';
};
}; };

View file

@ -11,26 +11,28 @@ let
useHostResolvConf = config.networking.resolvconf.enable && config.networking.useHostResolvConf; useHostResolvConf = config.networking.resolvconf.enable && config.networking.useHostResolvConf;
bootStage2 = pkgs.substituteAll { bootStage2 = pkgs.replaceVarsWith {
src = ./stage-2-init.sh; src = ./stage-2-init.sh;
shellDebug = "${pkgs.bashInteractive}/bin/bash";
shell = "${pkgs.bash}/bin/bash";
inherit (config.boot) readOnlyNixStore systemdExecutable extraSystemdUnitPaths;
inherit (config.system.nixos) distroName;
isExecutable = true; isExecutable = true;
inherit useHostResolvConf; replacements = {
inherit (config.system.build) earlyMountScript; shell = "${pkgs.bash}/bin/bash";
path = lib.makeBinPath ( systemConfig = null; # replaced in ../activation/top-level.nix
[ inherit (config.boot) readOnlyNixStore systemdExecutable;
pkgs.coreutils inherit (config.system.nixos) distroName;
pkgs.util-linux inherit useHostResolvConf;
] inherit (config.system.build) earlyMountScript;
++ lib.optional useHostResolvConf pkgs.openresolv path = lib.makeBinPath (
); [
postBootCommands = pkgs.writeText "local-cmds" '' pkgs.coreutils
${config.boot.postBootCommands} pkgs.util-linux
${config.powerManagement.powerUpCommands} ]
''; ++ lib.optional useHostResolvConf pkgs.openresolv
);
postBootCommands = pkgs.writeText "local-cmds" ''
${config.boot.postBootCommands}
${config.powerManagement.powerUpCommands}
'';
};
}; };
in in

View file

@ -1,4 +1,4 @@
#!@shell@ #!@runtimeShell@
# shellcheck shell=bash # shellcheck shell=bash
if [ -n "$DEBUG" ] ; then if [ -n "$DEBUG" ] ; then

View file

@ -11,19 +11,22 @@
}: }:
rec { rec {
appimage-exec = pkgs.substituteAll { appimage-exec = pkgs.replaceVarsWith {
src = ./appimage-exec.sh; src = ./appimage-exec.sh;
isExecutable = true; isExecutable = true;
dir = "bin"; dir = "bin";
path = lib.makeBinPath [ replacements = {
bash inherit (pkgs) runtimeShell;
binutils-unwrapped path = lib.makeBinPath [
coreutils bash
gawk binutils-unwrapped
libarchive coreutils
pv gawk
squashfsTools libarchive
]; pv
squashfsTools
];
};
}; };
extract = args@{ pname, version, name ? null, postExtract ? "", src, ... }: extract = args@{ pname, version, name ? null, postExtract ? "", src, ... }:

View file

@ -3,7 +3,7 @@
runtimeShell, runtimeShell,
nix, nix,
lib, lib,
substituteAll, replaceVarsWith,
nuget-to-nix, nuget-to-nix,
nixfmt-rfc-style, nixfmt-rfc-style,
cacert, cacert,
@ -63,12 +63,13 @@ attrs
let let
drv = builtins.unsafeDiscardOutputDependency fetch-drv.drvPath; drv = builtins.unsafeDiscardOutputDependency fetch-drv.drvPath;
innerScript = substituteAll { innerScript = replaceVarsWith {
src = ./fetch-deps.sh; src = ./fetch-deps.sh;
isExecutable = true; isExecutable = true;
inherit cacert; replacements = {
nugetToNix = nuget-to-nix; nugetToNix = nuget-to-nix;
nixfmt = nixfmt-rfc-style; nixfmt = nixfmt-rfc-style;
};
}; };
defaultDepsFile = defaultDepsFile =

View file

@ -2,7 +2,7 @@
lib, lib,
stdenv, stdenv,
fetchFromGitHub, fetchFromGitHub,
substituteAll, replaceVarsWith,
jam, jam,
cctools, cctools,
pkg-config, pkg-config,
@ -77,8 +77,8 @@ stdenv.mkDerivation rec {
installPhase = installPhase =
if stdenv.hostPlatform.isDarwin then if stdenv.hostPlatform.isDarwin then
(substituteAll { (replaceVarsWith {
inherit (stdenv) shell; replacements = { inherit (stdenv) shell; };
isExecutable = true; isExecutable = true;
src = ./darwin.sh; src = ./darwin.sh;
}) })

View file

@ -3,7 +3,7 @@
stdenv, stdenv,
rpm, rpm,
cpio, cpio,
substituteAll, replaceVarsWith,
}: }:
stdenv.mkDerivation { stdenv.mkDerivation {
@ -13,11 +13,13 @@ stdenv.mkDerivation {
install -Dm755 $script $out/bin/rpmextract install -Dm755 $script $out/bin/rpmextract
''; '';
script = substituteAll { script = replaceVarsWith {
src = ./rpmextract.sh; src = ./rpmextract.sh;
isExecutable = true; isExecutable = true;
inherit rpm cpio; replacements = {
inherit (stdenv) shell; inherit rpm cpio;
inherit (stdenv) shell;
};
}; };
meta = with lib; { meta = with lib; {

View file

@ -2,7 +2,7 @@
lib, lib,
stdenv, stdenv,
runCommand, runCommand,
substituteAll, replaceVarsWith,
coreutils, coreutils,
}: }:
@ -12,11 +12,13 @@ let
in in
runCommand name runCommand name
{ {
script = substituteAll { script = replaceVarsWith {
src = ./service-wrapper.sh; src = ./service-wrapper.sh;
isExecutable = true; isExecutable = true;
inherit (stdenv) shell; replacements = {
inherit coreutils; inherit (stdenv) shell;
inherit coreutils;
};
}; };
meta = with lib; { meta = with lib; {

View file

@ -16,7 +16,8 @@
cctools, cctools,
cairo, cairo,
gnome, gnome,
substituteAll, replaceVars,
replaceVarsWith,
buildPackages, buildPackages,
gobject-introspection-unwrapped, gobject-introspection-unwrapped,
nixStoreDir ? builtins.storeDir, nixStoreDir ? builtins.storeDir,
@ -63,17 +64,18 @@ stdenv.mkDerivation (finalAttrs: {
# Make g-ir-scanner put absolute path to GIR files it generates # Make g-ir-scanner put absolute path to GIR files it generates
# so that programs can just dlopen them without having to muck # so that programs can just dlopen them without having to muck
# with LD_LIBRARY_PATH environment variable. # with LD_LIBRARY_PATH environment variable.
(substituteAll { (replaceVars ./absolute_shlib_path.patch {
src = ./absolute_shlib_path.patch;
inherit nixStoreDir; inherit nixStoreDir;
}) })
] ]
++ lib.optionals x11Support [ ++ lib.optionals x11Support [
# Hardcode the cairo shared library path in the Cairo gir shipped with this package. # Hardcode the cairo shared library path in the Cairo gir shipped with this package.
# https://github.com/NixOS/nixpkgs/issues/34080 # https://github.com/NixOS/nixpkgs/issues/34080
(substituteAll { (replaceVars ./absolute_gir_path.patch {
src = ./absolute_gir_path.patch;
cairoLib = "${lib.getLib cairo}/lib"; cairoLib = "${lib.getLib cairo}/lib";
# original source code in patch's context
CAIRO_GIR_PACKAGE = null;
CAIRO_SHARED_LIBRARY = null;
}) })
]; ];
@ -117,12 +119,14 @@ stdenv.mkDerivation (finalAttrs: {
] ]
++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
"-Dgi_cross_ldd_wrapper=${ "-Dgi_cross_ldd_wrapper=${
substituteAll { replaceVarsWith {
name = "g-ir-scanner-lddwrapper"; name = "g-ir-scanner-lddwrapper";
isExecutable = true; isExecutable = true;
src = ./wrappers/g-ir-scanner-lddwrapper.sh; src = ./wrappers/g-ir-scanner-lddwrapper.sh;
inherit (buildPackages) bash; replacements = {
buildlddtree = "${buildPackages.pax-utils}/bin/lddtree"; inherit (buildPackages) bash;
buildlddtree = "${buildPackages.pax-utils}/bin/lddtree";
};
} }
}" }"
"-Dgi_cross_binary_wrapper=${stdenv.hostPlatform.emulator buildPackages}" "-Dgi_cross_binary_wrapper=${stdenv.hostPlatform.emulator buildPackages}"

View file

@ -1,7 +1,7 @@
{ {
lib, lib,
stdenv, stdenv,
substituteAll, replaceVarsWith,
}: }:
# Provides a facility to hook into rfkill changes. # Provides a facility to hook into rfkill changes.
@ -29,8 +29,8 @@
# in the rfkill package. # in the rfkill package.
let let
rfkillHook = substituteAll { rfkillHook = replaceVarsWith {
inherit (stdenv) shell; replacements = { inherit (stdenv) shell; };
isExecutable = true; isExecutable = true;
src = ./rfkill-hook.sh; src = ./rfkill-hook.sh;
}; };

View file

@ -6,7 +6,7 @@
autoreconfHook, autoreconfHook,
makeWrapper, makeWrapper,
pkg-config, pkg-config,
substituteAll, replaceVarsWith,
curl, curl,
gtk3, gtk3,
libassuan, libassuan,
@ -70,10 +70,12 @@ stdenv.mkDerivation rec {
postInstall = postInstall =
let let
eid-nssdb-in = substituteAll { eid-nssdb-in = replaceVarsWith {
inherit (stdenv) shell;
isExecutable = true; isExecutable = true;
src = ./eid-nssdb.in; src = ./eid-nssdb.in;
replacements = {
inherit (stdenv) shell;
};
}; };
in in
'' ''