summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2006-11-02 22:44:32 +0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2006-11-02 22:44:32 +0000
commit05c884b471dcb5bccd62a8b898ee6af11c95e456 (patch)
treeafdfce4f28583bb0b1df20fcd21814c4e3743f5e /pkgs/build-support
parent2f0d625a7a4d0a50c331f27bfe5773fec2e8f5e5 (diff)
downloadnixlib-05c884b471dcb5bccd62a8b898ee6af11c95e456.tar
nixlib-05c884b471dcb5bccd62a8b898ee6af11c95e456.tar.gz
nixlib-05c884b471dcb5bccd62a8b898ee6af11c95e456.tar.bz2
nixlib-05c884b471dcb5bccd62a8b898ee6af11c95e456.tar.lz
nixlib-05c884b471dcb5bccd62a8b898ee6af11c95e456.tar.xz
nixlib-05c884b471dcb5bccd62a8b898ee6af11c95e456.tar.zst
nixlib-05c884b471dcb5bccd62a8b898ee6af11c95e456.zip
* 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
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/substitute/generic-substituter.nix10
-rw-r--r--pkgs/build-support/substitute/generic-substituter.sh16
2 files changed, 26 insertions, 0 deletions
diff --git a/pkgs/build-support/substitute/generic-substituter.nix b/pkgs/build-support/substitute/generic-substituter.nix
new file mode 100644
index 000000000000..acc349ac816e
--- /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 000000000000..085e749c3313
--- /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