summary refs log tree commit diff
path: root/pkgs/build-support/substitute
diff options
context:
space:
mode:
authorDave Nicponski <dev.Nicponski.Dave@dev.bwater.com>2019-11-18 15:48:04 -0500
committerDave Nicponski <dev.Nicponski.Dave@dev.bwater.com>2019-11-18 15:55:41 -0500
commit7914de9b8c9da562e2cd342b96a8547cf482a16c (patch)
tree973545fc2429ae0671c7b509917a6b99a4a98af1 /pkgs/build-support/substitute
parenta6934e36534f8a87a78f877eee65c08fa9867ba5 (diff)
downloadnixpkgs-7914de9b8c9da562e2cd342b96a8547cf482a16c.tar
nixpkgs-7914de9b8c9da562e2cd342b96a8547cf482a16c.tar.gz
nixpkgs-7914de9b8c9da562e2cd342b96a8547cf482a16c.tar.bz2
nixpkgs-7914de9b8c9da562e2cd342b96a8547cf482a16c.tar.lz
nixpkgs-7914de9b8c9da562e2cd342b96a8547cf482a16c.tar.xz
nixpkgs-7914de9b8c9da562e2cd342b96a8547cf482a16c.tar.zst
nixpkgs-7914de9b8c9da562e2cd342b96a8547cf482a16c.zip
substitute: init at 0
Similar to the colocated `substituteAll` script and derivation, this
PR adds nix-level support for `substitute` directly.  This is useful,
for instance, to be able to easily make tweaks to patch files for an
existing derivation's existing patch files.
Diffstat (limited to 'pkgs/build-support/substitute')
-rw-r--r--pkgs/build-support/substitute/substitute.nix14
-rw-r--r--pkgs/build-support/substitute/substitute.sh18
2 files changed, 32 insertions, 0 deletions
diff --git a/pkgs/build-support/substitute/substitute.nix b/pkgs/build-support/substitute/substitute.nix
new file mode 100644
index 00000000000..7f033233458
--- /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 00000000000..dbac275a80e
--- /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"
+