diff options
author | Robert Hensing <roberth@users.noreply.github.com> | 2021-12-10 00:45:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-10 00:45:30 +0100 |
commit | 9fb7d91888fa24a7f96fd1915da2d4bc5e9b834e (patch) | |
tree | 2fcea539901c914ae08d574e8e88e32ffa1aca33 /doc | |
parent | 296081d9fa5a0606de52c72c3a9f2eb19f42a6ca (diff) | |
parent | 39b0aa415c67b6bcaabbb7110344503cc184575a (diff) | |
download | nixlib-9fb7d91888fa24a7f96fd1915da2d4bc5e9b834e.tar nixlib-9fb7d91888fa24a7f96fd1915da2d4bc5e9b834e.tar.gz nixlib-9fb7d91888fa24a7f96fd1915da2d4bc5e9b834e.tar.bz2 nixlib-9fb7d91888fa24a7f96fd1915da2d4bc5e9b834e.tar.lz nixlib-9fb7d91888fa24a7f96fd1915da2d4bc5e9b834e.tar.xz nixlib-9fb7d91888fa24a7f96fd1915da2d4bc5e9b834e.tar.zst nixlib-9fb7d91888fa24a7f96fd1915da2d4bc5e9b834e.zip |
Merge pull request #124556 from bergkvist/bergkvist/make-c-wrapper
Generate tiny compiled binary for wrapping executables
Diffstat (limited to 'doc')
-rw-r--r-- | doc/stdenv/stdenv.chapter.md | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/doc/stdenv/stdenv.chapter.md b/doc/stdenv/stdenv.chapter.md index c108fffd1b01..6d72bd0deb4f 100644 --- a/doc/stdenv/stdenv.chapter.md +++ b/doc/stdenv/stdenv.chapter.md @@ -796,7 +796,7 @@ The standard environment provides a number of useful functions. ### `makeWrapper` \<executable\> \<wrapperfile\> \<args\> {#fun-makeWrapper} -Constructs a wrapper for a program with various possible arguments. For example: +Constructs a wrapper for a program with various possible arguments. It is defined as part of 2 setup-hooks named `makeWrapper` and `makeBinaryWrapper` that implement the same bash functions. Hence, to use it you have to add `makeWrapper` to your `nativeBuildInputs`. Here's an example usage: ```bash # adds `FOOBAR=baz` to `$out/bin/foo`’s environment @@ -808,9 +808,11 @@ makeWrapper $out/bin/foo $wrapperfile --set FOOBAR baz makeWrapper $out/bin/foo $wrapperfile --prefix PATH : ${lib.makeBinPath [ hello git ]} ``` -There’s many more kinds of arguments, they are documented in `nixpkgs/pkgs/build-support/setup-hooks/make-wrapper.sh`. +There’s many more kinds of arguments, they are documented in `nixpkgs/pkgs/build-support/setup-hooks/make-wrapper.sh` for the `makeWrapper` implementation and in `nixpkgs/pkgs/build-support/setup-hooks/make-binary-wrapper.sh` for the `makeBinaryWrapper` implementation. -`wrapProgram` is a convenience function you probably want to use most of the time. +`wrapProgram` is a convenience function you probably want to use most of the time, implemented by both `makeWrapper` and `makeBinaryWrapper`. + +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. ### `substitute` \<infile\> \<outfile\> \<subs\> {#fun-substitute} @@ -885,9 +887,9 @@ someVar=$(stripHash $name) ### `wrapProgram` \<executable\> \<makeWrapperArgs\> {#fun-wrapProgram} -Convenience function for `makeWrapper` that automatically creates a sane wrapper file. It takes all the same arguments as `makeWrapper`, except for `--argv0`. +Convenience function for `makeWrapper` that replaces `<\executable\>` with a wrapper that executes the original program. It takes all the same arguments as `makeWrapper`, except for `--inherit-argv0` (used by the `makeBinaryWrapper` implementation) and `--argv0` (used by both `makeWrapper` and `makeBinaryWrapper` wrapper implementations). -It cannot be applied multiple times, since it will overwrite the wrapper file. +If you will apply it multiple times, it will overwrite the wrapper file and you will end up with double wrapping, which should be avoided. ## Package setup hooks {#ssec-setup-hooks} |