makeBinaryWrapper: Document

This commit is contained in:
Doron Behar 2021-10-02 01:20:41 +03:00 committed by Tobias Bergkvist
parent c310cb0d94
commit ba86a1916b

View file

@ -774,7 +774,7 @@ The standard environment provides a number of useful functions.
### `makeWrapper` \<executable\> \<wrapperfile\> \<args\> {#fun-makeWrapper} ### `makeWrapper` \<executable\> \<wrapperfile\> \<args\> {#fun-makeWrapper}
Constructs a wrapper for a program with various possible arguments. For example: A setup-hook that can be added to a derivation's inputs. It adds a `makeWrapper` bash function that constructs a wrapper for a program with various possible arguments. For example:
```bash ```bash
# adds `FOOBAR=baz` to `$out/bin/foo`s environment # adds `FOOBAR=baz` to `$out/bin/foo`s environment
@ -790,6 +790,14 @@ Theres many more kinds of arguments, they are documented in `nixpkgs/pkgs/bui
`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.
### `makeBinaryWrapper` \<executable\> \<wrapperfile\> \<args\> {#fun-makeBinaryWrapper}
A setup-hook very similar to `makeWrapper`, only 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). The arguments it accepts are <!-- TODO: make them identical? --> similar to those of `makeWrapper` and they are documented in `nixpkgs/pkgs/build-support/setup-hooks/make-binary-wrapper.sh`.
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 C code that generated the executable and there see the environment variables that were injected into the wrapper.
Similarly to `wrapProgram`, the `makeBinaryWrapper` setup-hook provides a `wrapProgramBinary` with similar command line arguments.
### `substitute` \<infile\> \<outfile\> \<subs\> {#fun-substitute} ### `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: Performs string substitution on the contents of \<infile\>, writing the result to \<outfile\>. The substitutions in \<subs\> are of the following form:
@ -865,7 +873,13 @@ someVar=$(stripHash $name)
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 automatically creates a sane wrapper file. It takes all the same arguments as `makeWrapper`, except for `--argv0`.
It cannot be applied multiple times, since it will overwrite the wrapper file. It cannot be applied multiple times, since it will overwrite the wrapper file and you will end up with double wrapping.
### `wrapProgramBinary` \<executable\> \<makeBinaryWrapperArgs\> {#fun-wrapProgramBinary}
Convenience function for `makeWrapperBinary` that automatically creates a sane wrapper file. It takes all the same arguments as `makeBinaryWrapper`, except for `--argv0`.
It cannot be applied multiple times, since it will overwrite the wrapper file and you will end up with double wrapping.
## Package setup hooks {#ssec-setup-hooks} ## Package setup hooks {#ssec-setup-hooks}