git.iko.soy/typeable/nixpkgs
on master help sign in
doc: document remove-references-to
commitf16a62bd63bbe01b795bb990de5f135bcafe318a authorGuillaume Girol <symphorien+git@xlumurb.eu> dateFri 11 Feb 2022, 12:00 (5 years ago) parent48d63e9
1 file changed+14−1
doc/stdenv/stdenv.chapter.md+14−1
doc/stdenv/stdenv.chapter.md+14−1
@@ -794,7 +794,7 @@ Hook executed at the start of the distribution phase.
794794
795795Hook executed at the end of the distribution phase.
796796
797−## Shell functions {#ssec-stdenv-functions}
797+## Shell functions and utilities {#ssec-stdenv-functions}
798798
799799The standard environment provides a number of useful functions.
800800
@@ -818,6 +818,19 @@ There’s many more kinds of arguments, they are documented in `nixpkgs/pkgs/bui
818818
819819Using 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.
820820
821+### `remove-references-to -t` \<storepath\> [ `-t` \<storepath\> ... ] \<file\> ... {#fun-remove-references-to}
822+
823+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.
824+To use this, add `removeReferencesTo` to `nativeBuildInputs`.
825+
826+As `remove-references-to` is an actual executable and not a shell function, it can be used with `find`.
827+Example removing all references to the compiler in the output:
828+```nix
829+postInstall = ''
830+ find "$out" -type f -exec remove-references-to -t ${stdenv.cc} '{}' +
831+'';
832+```
833+
821834### `substitute` \<infile\> \<outfile\> \<subs\> {#fun-substitute}
822835
823836Performs string substitution on the contents of \<infile\>, writing the result to \<outfile\>. The substitutions in \<subs\> are of the following form: