summary refs log tree commit diff
path: root/pkgs/build-support/remove-references-to/default.nix
diff options
context:
space:
mode:
authorLinus Heckemann <git@sphalerite.org>2017-03-06 17:54:54 +0000
committerLinus Heckemann <git@sphalerite.org>2017-03-09 12:01:55 +0000
commit603b799bcbcb8d49a9397bbd2896c1a454ee6ff6 (patch)
treeac6c86ba1e092458f0dc588505ab18b7b3f7d391 /pkgs/build-support/remove-references-to/default.nix
parent77ed6e3dd2a47fa52a36737415e164d0314cae66 (diff)
downloadnixpkgs-603b799bcbcb8d49a9397bbd2896c1a454ee6ff6.tar
nixpkgs-603b799bcbcb8d49a9397bbd2896c1a454ee6ff6.tar.gz
nixpkgs-603b799bcbcb8d49a9397bbd2896c1a454ee6ff6.tar.bz2
nixpkgs-603b799bcbcb8d49a9397bbd2896c1a454ee6ff6.tar.lz
nixpkgs-603b799bcbcb8d49a9397bbd2896c1a454ee6ff6.tar.xz
nixpkgs-603b799bcbcb8d49a9397bbd2896c1a454ee6ff6.tar.zst
nixpkgs-603b799bcbcb8d49a9397bbd2896c1a454ee6ff6.zip
Add removeReferencesTo for removing specific refs
This allows for a less blanket approach than nuke-refs, targetting specific
references that we know we don't want rather than all references that we don't
know we want.
Diffstat (limited to 'pkgs/build-support/remove-references-to/default.nix')
-rw-r--r--pkgs/build-support/remove-references-to/default.nix34
1 files changed, 34 insertions, 0 deletions
diff --git a/pkgs/build-support/remove-references-to/default.nix b/pkgs/build-support/remove-references-to/default.nix
new file mode 100644
index 00000000000..8b1d05fc230
--- /dev/null
+++ b/pkgs/build-support/remove-references-to/default.nix
@@ -0,0 +1,34 @@
+# The program `remove-references-to' created by this derivation replaces all
+# references to the given Nix store paths in the specified files by a
+# non-existent path (/nix/store/eeee...).  This is useful for getting rid of
+# dependencies that you know are not actually needed at runtime.
+
+{ stdenv, writeScriptBin }:
+
+writeScriptBin "remove-references-to" ''
+#! ${stdenv.shell} -e
+
+# References to remove
+targets=()
+while getopts t: o; do
+    case "$o" in
+        t) storeId=$(echo "$OPTARG" | sed -n "s|^$NIX_STORE/\\([a-z0-9]\{32\}\\)-.*|\1|p")
+           if [ -z "$storeId" ]; then
+               echo "-t argument must be a Nix store path"
+               exit 1
+           fi
+           targets+=("$storeId")
+    esac
+done
+shift $(($OPTIND-1))
+
+# Files to remove the references from
+regions=()
+for i in "$@"; do
+    test ! -L "$i" -a -f "$i" && regions+=("$i")
+done
+
+for target in "''${targets[@]}" ; do
+    sed -i -e "s|$NIX_STORE/$target-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" "''${regions[@]}"
+done
+''