Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at python-updates 36 lines 1.5 kB view raw
1{ replaceVarsWith }: 2 3/** 4 `replaceVars` is a wrapper around the [bash function `substitute`](https://nixos.org/manual/nixpkgs/stable/#fun-substitute) 5 in the stdenv. It allows for terse replacement of names in the specified path, while checking 6 for common mistakes such as naming a replacement that does nothing or forgetting a variable which 7 needs to be replaced. 8 9 As with the [`--subst-var-by`](https://nixos.org/manual/nixpkgs/stable/#fun-substitute-subst-var-by) 10 flag, names are encoded as `@name@` in the provided file at the provided path. 11 12 Any unmatched variable names in the file at the provided path will cause a build failure. 13 14 By default, any remaining text that matches `@[A-Za-z_][0-9A-Za-z_'-]@` in the output after replacement 15 has occurred will cause a build failure. Variables can be excluded from this check by passing "null" for them. 16 17 # Inputs 18 19 `src` ([Store Path](https://nixos.org/manual/nix/latest/store/store-path.html#store-path) String) 20 : The file in which to replace variables. 21 22 `replacements` (AttrsOf String) 23 : Each entry in this set corresponds to a `--subst-var-by` entry in [`substitute`](https://nixos.org/manual/nixpkgs/stable/#fun-substitute) or 24 null to keep it unchanged. 25 26 # Example 27 28 ```nix 29 { replaceVars }: 30 31 replaceVars ./greeting.txt { world = "hello"; } 32 ``` 33 34 See `../../test/replace-vars/default.nix` for tests of this function. 35*/ 36src: replacements: replaceVarsWith { inherit src replacements; }