diff --git a/pkgs/build-support/substitute/generic-substituter.nix b/pkgs/build-support/substitute/generic-substituter.nix new file mode 100644 index 00000000000..acc349ac816 --- /dev/null +++ b/pkgs/build-support/substitute/generic-substituter.nix @@ -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) diff --git a/pkgs/build-support/substitute/generic-substituter.sh b/pkgs/build-support/substitute/generic-substituter.sh new file mode 100644 index 00000000000..085e749c331 --- /dev/null +++ b/pkgs/build-support/substitute/generic-substituter.sh @@ -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 diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index f28f49072a9..d02d49df82c 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -188,6 +188,10 @@ rec { substituter = ../build-support/substitute/substitute.sh; + genericSubstituter = import ../build-support/substitute/generic-substituter.nix { + inherit stdenv; + }; + ### TOOLS