summary refs log tree commit diff
path: root/doc
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2022-02-19 15:17:05 +0100
committerGitHub <noreply@github.com>2022-02-19 15:17:05 +0100
commite61eec13a5d933a7fe59db13f9a298e973f6fc1c (patch)
treeebd3aa27ef2ba5d38885e47db9dee9ea57d633c3 /doc
parent0c030a31afb711fd355e62348766f9dea5bae238 (diff)
parentf16a62bd63bbe01b795bb990de5f135bcafe318a (diff)
downloadnixpkgs-e61eec13a5d933a7fe59db13f9a298e973f6fc1c.tar
nixpkgs-e61eec13a5d933a7fe59db13f9a298e973f6fc1c.tar.gz
nixpkgs-e61eec13a5d933a7fe59db13f9a298e973f6fc1c.tar.bz2
nixpkgs-e61eec13a5d933a7fe59db13f9a298e973f6fc1c.tar.lz
nixpkgs-e61eec13a5d933a7fe59db13f9a298e973f6fc1c.tar.xz
nixpkgs-e61eec13a5d933a7fe59db13f9a298e973f6fc1c.tar.zst
nixpkgs-e61eec13a5d933a7fe59db13f9a298e973f6fc1c.zip
Merge pull request #159344 from symphorien/doc-remove-references-to
doc: document remove-references-to
Diffstat (limited to 'doc')
-rw-r--r--doc/stdenv/stdenv.chapter.md15
1 files changed, 14 insertions, 1 deletions
diff --git a/doc/stdenv/stdenv.chapter.md b/doc/stdenv/stdenv.chapter.md
index 51330f1ec9d..1d4ca99e3cb 100644
--- a/doc/stdenv/stdenv.chapter.md
+++ b/doc/stdenv/stdenv.chapter.md
@@ -797,7 +797,7 @@ Hook executed at the start of the distribution phase.
 
 Hook executed at the end of the distribution phase.
 
-## Shell functions {#ssec-stdenv-functions}
+## Shell functions and utilities {#ssec-stdenv-functions}
 
 The standard environment provides a number of useful functions.
 
@@ -821,6 +821,19 @@ There’s many more kinds of arguments, they are documented in `nixpkgs/pkgs/bui
 
 Using the `makeBinaryWrapper` implementation is usually preferred, as it creates a tiny _compiled_ wrapper executable, that can be used as a shebang interpreter. This is needed mostly on Darwin, where shebangs cannot point to scripts, [due to a limitation with the `execve`-syscall](https://stackoverflow.com/questions/67100831/macos-shebang-with-absolute-path-not-working). Compiled wrappers generated by `makeBinaryWrapper` can be inspected with `less <path-to-wrapper>` - by scrolling past the binary data you should be able to see the shell command that generated the executable and there see the environment variables that were injected into the wrapper.
 
+### `remove-references-to -t` \<storepath\> [ `-t` \<storepath\> ... ] \<file\> ... {#fun-remove-references-to}
+
+Removes the references of the specified files to the specified store files. This is done without changing the size of the file by replacing the hash by `eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee`, and should work on compiled executables. This is meant to be used to remove the dependency of the output on inputs that are known to be unnecessary at runtime. Of course, reckless usage will break the patched programs.
+To use this, add `removeReferencesTo` to `nativeBuildInputs`.
+
+As `remove-references-to` is an actual executable and not a shell function, it can be used with `find`.
+Example removing all references to the compiler in the output:
+```nix
+postInstall = ''
+  find "$out" -type f -exec remove-references-to -t ${stdenv.cc} '{}' +
+'';
+```
+
 ### `substitute` \<infile\> \<outfile\> \<subs\> {#fun-substitute}
 
 Performs string substitution on the contents of \<infile\>, writing the result to \<outfile\>. The substitutions in \<subs\> are of the following form: