···1-{ stdenvNoCC }:
0000000000002000000000000003args:
45-# This is a wrapper around `substitute` in the stdenv.
6-# The `replacements` attribute should be a list of list of arguments
7-# to `substitute`, such as `[ "--replace" "sourcetext" "replacementtext" ]`
8-stdenvNoCC.mkDerivation ({
9 name = if args ? name then args.name else baseNameOf (toString args.src);
000000000000000010 builder = ./substitute.sh;
11 inherit (args) src;
12 preferLocalBuild = true;
13 allowSubstitutes = false;
14-} // args // { replacements = args.replacements; })
00000
···1+{ lib, stdenvNoCC }:
2+/*
3+This is a wrapper around `substitute` in the stdenv.
4+5+Attribute arguments:
6+- `name` (optional): The name of the resulting derivation
7+- `src`: The path to the file to substitute
8+- `substitutions`: The list of substitution arguments to pass
9+ See https://nixos.org/manual/nixpkgs/stable/#fun-substitute
10+- `replacements`: Deprecated version of `substitutions`
11+ that doesn't support spaces in arguments.
12+13+Example:
1415+```nix
16+{ substitute }:
17+substitute {
18+ src = ./greeting.txt;
19+ substitutions = [
20+ "--replace"
21+ "world"
22+ "paul"
23+ ];
24+}
25+```
26+27+See ../../test/substitute for tests
28+*/
29args:
3031+let
00032 name = if args ? name then args.name else baseNameOf (toString args.src);
33+ deprecationReplacement = lib.pipe args.replacements [
34+ lib.toList
35+ (map (lib.splitString " "))
36+ lib.concatLists
37+ (lib.concatMapStringsSep " " lib.strings.escapeNixString)
38+ ];
39+ optionalDeprecationWarning =
40+ # substitutions is only available starting 24.05.
41+ # TODO: Remove support for replacements sometime after the next release
42+ lib.warnIf (args ? replacements && lib.isInOldestRelease 2405) ''
43+ pkgs.substitute: For "${name}", `replacements` is used, which is deprecated since it doesn't support arguments with spaces. Use `substitutions` instead:
44+ substitutions = [ ${deprecationReplacement} ];'';
45+in
46+optionalDeprecationWarning
47+stdenvNoCC.mkDerivation ({
48+ inherit name;
49 builder = ./substitute.sh;
50 inherit (args) src;
51 preferLocalBuild = true;
52 allowSubstitutes = false;
53+} // args // lib.optionalAttrs (args ? substitutions) {
54+ substitutions =
55+ assert lib.assertMsg (lib.isList args.substitutions) ''
56+ pkgs.substitute: For "${name}", `substitutions` is passed, which is expected to be a list, but it's a ${builtins.typeOf args.substitutions} instead.'';
57+ lib.escapeShellArgs args.substitutions;
58+})
+7-1
pkgs/build-support/substitute/substitute.sh
···8 mkdir -p $out/$dir
9fi
1011-substitute $src $target $replacements
0000001213if test -n "$isExecutable"; then
14 chmod +x $target
···8 mkdir -p $out/$dir
9fi
1011+substitutionsList=($replacements)
12+13+if [[ -v substitutions ]]; then
14+ eval "substitutionsList+=($substitutions)"
15+fi
16+17+substitute $src $target "${substitutionsList[@]}"
1819if test -n "$isExecutable"; then
20 chmod +x $target
···91 # this patch is from debian:
92 # https://sources.debian.org/data/main/b/binutils/2.38-3/debian/patches/mips64-default-n64.diff
93 (if stdenv.targetPlatform.isMusl
94- then substitute { src = ./mips64-default-n64.patch; replacements = [ "--replace" "gnuabi64" "muslabi64" ]; }
95 else ./mips64-default-n64.patch)
96 # On PowerPC, when generating assembly code, GCC generates a `.machine`
97 # custom instruction which instructs the assembler to generate code for this
···91 # this patch is from debian:
92 # https://sources.debian.org/data/main/b/binutils/2.38-3/debian/patches/mips64-default-n64.diff
93 (if stdenv.targetPlatform.isMusl
94+ then substitute { src = ./mips64-default-n64.patch; substitutions = [ "--replace" "gnuabi64" "muslabi64" ]; }
95 else ./mips64-default-n64.patch)
96 # On PowerPC, when generating assembly code, GCC generates a `.machine`
97 # custom instruction which instructs the assembler to generate code for this
+1-1
pkgs/development/tools/misc/binutils/default.nix
···105 # this patch is from debian:
106 # https://sources.debian.org/data/main/b/binutils/2.38-3/debian/patches/mips64-default-n64.diff
107 (if stdenv.targetPlatform.isMusl
108- then substitute { src = ./mips64-default-n64.patch; replacements = [ "--replace" "gnuabi64" "muslabi64" ]; }
109 else ./mips64-default-n64.patch)
110 # This patch fixes a bug in 2.40 on MinGW, which breaks DXVK when cross-building from Darwin.
111 # See https://sourceware.org/bugzilla/show_bug.cgi?id=30079
···105 # this patch is from debian:
106 # https://sources.debian.org/data/main/b/binutils/2.38-3/debian/patches/mips64-default-n64.diff
107 (if stdenv.targetPlatform.isMusl
108+ then substitute { src = ./mips64-default-n64.patch; substitutions = [ "--replace" "gnuabi64" "muslabi64" ]; }
109 else ./mips64-default-n64.patch)
110 # This patch fixes a bug in 2.40 on MinGW, which breaks DXVK when cross-building from Darwin.
111 # See https://sourceware.org/bugzilla/show_bug.cgi?id=30079