Home Explore Blog CI



nixpkgs

25th chunk of `doc/stdenv/stdenv.chapter.md`
d790bef4c469d70f0b45098ab92d9b22522823b16763b48e0000000100000ff7
This verifies that no references are left from the install binaries to the directory used to build those binaries. This ensures that the binaries do not need things outside the Nix store. This is currently supported in Linux only.

### `multiple-outputs.sh` {#multiple-outputs.sh}

This setup hook adds configure flags that tell packages to install files into any one of the proper outputs listed in `outputs`. This behavior can be turned off by setting `setOutputFlags` to false in the derivation environment. See [](#chap-multiple-output) for more information.

### `move-sbin.sh` {#move-sbin.sh}

This setup hook moves any binaries installed in the `sbin/` subdirectory into `bin/`. In addition, a link is provided from `sbin/` to `bin/` for compatibility.

### `move-lib64.sh` {#move-lib64.sh}

This setup hook moves any libraries installed in the `lib64/` subdirectory into `lib/`. In addition, a link is provided from `lib64/` to `lib/` for compatibility.

### `move-systemd-user-units.sh` {#move-systemd-user-units.sh}

This setup hook moves any systemd user units installed in the `lib/` subdirectory into `share/`. In addition, a link is provided from `share/` to `lib/` for compatibility. This is needed for systemd to find user services when installed into the user profile.

This hook only runs when compiling for Linux.

### `no-broken-symlinks.sh` {#no-broken-symlinks.sh}

This setup hook checks for, reports, and (by default) fails builds when "broken" symlinks are found. A symlink is considered "broken" if it's dangling (the target doesn't exist) or reflexive (it refers to itself).

This hook can be disabled by setting `dontCheckForBrokenSymlinks`.

::: {.note}
The hook only considers symlinks with targets inside the Nix store.
:::

::: {.note}
The check for reflexivity is direct and does not account for transitivity, so this hook will not prevent cycles in symlinks.
:::

### `set-source-date-epoch-to-latest.sh` {#set-source-date-epoch-to-latest.sh}

This sets `SOURCE_DATE_EPOCH` to the modification time of the most recent file.

### `add-bin-to-path.sh` {#add-bin-to-path.sh}

This setup hook checks if the `bin/` directory exists in the `$out` output path
and, if so, adds it to the `PATH` environment variable. This ensures that
executables located in `$out/bin` are accessible.

This hook is particularly useful during testing, as it allows packages to locate their executables without requiring manual modifications to the `PATH`.

**Note**: This hook is specifically designed for the `$out/bin` directory only
and does not handle and support other paths like `$sourceRoot/bin`. It may not
work as intended in cases with multiple outputs or when binaries are located in
directories like `sbin/`. These caveats should be considered when using this
hook, as they might introduce unexpected behavior in some specific cases.

### `writable-tmpdir-as-home.sh` {#writable-tmpdir-as-home.sh}

This setup hook ensures that the directory specified by the `HOME` environment
variable is writable. If it is not, the hook assigns `HOME` to a writable
directory (in `.home` in `$NIX_BUILD_TOP`). This adjustment is necessary for
certain packages that require write access to a home directory.

By setting `HOME` to a writable directory, this setup hook prevents failures in
packages that attempt to write to the home directory.

### Bintools Wrapper and hook {#bintools-wrapper}

The Bintools Wrapper wraps the binary utilities for a bunch of miscellaneous purposes. These are GNU Binutils when targeting Linux, and a mix of cctools and GNU binutils for Darwin. \[The “Bintools” name is supposed to be a compromise between “Binutils” and “cctools” not denoting any specific implementation.\] Specifically, the underlying bintools package, and a C standard library (glibc or Darwin’s libSystem, just for the dynamic loader) are all fed in, and dependency finding, hardening (see below), and purity checks for each are handled by the Bintools Wrapper. Packages typically depend on CC Wrapper, which in turn (at run time) depends on the Bintools Wrapper.

Title: More Default Setup Hooks in Nixpkgs stdenv
Summary
This section continues describing default setup hooks provided by `stdenv`: `multiple-outputs.sh` for configuring installation paths for multiple outputs, `move-sbin.sh` and `move-lib64.sh` for moving binaries and libraries, `move-systemd-user-units.sh` for systemd user units, `no-broken-symlinks.sh` for checking broken symlinks, `set-source-date-epoch-to-latest.sh` for setting the source date epoch, `add-bin-to-path.sh` for adding bin/ to PATH, `writable-tmpdir-as-home.sh` for ensuring HOME is writable, and the Bintools Wrapper for wrapping binary utilities and handling dependencies, hardening, and purity checks.