···11-{ stdenvNoCC }:
11+{ lib, stdenvNoCC }:
22+/*
33+This is a wrapper around `substitute` in the stdenv.
44+55+Attribute arguments:
66+- `name` (optional): The name of the resulting derivation
77+- `src`: The path to the file to substitute
88+- `substitutions`: The list of substitution arguments to pass
99+ See https://nixos.org/manual/nixpkgs/stable/#fun-substitute
1010+- `replacements`: Deprecated version of `substitutions`
1111+ that doesn't support spaces in arguments.
1212+1313+Example:
2141515+```nix
1616+{ substitute }:
1717+substitute {
1818+ src = ./greeting.txt;
1919+ substitutions = [
2020+ "--replace"
2121+ "world"
2222+ "paul"
2323+ ];
2424+}
2525+```
2626+2727+See ../../test/substitute for tests
2828+*/
329args:
43055-# This is a wrapper around `substitute` in the stdenv.
66-# The `replacements` attribute should be a list of list of arguments
77-# to `substitute`, such as `[ "--replace" "sourcetext" "replacementtext" ]`
88-stdenvNoCC.mkDerivation ({
3131+let
932 name = if args ? name then args.name else baseNameOf (toString args.src);
3333+ deprecationReplacement = lib.pipe args.replacements [
3434+ lib.toList
3535+ (map (lib.splitString " "))
3636+ lib.concatLists
3737+ (lib.concatMapStringsSep " " lib.strings.escapeNixString)
3838+ ];
3939+ optionalDeprecationWarning =
4040+ # substitutions is only available starting 24.05.
4141+ # TODO: Remove support for replacements sometime after the next release
4242+ lib.warnIf (args ? replacements && lib.isInOldestRelease 2405) ''
4343+ pkgs.substitute: For "${name}", `replacements` is used, which is deprecated since it doesn't support arguments with spaces. Use `substitutions` instead:
4444+ substitutions = [ ${deprecationReplacement} ];'';
4545+in
4646+optionalDeprecationWarning
4747+stdenvNoCC.mkDerivation ({
4848+ inherit name;
1049 builder = ./substitute.sh;
1150 inherit (args) src;
1251 preferLocalBuild = true;
1352 allowSubstitutes = false;
1414-} // args // { replacements = args.replacements; })
5353+} // args // lib.optionalAttrs (args ? substitutions) {
5454+ substitutions =
5555+ assert lib.assertMsg (lib.isList args.substitutions) ''
5656+ pkgs.substitute: For "${name}", `substitutions` is passed, which is expected to be a list, but it's a ${builtins.typeOf args.substitutions} instead.'';
5757+ lib.escapeShellArgs args.substitutions;
5858+})