diff options
25 files changed, 199 insertions, 168 deletions
diff --git a/doc/hooks/autoconf.section.md b/doc/hooks/autoconf.section.md new file mode 100644 index 0000000000000..13d75910f1929 --- /dev/null +++ b/doc/hooks/autoconf.section.md @@ -0,0 +1,4 @@ + +### Autoconf {#setup-hook-autoconf} + +The `autoreconfHook` derivation adds `autoreconfPhase`, which runs autoreconf, libtoolize and automake, essentially preparing the configure script in autotools-based builds. Most autotools-based packages come with the configure script pre-generated, but this hook is necessary for a few packages and when you need to patch the package’s configure scripts. diff --git a/doc/hooks/automake.section.md b/doc/hooks/automake.section.md new file mode 100644 index 0000000000000..562ac18fcd93c --- /dev/null +++ b/doc/hooks/automake.section.md @@ -0,0 +1,4 @@ + +### Automake {#setup-hook-automake} + +Adds the `share/aclocal` subdirectory of each build input to the `ACLOCAL_PATH` environment variable. diff --git a/doc/hooks/autopatchelf.section.md b/doc/hooks/autopatchelf.section.md new file mode 100644 index 0000000000000..9c2852ccf2794 --- /dev/null +++ b/doc/hooks/autopatchelf.section.md @@ -0,0 +1,12 @@ + +### autoPatchelfHook {#setup-hook-autopatchelfhook} + +This is a special setup hook which helps in packaging proprietary software in that it automatically tries to find missing shared library dependencies of ELF files based on the given `buildInputs` and `nativeBuildInputs`. + +You can also specify a `runtimeDependencies` variable which lists dependencies to be unconditionally added to rpath of all executables. This is useful for programs that use dlopen 3 to load libraries at runtime. + +In certain situations you may want to run the main command (`autoPatchelf`) of the setup hook on a file or a set of directories instead of unconditionally patching all outputs. This can be done by setting the `dontAutoPatchelf` environment variable to a non-empty value. + +By default `autoPatchelf` will fail as soon as any ELF file requires a dependency which cannot be resolved via the given build inputs. In some situations you might prefer to just leave missing dependencies unpatched and continue to patch the rest. This can be achieved by setting the `autoPatchelfIgnoreMissingDeps` environment variable to a non-empty value. `autoPatchelfIgnoreMissingDeps` can be set to a list like `autoPatchelfIgnoreMissingDeps = [ "libcuda.so.1" "libcudart.so.1" ];` or to simply `[ "*" ]` to ignore all missing dependencies. + +The `autoPatchelf` command also recognizes a `--no-recurse` command line flag, which prevents it from recursing into subdirectories. diff --git a/doc/hooks/breakpoint.section.md b/doc/hooks/breakpoint.section.md new file mode 100644 index 0000000000000..41e50653e91df --- /dev/null +++ b/doc/hooks/breakpoint.section.md @@ -0,0 +1,18 @@ + +### breakpointHook {#breakpointhook} + +This hook will make a build pause instead of stopping when a failure happens. It prevents nix from cleaning up the build environment immediately and allows the user to attach to a build environment using the `cntr` command. Upon build error it will print instructions on how to use `cntr`, which can be used to enter the environment for debugging. Installing cntr and running the command will provide shell access to the build sandbox of failed build. At `/var/lib/cntr` the sandboxed filesystem is mounted. All commands and files of the system are still accessible within the shell. To execute commands from the sandbox use the cntr exec subcommand. `cntr` is only supported on Linux-based platforms. To use it first add `cntr` to your `environment.systemPackages` on NixOS or alternatively to the root user on non-NixOS systems. Then in the package that is supposed to be inspected, add `breakpointHook` to `nativeBuildInputs`. + +```nix +nativeBuildInputs = [ breakpointHook ]; +``` + +When a build failure happens there will be an instruction printed that shows how to attach with `cntr` to the build sandbox. + +::: {.note} +::: {.title} +Caution with remote builds +::: + +This won’t work with remote builds as the build environment is on a different machine and can’t be accessed by `cntr`. Remote builds can be turned off by setting `--option builders ''` for `nix-build` or `--builders ''` for `nix build`. +::: diff --git a/doc/hooks/cmake.section.md b/doc/hooks/cmake.section.md new file mode 100644 index 0000000000000..58fbfa45a2e06 --- /dev/null +++ b/doc/hooks/cmake.section.md @@ -0,0 +1,4 @@ + +### cmake {#cmake} + +Overrides the default configure phase to run the CMake command. By default, we use the Make generator of CMake. In addition, dependencies are added automatically to `CMAKE_PREFIX_PATH` so that packages are correctly detected by CMake. Some additional flags are passed in to give similar behavior to configure-based packages. You can disable this hook’s behavior by setting `configurePhase` to a custom value, or by setting `dontUseCmakeConfigure`. `cmakeFlags` controls flags passed only to CMake. By default, parallel building is enabled as CMake supports parallel building almost everywhere. When Ninja is also in use, CMake will detect that and use the ninja generator. diff --git a/doc/hooks/gdk-pixbuf.section.md b/doc/hooks/gdk-pixbuf.section.md new file mode 100644 index 0000000000000..565216560abcb --- /dev/null +++ b/doc/hooks/gdk-pixbuf.section.md @@ -0,0 +1,4 @@ + +### gdk-pixbuf {#setup-hook-gdk-pixbuf} + +Exports `GDK_PIXBUF_MODULE_FILE` environment variable to the builder. Add librsvg package to `buildInputs` to get svg support. See also the [setup hook description in GNOME platform docs](#ssec-gnome-hooks-gdk-pixbuf). diff --git a/doc/hooks/ghc.section.md b/doc/hooks/ghc.section.md new file mode 100644 index 0000000000000..a4b0841ea486c --- /dev/null +++ b/doc/hooks/ghc.section.md @@ -0,0 +1,4 @@ + +### GHC {#ghc} + +Creates a temporary package database and registers every Haskell build input in it (TODO: how?). diff --git a/doc/hooks/gnome.section.md b/doc/hooks/gnome.section.md new file mode 100644 index 0000000000000..8c209d9b472ce --- /dev/null +++ b/doc/hooks/gnome.section.md @@ -0,0 +1,4 @@ + +### GNOME platform {#gnome-platform} + +Hooks related to GNOME platform and related libraries like GLib, GTK and GStreamer are described in [](#sec-language-gnome). diff --git a/doc/hooks/index.xml b/doc/hooks/index.xml index 6a046eae28857..ed703c03d8b07 100644 --- a/doc/hooks/index.xml +++ b/doc/hooks/index.xml @@ -6,5 +6,31 @@ <para> Nixpkgs has several hook packages that augment the stdenv phases. </para> + <para> + The stdenv built-in hooks are documented in <xref linkend="ssec-setup-hooks"/>. + </para> + <xi:include href="./autoconf.section.xml" /> + <xi:include href="./automake.section.xml" /> + <xi:include href="./autopatchelf.section.xml" /> + <xi:include href="./breakpoint.section.xml" /> + <xi:include href="./cmake.section.xml" /> + <xi:include href="./gdk-pixbuf.section.xml" /> + <xi:include href="./ghc.section.xml" /> + <xi:include href="./gnome.section.xml" /> + <xi:include href="./installShellFiles.section.xml" /> + <xi:include href="./libiconv.section.xml" /> + <xi:include href="./libxml2.section.xml" /> + <xi:include href="./meson.section.xml" /> + <xi:include href="./ninja.section.xml" /> + <xi:include href="./perl.section.xml" /> + <xi:include href="./pkg-config.section.xml" /> <xi:include href="./postgresql-test-hook.section.xml" /> + <xi:include href="./python.section.xml" /> + <xi:include href="./qt-4.section.xml" /> + <xi:include href="./scons.section.xml" /> + <xi:include href="./tetex-tex-live.section.xml" /> + <xi:include href="./unzip.section.xml" /> + <xi:include href="./validatePkgConfig.section.xml" /> + <xi:include href="./waf.section.xml" /> + <xi:include href="./xcbuild.section.xml" /> </chapter> diff --git a/doc/hooks/installShellFiles.section.md b/doc/hooks/installShellFiles.section.md new file mode 100644 index 0000000000000..d27527503fedd --- /dev/null +++ b/doc/hooks/installShellFiles.section.md @@ -0,0 +1,26 @@ + +### `installShellFiles` {#installshellfiles} + +This hook helps with installing manpages and shell completion files. It exposes 2 shell functions `installManPage` and `installShellCompletion` that can be used from your `postInstall` hook. + +The `installManPage` function takes one or more paths to manpages to install. The manpages must have a section suffix, and may optionally be compressed (with `.gz` suffix). This function will place them into the correct directory. + +The `installShellCompletion` function takes one or more paths to shell completion files. By default it will autodetect the shell type from the completion file extension, but you may also specify it by passing one of `--bash`, `--fish`, or `--zsh`. These flags apply to all paths listed after them (up until another shell flag is given). Each path may also have a custom installation name provided by providing a flag `--name NAME` before the path. If this flag is not provided, zsh completions will be renamed automatically such that `foobar.zsh` becomes `_foobar`. A root name may be provided for all paths using the flag `--cmd NAME`; this synthesizes the appropriate name depending on the shell (e.g. `--cmd foo` will synthesize the name `foo.bash` for bash and `_foo` for zsh). The path may also be a fifo or named fd (such as produced by `<(cmd)`), in which case the shell and name must be provided. + +```nix +nativeBuildInputs = [ installShellFiles ]; +postInstall = '' + installManPage doc/foobar.1 doc/barfoo.3 + # explicit behavior + installShellCompletion --bash --name foobar.bash share/completions.bash + installShellCompletion --fish --name foobar.fish share/completions.fish + installShellCompletion --zsh --name _foobar share/completions.zsh + # implicit behavior + installShellCompletion share/completions/foobar.{bash,fish,zsh} + # using named fd + installShellCompletion --cmd foobar \ + --bash <($out/bin/foobar --bash-completion) \ + --fish <($out/bin/foobar --fish-completion) \ + --zsh <($out/bin/foobar --zsh-completion) +''; +``` diff --git a/doc/hooks/libiconv.section.md b/doc/hooks/libiconv.section.md new file mode 100644 index 0000000000000..c228fe339e149 --- /dev/null +++ b/doc/hooks/libiconv.section.md @@ -0,0 +1,4 @@ + +### libiconv, libintl {#libiconv-libintl} + +A few libraries automatically add to `NIX_LDFLAGS` their library, making their symbols automatically available to the linker. This includes libiconv and libintl (gettext). This is done to provide compatibility between GNU Linux, where libiconv and libintl are bundled in, and other systems where that might not be the case. Sometimes, this behavior is not desired. To disable this behavior, set `dontAddExtraLibs`. diff --git a/doc/hooks/libxml2.section.md b/doc/hooks/libxml2.section.md new file mode 100644 index 0000000000000..770ef9ff3ffec --- /dev/null +++ b/doc/hooks/libxml2.section.md @@ -0,0 +1,4 @@ + +### libxml2 {#setup-hook-libxml2} + +Adds every file named `catalog.xml` found under the `xml/dtd` and `xml/xsl` subdirectories of each build input to the `XML_CATALOG_FILES` environment variable. diff --git a/doc/hooks/meson.section.md b/doc/hooks/meson.section.md new file mode 100644 index 0000000000000..32804b5e32f22 --- /dev/null +++ b/doc/hooks/meson.section.md @@ -0,0 +1,26 @@ + +### Meson {#meson} + +Overrides the configure phase to run meson to generate Ninja files. To run these files, you should accompany Meson with ninja. By default, `enableParallelBuilding` is enabled as Meson supports parallel building almost everywhere. + +#### Variables controlling Meson {#variables-controlling-meson} + +##### `mesonFlags` {#mesonflags} + +Controls the flags passed to meson. + +##### `mesonBuildType` {#mesonbuildtype} + +Which [`--buildtype`](https://mesonbuild.com/Builtin-options.html#core-options) to pass to Meson. We default to `plain`. + +##### `mesonAutoFeatures` {#mesonautofeatures} + +What value to set [`-Dauto_features=`](https://mesonbuild.com/Builtin-options.html#core-options) to. We default to `enabled`. + +##### `mesonWrapMode` {#mesonwrapmode} + +What value to set [`-Dwrap_mode=`](https://mesonbuild.com/Builtin-options.html#core-options) to. We default to `nodownload` as we disallow network access. + +##### `dontUseMesonConfigure` {#dontusemesonconfigure} + +Disables using Meson’s `configurePhase`. diff --git a/doc/hooks/ninja.section.md b/doc/hooks/ninja.section.md new file mode 100644 index 0000000000000..5ea1ee87070ad --- /dev/null +++ b/doc/hooks/ninja.section.md @@ -0,0 +1,4 @@ + +### ninja {#ninja} + +Overrides the build, install, and check phase to run ninja instead of make. You can disable this behavior with the `dontUseNinjaBuild`, `dontUseNinjaInstall`, and `dontUseNinjaCheck`, respectively. Parallel building is enabled by default in Ninja. diff --git a/doc/hooks/perl.section.md b/doc/hooks/perl.section.md new file mode 100644 index 0000000000000..403227a9bf181 --- /dev/null +++ b/doc/hooks/perl.section.md @@ -0,0 +1,4 @@ + +### Perl {#setup-hook-perl} + +Adds the `lib/site_perl` subdirectory of each build input to the `PERL5LIB` environment variable. For instance, if `buildInputs` contains Perl, then the `lib/site_perl` subdirectory of each input is added to the `PERL5LIB` environment variable. diff --git a/doc/hooks/pkg-config.section.md b/doc/hooks/pkg-config.section.md new file mode 100644 index 0000000000000..969c81f6d18ab --- /dev/null +++ b/doc/hooks/pkg-config.section.md @@ -0,0 +1,4 @@ + +### pkg-config {#setup-hook-pkg-config} + +Adds the `lib/pkgconfig` and `share/pkgconfig` subdirectories of each build input to the `PKG_CONFIG_PATH` environment variable. diff --git a/doc/hooks/python.section.md b/doc/hooks/python.section.md new file mode 100644 index 0000000000000..a46a727e95b10 --- /dev/null +++ b/doc/hooks/python.section.md @@ -0,0 +1,4 @@ + +### Python {#setup-hook-python} + +Adds the `lib/${python.libPrefix}/site-packages` subdirectory of each build input to the `PYTHONPATH` environment variable. diff --git a/doc/hooks/qt-4.section.md b/doc/hooks/qt-4.section.md new file mode 100644 index 0000000000000..f15d858e2377c --- /dev/null +++ b/doc/hooks/qt-4.section.md @@ -0,0 +1,4 @@ + +### Qt 4 {#qt-4} + +Sets the `QTDIR` environment variable to Qt’s path. diff --git a/doc/hooks/scons.section.md b/doc/hooks/scons.section.md new file mode 100644 index 0000000000000..1392269e5d55d --- /dev/null +++ b/doc/hooks/scons.section.md @@ -0,0 +1,4 @@ + +### scons {#scons} + +Overrides the build, install, and check phases. This uses the scons build system as a replacement for make. scons does not provide a configure phase, so everything is managed at build and install time. diff --git a/doc/hooks/tetex-tex-live.section.md b/doc/hooks/tetex-tex-live.section.md new file mode 100644 index 0000000000000..0ecdcc12e45ab --- /dev/null +++ b/doc/hooks/tetex-tex-live.section.md @@ -0,0 +1,4 @@ + +### teTeX / TeX Live {#tetex-tex-live} + +Adds the `share/texmf-nix` subdirectory of each build input to the `TEXINPUTS` environment variable. diff --git a/doc/hooks/unzip.section.md b/doc/hooks/unzip.section.md new file mode 100644 index 0000000000000..91dc072de6621 --- /dev/null +++ b/doc/hooks/unzip.section.md @@ -0,0 +1,4 @@ + +### unzip {#unzip} + +This setup hook will allow you to unzip .zip files specified in `$src`. There are many similar packages like `unrar`, `undmg`, etc. diff --git a/doc/hooks/validatePkgConfig.section.md b/doc/hooks/validatePkgConfig.section.md new file mode 100644 index 0000000000000..8719ae930fcb0 --- /dev/null +++ b/doc/hooks/validatePkgConfig.section.md @@ -0,0 +1,4 @@ + +### validatePkgConfig {#validatepkgconfig} + +The `validatePkgConfig` hook validates all pkg-config (`.pc`) files in a package. This helps catching some common errors in pkg-config files, such as undefined variables. diff --git a/doc/hooks/waf.section.md b/doc/hooks/waf.section.md new file mode 100644 index 0000000000000..de65abde4502b --- /dev/null +++ b/doc/hooks/waf.section.md @@ -0,0 +1,4 @@ + +### wafHook {#wafhook} + +Overrides the configure, build, and install phases. This will run the “waf” script used by many projects. If `wafPath` (default `./waf`) doesn’t exist, it will copy the version of waf available in Nixpkgs. `wafFlags` can be used to pass flags to the waf script. diff --git a/doc/hooks/xcbuild.section.md b/doc/hooks/xcbuild.section.md new file mode 100644 index 0000000000000..1426431f6dce2 --- /dev/null +++ b/doc/hooks/xcbuild.section.md @@ -0,0 +1,4 @@ + +### xcbuildHook {#xcbuildhook} + +Overrides the build and install phases to run the "xcbuild" command. This hook is needed when a project only comes with build files for the XCode build system. You can disable this behavior by setting buildPhase and configurePhase to a custom value. xcbuildFlags controls flags passed only to xcbuild. diff --git a/doc/stdenv/stdenv.chapter.md b/doc/stdenv/stdenv.chapter.md index a304c0e146577..12213d7ca5def 100644 --- a/doc/stdenv/stdenv.chapter.md +++ b/doc/stdenv/stdenv.chapter.md @@ -1010,19 +1010,19 @@ The *existence* of setups hooks has long been documented and packages inside Nix First, let’s cover some setup hooks that are part of Nixpkgs default `stdenv`. This means that they are run for every package built using `stdenv.mkDerivation` or when using a custom builder that has `source $stdenv/setup`. Some of these are platform specific, so they may run on Linux but not Darwin or vice-versa. -### Default hook `move-docs.sh` {#move-docs.sh} +### `move-docs.sh` {#move-docs.sh} This setup hook moves any installed documentation to the `/share` subdirectory directory. This includes the man, doc and info directories. This is needed for legacy programs that do not know how to use the `share` subdirectory. -### Default hook `compress-man-pages.sh` {#compress-man-pages.sh} +### `compress-man-pages.sh` {#compress-man-pages.sh} This setup hook compresses any man pages that have been installed. The compression is done using the gzip program. This helps to reduce the installed size of packages. -### Default hook `strip.sh` {#strip.sh} +### `strip.sh` {#strip.sh} This runs the strip command on installed binaries and libraries. This removes unnecessary information like debug symbols when they are not needed. This also helps to reduce the installed size of packages. -### Default hook `patch-shebangs.sh` {#patch-shebangs.sh} +### `patch-shebangs.sh` {#patch-shebangs.sh} This setup hook patches installed scripts to add Nix store paths to their shebang interpreter as found in the build environment. The [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) line tells a Unix-like operating system which interpreter to use to execute the script's contents. @@ -1089,32 +1089,37 @@ If you need to run `patchShebangs` at build time, it must be called explicitly w [patchShebangs]: https://github.com/NixOS/nixpkgs/blob/19d4f7dc485f74109bd66ef74231285ff797a823/pkgs/build-support/setup-hooks/patch-shebangs.sh#L24-L105 [patchShebangsAuto]: https://github.com/NixOS/nixpkgs/blob/19d4f7dc485f74109bd66ef74231285ff797a823/pkgs/build-support/setup-hooks/patch-shebangs.sh#L107-L119 -### Default hook `audit-tmpdir.sh` {#audit-tmpdir.sh} +### `audit-tmpdir.sh` {#audit-tmpdir.sh} 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. -### Default hook `multiple-outputs.sh` {#multiple-outputs.sh} +### `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. -### Default hook `move-sbin.sh` {#move-sbin.sh} +### `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. -### Default hook `move-lib64.sh` {#move-lib64.sh} +### `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. -### Default hook `move-systemd-user-units.sh` {#move-systemd-user-units.sh} +### `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. -### Default hook `set-source-date-epoch-to-latest.sh` {#set-source-date-epoch-to-latest.sh} +### `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. +### Other hooks + +Many other packages provide hooks, that are not part of `stdenv`. You can find +these in the [Hooks Reference](#chap-hooks). + ### Bintools Wrapper {#bintools-wrapper} The Bintools Wrapper wraps the binary utilities for a bunch of miscellaneous purposes. These are GNU Binutils when targetting 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. @@ -1135,164 +1140,6 @@ Similarly, the CC Wrapper follows the Bintools Wrapper in defining standard envi Here are some more packages that provide a setup hook. Since the list of hooks is extensible, this is not an exhaustive list. The mechanism is only to be used as a last resort, so it might cover most uses. -### Optional hook Perl {#setup-hook-perl} - -Adds the `lib/site_perl` subdirectory of each build input to the `PERL5LIB` environment variable. For instance, if `buildInputs` contains Perl, then the `lib/site_perl` subdirectory of each input is added to the `PERL5LIB` environment variable. - -### Optional hook Python {#setup-hook-python} - -Adds the `lib/${python.libPrefix}/site-packages` subdirectory of each build input to the `PYTHONPATH` environment variable. - -### Optional hook pkg-config {#setup-hook-pkg-config} - -Adds the `lib/pkgconfig` and `share/pkgconfig` subdirectories of each build input to the `PKG_CONFIG_PATH` environment variable. - -### Optional hook Automake {#setup-hook-automake} - -Adds the `share/aclocal` subdirectory of each build input to the `ACLOCAL_PATH` environment variable. - -### Optional hook Autoconf {#setup-hook-autoconf} - -The `autoreconfHook` derivation adds `autoreconfPhase`, which runs autoreconf, libtoolize and automake, essentially preparing the configure script in autotools-based builds. Most autotools-based packages come with the configure script pre-generated, but this hook is necessary for a few packages and when you need to patch the package’s configure scripts. - -### Optional hook libxml2 {#setup-hook-libxml2} - -Adds every file named `catalog.xml` found under the `xml/dtd` and `xml/xsl` subdirectories of each build input to the `XML_CATALOG_FILES` environment variable. - -### Optional hook teTeX / TeX Live {#tetex-tex-live} - -Adds the `share/texmf-nix` subdirectory of each build input to the `TEXINPUTS` environment variable. - -### Optional hook Qt 4 {#qt-4} - -Sets the `QTDIR` environment variable to Qt’s path. - -### Optional hook gdk-pixbuf {#setup-hook-gdk-pixbuf} - -Exports `GDK_PIXBUF_MODULE_FILE` environment variable to the builder. Add librsvg package to `buildInputs` to get svg support. See also the [setup hook description in GNOME platform docs](#ssec-gnome-hooks-gdk-pixbuf). - -### Optional hook GHC {#ghc} - -Creates a temporary package database and registers every Haskell build input in it (TODO: how?). - -### Optional hook GNOME platform {#gnome-platform} - -Hooks related to GNOME platform and related libraries like GLib, GTK and GStreamer are described in [](#sec-language-gnome). - -### Optional hook autoPatchelfHook {#setup-hook-autopatchelfhook} - -This is a special setup hook which helps in packaging proprietary software in that it automatically tries to find missing shared library dependencies of ELF files based on the given `buildInputs` and `nativeBuildInputs`. - -You can also specify a `runtimeDependencies` variable which lists dependencies to be unconditionally added to rpath of all executables. This is useful for programs that use dlopen 3 to load libraries at runtime. - -In certain situations you may want to run the main command (`autoPatchelf`) of the setup hook on a file or a set of directories instead of unconditionally patching all outputs. This can be done by setting the `dontAutoPatchelf` environment variable to a non-empty value. - -By default `autoPatchelf` will fail as soon as any ELF file requires a dependency which cannot be resolved via the given build inputs. In some situations you might prefer to just leave missing dependencies unpatched and continue to patch the rest. This can be achieved by setting the `autoPatchelfIgnoreMissingDeps` environment variable to a non-empty value. `autoPatchelfIgnoreMissingDeps` can be set to a list like `autoPatchelfIgnoreMissingDeps = [ "libcuda.so.1" "libcudart.so.1" ];` or to simply `[ "*" ]` to ignore all missing dependencies. - -The `autoPatchelf` command also recognizes a `--no-recurse` command line flag, which prevents it from recursing into subdirectories. - -### Optional hook breakpointHook {#breakpointhook} - -This hook will make a build pause instead of stopping when a failure happens. It prevents nix from cleaning up the build environment immediately and allows the user to attach to a build environment using the `cntr` command. Upon build error it will print instructions on how to use `cntr`, which can be used to enter the environment for debugging. Installing cntr and running the command will provide shell access to the build sandbox of failed build. At `/var/lib/cntr` the sandboxed filesystem is mounted. All commands and files of the system are still accessible within the shell. To execute commands from the sandbox use the cntr exec subcommand. `cntr` is only supported on Linux-based platforms. To use it first add `cntr` to your `environment.systemPackages` on NixOS or alternatively to the root user on non-NixOS systems. Then in the package that is supposed to be inspected, add `breakpointHook` to `nativeBuildInputs`. - -```nix -nativeBuildInputs = [ breakpointHook ]; -``` - -When a build failure happens there will be an instruction printed that shows how to attach with `cntr` to the build sandbox. - -::: {.note} -::: {.title} -Caution with remote builds -::: - -This won’t work with remote builds as the build environment is on a different machine and can’t be accessed by `cntr`. Remote builds can be turned off by setting `--option builders ''` for `nix-build` or `--builders ''` for `nix build`. -::: - -### Optional hook `installShellFiles` {#installshellfiles} - -This hook helps with installing manpages and shell completion files. It exposes 2 shell functions `installManPage` and `installShellCompletion` that can be used from your `postInstall` hook. - -The `installManPage` function takes one or more paths to manpages to install. The manpages must have a section suffix, and may optionally be compressed (with `.gz` suffix). This function will place them into the correct directory. - -The `installShellCompletion` function takes one or more paths to shell completion files. By default it will autodetect the shell type from the completion file extension, but you may also specify it by passing one of `--bash`, `--fish`, or `--zsh`. These flags apply to all paths listed after them (up until another shell flag is given). Each path may also have a custom installation name provided by providing a flag `--name NAME` before the path. If this flag is not provided, zsh completions will be renamed automatically such that `foobar.zsh` becomes `_foobar`. A root name may be provided for all paths using the flag `--cmd NAME`; this synthesizes the appropriate name depending on the shell (e.g. `--cmd foo` will synthesize the name `foo.bash` for bash and `_foo` for zsh). The path may also be a fifo or named fd (such as produced by `<(cmd)`), in which case the shell and name must be provided. - -```nix -nativeBuildInputs = [ installShellFiles ]; -postInstall = '' - installManPage doc/foobar.1 doc/barfoo.3 - # explicit behavior - installShellCompletion --bash --name foobar.bash share/completions.bash - installShellCompletion --fish --name foobar.fish share/completions.fish - installShellCompletion --zsh --name _foobar share/completions.zsh - # implicit behavior - installShellCompletion share/completions/foobar.{bash,fish,zsh} - # using named fd - installShellCompletion --cmd foobar \ - --bash <($out/bin/foobar --bash-completion) \ - --fish <($out/bin/foobar --fish-completion) \ - --zsh <($out/bin/foobar --zsh-completion) -''; -``` - -### Optional hook libiconv, libintl {#libiconv-libintl} - -A few libraries automatically add to `NIX_LDFLAGS` their library, making their symbols automatically available to the linker. This includes libiconv and libintl (gettext). This is done to provide compatibility between GNU Linux, where libiconv and libintl are bundled in, and other systems where that might not be the case. Sometimes, this behavior is not desired. To disable this behavior, set `dontAddExtraLibs`. - -### Optional hook validatePkgConfig {#validatepkgconfig} - -The `validatePkgConfig` hook validates all pkg-config (`.pc`) files in a package. This helps catching some common errors in pkg-config files, such as undefined variables. - -### Optional hook cmake {#cmake} - -Overrides the default configure phase to run the CMake command. By default, we use the Make generator of CMake. In addition, dependencies are added automatically to `CMAKE_PREFIX_PATH` so that packages are correctly detected by CMake. Some additional flags are passed in to give similar behavior to configure-based packages. You can disable this hook’s behavior by setting `configurePhase` to a custom value, or by setting `dontUseCmakeConfigure`. `cmakeFlags` controls flags passed only to CMake. By default, parallel building is enabled as CMake supports parallel building almost everywhere. When Ninja is also in use, CMake will detect that and use the ninja generator. - -### Optional hook xcbuildHook {#xcbuildhook} - -Overrides the build and install phases to run the "xcbuild" command. This hook is needed when a project only comes with build files for the XCode build system. You can disable this behavior by setting buildPhase and configurePhase to a custom value. xcbuildFlags controls flags passed only to xcbuild. - -### Optional hook Meson {#meson} - -Overrides the configure phase to run meson to generate Ninja files. To run these files, you should accompany Meson with ninja. By default, `enableParallelBuilding` is enabled as Meson supports parallel building almost everywhere. - -#### Variables controlling Meson {#variables-controlling-meson} - -##### `mesonFlags` {#mesonflags} - -Controls the flags passed to meson. - -##### `mesonBuildType` {#mesonbuildtype} - -Which [`--buildtype`](https://mesonbuild.com/Builtin-options.html#core-options) to pass to Meson. We default to `plain`. - -##### `mesonAutoFeatures` {#mesonautofeatures} - -What value to set [`-Dauto_features=`](https://mesonbuild.com/Builtin-options.html#core-options) to. We default to `enabled`. - -##### `mesonWrapMode` {#mesonwrapmode} - -What value to set [`-Dwrap_mode=`](https://mesonbuild.com/Builtin-options.html#core-options) to. We default to `nodownload` as we disallow network access. - -##### `dontUseMesonConfigure` {#dontusemesonconfigure} - -Disables using Meson’s `configurePhase`. - -### Optional hook ninja {#ninja} - -Overrides the build, install, and check phase to run ninja instead of make. You can disable this behavior with the `dontUseNinjaBuild`, `dontUseNinjaInstall`, and `dontUseNinjaCheck`, respectively. Parallel building is enabled by default in Ninja. - -### Optional hook unzip {#unzip} - -This setup hook will allow you to unzip .zip files specified in `$src`. There are many similar packages like `unrar`, `undmg`, etc. - -### Optional hook wafHook {#wafhook} - -Overrides the configure, build, and install phases. This will run the “waf” script used by many projects. If `wafPath` (default `./waf`) doesn’t exist, it will copy the version of waf available in Nixpkgs. `wafFlags` can be used to pass flags to the waf script. - -### Optional hook scons {#scons} - -Overrides the build, install, and check phases. This uses the scons build system as a replacement for make. scons does not provide a configure phase, so everything is managed at build and install time. - ## Purity in Nixpkgs {#sec-purity-in-nixpkgs} *Measures taken to prevent dependencies on packages outside the store, and what you can do to prevent them.* |