nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 61 lines 1.9 kB view raw
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: 14 15 ```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: 30 31let 32 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.oldestSupportedReleaseIsAtLeast 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} ];''; 45in 46optionalDeprecationWarning stdenvNoCC.mkDerivation ( 47 { 48 inherit name; 49 builder = ./substitute.sh; 50 inherit (args) src; 51 preferLocalBuild = true; 52 allowSubstitutes = false; 53 } 54 // args 55 // lib.optionalAttrs (args ? substitutions) { 56 substitutions = 57 assert lib.assertMsg (lib.isList args.substitutions) 58 ''pkgs.substitute: For "${name}", `substitutions` is passed, which is expected to be a list, but it's a ${builtins.typeOf args.substitutions} instead.''; 59 lib.escapeShellArgs args.substitutions; 60 } 61)