mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-01 23:22:37 +00:00
* Utility: the generic substituter. It substitutes all occurences of
`@var@' in the file `src', writing the result to $out, where `var' is any environment variable starting with a lowercase character. Example: genericSubstituter { src = ./file; foo = "bla"; shell = bash + "/bin/sh"; }; will replace `@foo@' with `bla' and `@shell@' with `/nix/store/...-bash-.../bin/sh'. svn path=/nixpkgs/trunk/; revision=6928
This commit is contained in:
parent
2f0d625a7a
commit
05c884b471
10
pkgs/build-support/substitute/generic-substituter.nix
Normal file
10
pkgs/build-support/substitute/generic-substituter.nix
Normal file
@ -0,0 +1,10 @@
|
||||
{stdenv}:
|
||||
|
||||
args:
|
||||
|
||||
stdenv.mkDerivation ({
|
||||
name = if args ? name then args.name else baseNameOf (toString args.src);
|
||||
builder = ./generic-substituter.sh;
|
||||
substitute = ./substitute.sh;
|
||||
inherit (args) src;
|
||||
} // args)
|
16
pkgs/build-support/substitute/generic-substituter.sh
Normal file
16
pkgs/build-support/substitute/generic-substituter.sh
Normal file
@ -0,0 +1,16 @@
|
||||
source $stdenv/setup
|
||||
source $substitute
|
||||
|
||||
args=
|
||||
|
||||
# Select all environment variables that start with a lowercase character.
|
||||
for envVar in $(env | sed "s/^[^a-z].*//" | sed "s/^\([^=]*\)=.*/\1/"); do
|
||||
echo "$envVar -> ${!envVar}"
|
||||
args="$args --subst-var $envVar"
|
||||
done
|
||||
|
||||
substitute $src $out $args
|
||||
|
||||
if test -n "$isExecutable"; then
|
||||
chmod +x $out
|
||||
fi
|
@ -188,6 +188,10 @@ rec {
|
||||
|
||||
substituter = ../build-support/substitute/substitute.sh;
|
||||
|
||||
genericSubstituter = import ../build-support/substitute/generic-substituter.nix {
|
||||
inherit stdenv;
|
||||
};
|
||||
|
||||
|
||||
### TOOLS
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user