about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--pkgs/build-support/substitute/substitute.nix14
-rw-r--r--pkgs/build-support/substitute/substitute.sh18
-rw-r--r--pkgs/top-level/all-packages.nix2
3 files changed, 34 insertions, 0 deletions
diff --git a/pkgs/build-support/substitute/substitute.nix b/pkgs/build-support/substitute/substitute.nix
new file mode 100644
index 0000000000000..7f0332334585b
--- /dev/null
+++ b/pkgs/build-support/substitute/substitute.nix
@@ -0,0 +1,14 @@
+{ stdenvNoCC }:
+
+args:
+
+# This is a wrapper around `substitute` in the stdenv.
+# The `replacements` attribute should be a list of list of arguments
+# to `substitute`, such as `[ "--replace" "sourcetext" "replacementtext" ]`
+stdenvNoCC.mkDerivation ({
+  name = if args ? name then args.name else baseNameOf (toString args.src);
+  builder = ./substitute.sh;
+  inherit (args) src;
+  preferLocalBuild = true;
+  allowSubstitutes = false;
+} // args // { replacements = args.replacements; })
diff --git a/pkgs/build-support/substitute/substitute.sh b/pkgs/build-support/substitute/substitute.sh
new file mode 100644
index 0000000000000..dbac275a80ede
--- /dev/null
+++ b/pkgs/build-support/substitute/substitute.sh
@@ -0,0 +1,18 @@
+source $stdenv/setup
+
+args=
+
+target=$out
+if test -n "$dir"; then
+    target=$out/$dir/$name
+    mkdir -p $out/$dir
+fi
+
+substitute $src $target $replacements
+
+if test -n "$isExecutable"; then
+    chmod +x $target
+fi
+
+eval "$postInstall"
+
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 79b78ab3ad8b9..81242c4720c35 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -420,6 +420,8 @@ in
 
   srcOnly = args: callPackage ../build-support/src-only args;
 
+  substitute = callPackage ../build-support/substitute/substitute.nix { };
+
   substituteAll = callPackage ../build-support/substitute/substitute-all.nix { };
 
   substituteAllFiles = callPackage ../build-support/substitute-files/substitute-all-files.nix { };