···2021`fetchpatch` works very similarly to `fetchurl` with the same arguments expected. It expects patch files as a source and performs normalization on them before computing the checksum. For example it will remove comments or other unstable parts that are sometimes added by version control systems and can change over time.
2223-24Other fetcher functions allow you to add source code directly from a VCS such as subversion or git. These are mostly straightforward nambes based on the name of the command used with the VCS system. Because they give you a working repository, they act most like `fetchzip`.
2526-## `fetchsvn`
2728Used with Subversion. Expects `url` to a Subversion directory, `rev`, and `sha256`.
2930-## `fetchgit`
3132Used with Git. Expects `url` to a Git repo, `rev`, and `sha256`. `rev` in this case can be full the git commit id (SHA1 hash) or a tag name like `refs/tags/v1.0`.
3334Additionally the following optional arguments can be given: `fetchSubmodules = true` makes `fetchgit` also fetch the submodules of a repository. If `deepClone` is set to true, the entire repository is cloned as opposing to just creating a shallow clone. `deepClone = true` also implies `leaveDotGit = true` which means that the `.git` directory of the clone won't be removed after checkout.
3536-## `fetchfossil`
3738Used with Fossil. Expects `url` to a Fossil archive, `rev`, and `sha256`.
3940-## `fetchcvs`
4142Used with CVS. Expects `cvsRoot`, `tag`, and `sha256`.
4344-## `fetchhg`
4546Used with Mercurial. Expects `url`, `rev`, and `sha256`.
4748A number of fetcher functions wrap part of `fetchurl` and `fetchzip`. They are mainly convenience functions intended for commonly used destinations of source code in Nixpkgs. These wrapper fetchers are listed below.
4950-## `fetchFromGitHub`
5152`fetchFromGitHub` expects four arguments. `owner` is a string corresponding to the GitHub user or organization that controls this repository. `repo` corresponds to the name of the software repository. These are located at the top of every GitHub HTML page as `owner`/`repo`. `rev` corresponds to the Git commit hash or tag (e.g `v1.0`) that will be downloaded from Git. Finally, `sha256` corresponds to the hash of the extracted directory. Again, other hash algorithms are also available but `sha256` is currently preferred.
5354`fetchFromGitHub` uses `fetchzip` to download the source archive generated by GitHub for the specified revision. If `leaveDotGit`, `deepClone` or `fetchSubmodules` are set to `true`, `fetchFromGitHub` will use `fetchgit` instead. Refer to its section for documentation of these options.
5556-## `fetchFromGitLab`
5758This is used with GitLab repositories. The arguments expected are very similar to fetchFromGitHub above.
5960-## `fetchFromGitiles`
6162This is used with Gitiles repositories. The arguments expected are similar to fetchgit.
6364-## `fetchFromBitbucket`
6566This is used with BitBucket repositories. The arguments expected are very similar to fetchFromGitHub above.
6768-## `fetchFromSavannah`
6970This is used with Savannah repositories. The arguments expected are very similar to fetchFromGitHub above.
7172-## `fetchFromRepoOrCz`
7374This is used with repo.or.cz repositories. The arguments expected are very similar to fetchFromGitHub above.
7576-## `fetchFromSourcehut`
7778This is used with sourcehut repositories. The arguments expected are very similar to fetchFromGitHub above. Don't forget the tilde (~) in front of the user name!
···2021`fetchpatch` works very similarly to `fetchurl` with the same arguments expected. It expects patch files as a source and performs normalization on them before computing the checksum. For example it will remove comments or other unstable parts that are sometimes added by version control systems and can change over time.
22023Other fetcher functions allow you to add source code directly from a VCS such as subversion or git. These are mostly straightforward nambes based on the name of the command used with the VCS system. Because they give you a working repository, they act most like `fetchzip`.
2425+## `fetchsvn` {#fetchsvn}
2627Used with Subversion. Expects `url` to a Subversion directory, `rev`, and `sha256`.
2829+## `fetchgit` {#fetchgit}
3031Used with Git. Expects `url` to a Git repo, `rev`, and `sha256`. `rev` in this case can be full the git commit id (SHA1 hash) or a tag name like `refs/tags/v1.0`.
3233Additionally the following optional arguments can be given: `fetchSubmodules = true` makes `fetchgit` also fetch the submodules of a repository. If `deepClone` is set to true, the entire repository is cloned as opposing to just creating a shallow clone. `deepClone = true` also implies `leaveDotGit = true` which means that the `.git` directory of the clone won't be removed after checkout.
3435+## `fetchfossil` {#fetchfossil}
3637Used with Fossil. Expects `url` to a Fossil archive, `rev`, and `sha256`.
3839+## `fetchcvs` {#fetchcvs}
4041Used with CVS. Expects `cvsRoot`, `tag`, and `sha256`.
4243+## `fetchhg` {#fetchhg}
4445Used with Mercurial. Expects `url`, `rev`, and `sha256`.
4647A number of fetcher functions wrap part of `fetchurl` and `fetchzip`. They are mainly convenience functions intended for commonly used destinations of source code in Nixpkgs. These wrapper fetchers are listed below.
4849+## `fetchFromGitHub` {#fetchfromgithub}
5051`fetchFromGitHub` expects four arguments. `owner` is a string corresponding to the GitHub user or organization that controls this repository. `repo` corresponds to the name of the software repository. These are located at the top of every GitHub HTML page as `owner`/`repo`. `rev` corresponds to the Git commit hash or tag (e.g `v1.0`) that will be downloaded from Git. Finally, `sha256` corresponds to the hash of the extracted directory. Again, other hash algorithms are also available but `sha256` is currently preferred.
5253`fetchFromGitHub` uses `fetchzip` to download the source archive generated by GitHub for the specified revision. If `leaveDotGit`, `deepClone` or `fetchSubmodules` are set to `true`, `fetchFromGitHub` will use `fetchgit` instead. Refer to its section for documentation of these options.
5455+## `fetchFromGitLab` {#fetchfromgitlab}
5657This is used with GitLab repositories. The arguments expected are very similar to fetchFromGitHub above.
5859+## `fetchFromGitiles` {#fetchfromgitiles}
6061This is used with Gitiles repositories. The arguments expected are similar to fetchgit.
6263+## `fetchFromBitbucket` {#fetchfrombitbucket}
6465This is used with BitBucket repositories. The arguments expected are very similar to fetchFromGitHub above.
6667+## `fetchFromSavannah` {#fetchfromsavannah}
6869This is used with Savannah repositories. The arguments expected are very similar to fetchFromGitHub above.
7071+## `fetchFromRepoOrCz` {#fetchfromrepoorcz}
7273This is used with repo.or.cz repositories. The arguments expected are very similar to fetchFromGitHub above.
7475+## `fetchFromSourcehut` {#fetchfromsourcehut}
7677This is used with sourcehut repositories. The arguments expected are very similar to fetchFromGitHub above. Don't forget the tilde (~) in front of the user name!
+1-1
doc/builders/images/appimagetools.section.md
···23`pkgs.appimageTools` is a set of functions for extracting and wrapping [AppImage](https://appimage.org/) files. They are meant to be used if traditional packaging from source is infeasible, or it would take too long. To quickly run an AppImage file, `pkgs.appimage-run` can be used as well.
45-::: warning
6The `appimageTools` API is unstable and may be subject to backwards-incompatible changes in the future.
7:::
8
···23`pkgs.appimageTools` is a set of functions for extracting and wrapping [AppImage](https://appimage.org/) files. They are meant to be used if traditional packaging from source is infeasible, or it would take too long. To quickly run an AppImage file, `pkgs.appimage-run` can be used as well.
45+::: {.warning}
6The `appimageTools` API is unstable and may be subject to backwards-incompatible changes in the future.
7:::
8
+2-2
doc/builders/images/dockertools.section.md
···1# pkgs.dockerTools {#sec-pkgs-dockerTools}
23-`pkgs.dockerTools` is a set of functions for creating and manipulating Docker images according to the [ Docker Image Specification v1.2.0 ](https://github.com/moby/moby/blob/master/image/spec/v1.2.md#docker-image-specification-v120). Docker itself is not used to perform any of the operations done by these functions.
45## buildImage {#ssec-pkgs-dockerTools-buildImage}
6···5253> **_NOTE:_** Using this parameter requires the `kvm` device to be available.
5455-- `config` is used to specify the configuration of the containers that will be started off the built image in Docker. The available options are listed in the [ Docker Image Specification v1.2.0 ](https://github.com/moby/moby/blob/master/image/spec/v1.2.md#image-json-field-descriptions).
5657After the new layer has been created, its closure (to which `contents`, `config` and `runAsRoot` contribute) will be copied in the layer itself. Only new dependencies that are not already in the existing layers will be copied.
58
···1# pkgs.dockerTools {#sec-pkgs-dockerTools}
23+`pkgs.dockerTools` is a set of functions for creating and manipulating Docker images according to the [Docker Image Specification v1.2.0](https://github.com/moby/moby/blob/master/image/spec/v1.2.md#docker-image-specification-v120). Docker itself is not used to perform any of the operations done by these functions.
45## buildImage {#ssec-pkgs-dockerTools-buildImage}
6···5253> **_NOTE:_** Using this parameter requires the `kvm` device to be available.
5455+- `config` is used to specify the configuration of the containers that will be started off the built image in Docker. The available options are listed in the [Docker Image Specification v1.2.0](https://github.com/moby/moby/blob/master/image/spec/v1.2.md#image-json-field-descriptions).
5657After the new layer has been created, its closure (to which `contents`, `config` and `runAsRoot` contribute) will be copied in the layer itself. Only new dependencies that are not already in the existing layers will be copied.
58
+2-2
doc/builders/images/snaptools.section.md
···1415The following expression packages GNU Hello as a Snapcraft snap.
1617-```{#ex-snapTools-buildSnap-hello .nix}
18let
19 inherit (import <nixpkgs> { }) snapTools hello;
20in snapTools.makeSnap {
···3536Graphical programs require many more integrations with the host. This example uses Firefox as an example, because it is one of the most complicated programs we could package.
3738-```{#ex-snapTools-buildSnap-firefox .nix}
39let
40 inherit (import <nixpkgs> { }) snapTools firefox;
41in snapTools.makeSnap {
···1415The following expression packages GNU Hello as a Snapcraft snap.
1617+``` {#ex-snapTools-buildSnap-hello .nix}
18let
19 inherit (import <nixpkgs> { }) snapTools hello;
20in snapTools.makeSnap {
···3536Graphical programs require many more integrations with the host. This example uses Firefox as an example, because it is one of the most complicated programs we could package.
3738+``` {#ex-snapTools-buildSnap-firefox .nix}
39let
40 inherit (import <nixpkgs> { }) snapTools firefox;
41in snapTools.makeSnap {
+3-3
doc/builders/packages/cataclysm-dda.section.md
···1# Cataclysm: Dark Days Ahead {#cataclysm-dark-days-ahead}
23-## How to install Cataclysm DDA
45To install the latest stable release of Cataclysm DDA to your profile, execute
6`nix-env -f "<nixpkgs>" -iA cataclysm-dda`. For the curses build (build
···34}
35```
3637-## Important note for overriding packages
3839After applying `overrideAttrs`, you need to fix `passthru.pkgs` and
40`passthru.withMods` attributes either manually or by using `attachPkgs`:
···69goodExample2.withMods (_: []) # parallel building enabled
70```
7172-## Customizing with mods
7374To install Cataclysm DDA with mods of your choice, you can use `withMods`
75attribute:
···1# Cataclysm: Dark Days Ahead {#cataclysm-dark-days-ahead}
23+## How to install Cataclysm DDA {#how-to-install-cataclysm-dda}
45To install the latest stable release of Cataclysm DDA to your profile, execute
6`nix-env -f "<nixpkgs>" -iA cataclysm-dda`. For the curses build (build
···34}
35```
3637+## Important note for overriding packages {#important-note-for-overriding-packages}
3839After applying `overrideAttrs`, you need to fix `passthru.pkgs` and
40`passthru.withMods` attributes either manually or by using `attachPkgs`:
···69goodExample2.withMods (_: []) # parallel building enabled
70```
7172+## Customizing with mods {#customizing-with-mods}
7374To install Cataclysm DDA with mods of your choice, you can use `withMods`
75attribute:
+1-1
doc/builders/packages/elm.section.md
···6nix-shell -p elmPackages.elm elmPackages.elm-format
7```
89-To update the Elm compiler, see <filename>nixpkgs/pkgs/development/compilers/elm/README.md</filename>.
1011To package Elm applications, [read about elm2nix](https://github.com/hercules-ci/elm2nix#elm2nix).
···6nix-shell -p elmPackages.elm elmPackages.elm-format
7```
89+To update the Elm compiler, see `nixpkgs/pkgs/development/compilers/elm/README.md`.
1011To package Elm applications, [read about elm2nix](https://github.com/hercules-ci/elm2nix#elm2nix).
+1-1
doc/builders/packages/firefox.section.md
···1# Firefox {#sec-firefox}
23-## Build wrapped Firefox with extensions and policies
45The `wrapFirefox` function allows to pass policies, preferences and extension that are available to firefox. With the help of `fetchFirefoxAddon` this allows build a firefox version that already comes with addons pre-installed:
6
···1# Firefox {#sec-firefox}
23+## Build wrapped Firefox with extensions and policies {#build-wrapped-firefox-with-extensions-and-policies}
45The `wrapFirefox` function allows to pass policies, preferences and extension that are available to firefox. With the help of `fetchFirefoxAddon` this allows build a firefox version that already comes with addons pre-installed:
6
+2-2
doc/builders/packages/opengl.section.md
···45Broadly, we support both GL vendors: Mesa and NVIDIA.
67-## NixOS Desktop
89The NixOS desktop or other non-headless configurations are the primary target for OpenGL libraries and applications. The current solution for discovering which drivers are available is based on [libglvnd](https://gitlab.freedesktop.org/glvnd/libglvnd). `libglvnd` performs "vendor-neutral dispatch", trying a variety of techniques to find the system's GL implementation. In practice, this will be either via standard GLX for X11 users or EGL for Wayland users, and supporting either NVIDIA or Mesa extensions.
1011-## Nix on GNU/Linux
1213If you are using a non-NixOS GNU/Linux/X11 desktop with free software video drivers, consider launching OpenGL-dependent programs from Nixpkgs with Nixpkgs versions of `libglvnd` and `mesa.drivers` in `LD_LIBRARY_PATH`. For Mesa drivers, the Linux kernel version doesn't have to match nixpkgs.
14
···45Broadly, we support both GL vendors: Mesa and NVIDIA.
67+## NixOS Desktop {#nixos-desktop}
89The NixOS desktop or other non-headless configurations are the primary target for OpenGL libraries and applications. The current solution for discovering which drivers are available is based on [libglvnd](https://gitlab.freedesktop.org/glvnd/libglvnd). `libglvnd` performs "vendor-neutral dispatch", trying a variety of techniques to find the system's GL implementation. In practice, this will be either via standard GLX for X11 users or EGL for Wayland users, and supporting either NVIDIA or Mesa extensions.
1011+## Nix on GNU/Linux {#nix-on-gnulinux}
1213If you are using a non-NixOS GNU/Linux/X11 desktop with free software video drivers, consider launching OpenGL-dependent programs from Nixpkgs with Nixpkgs versions of `libglvnd` and `mesa.drivers` in `LD_LIBRARY_PATH`. For Mesa drivers, the Linux kernel version doesn't have to match nixpkgs.
14
+13-10
doc/builders/packages/steam.section.md
···20## Troubleshooting {#sec-steam-troub}
2122- **Steam fails to start. What do I do?**
023 Try to run
2425 ```ShellSession
···3233 - The `newStdcpp` parameter was removed since NixOS 17.09 and should not be needed anymore.
34 - Steam ships statically linked with a version of libcrypto that conflics with the one dynamically loaded by radeonsi_dri.so. If you get the error
035 ```
36 steam.sh: line 713: 7842 Segmentation fault (core dumped)
37 ```
038 have a look at [this pull request](https://github.com/NixOS/nixpkgs/pull/20269).
3940- **Java**
4142 1. There is no java in steam chrootenv by default. If you get a message like
4344- ```
45- /home/foo/.local/share/Steam/SteamApps/common/towns/towns.sh: line 1: java: command not found
46- ```
4748- You need to add
4950- ```nix
51- steam.override { withJava = true; };
52- ```
5354## steam-run {#sec-steam-run}
55···5758```nix
59pkgs.steam.override ({
60- nativeOnly = true;
61- newStdcpp = true;
62- }).run
63```
6465to your configuration, rebuild, and run the game with
···20## Troubleshooting {#sec-steam-troub}
2122- **Steam fails to start. What do I do?**
23+24 Try to run
2526 ```ShellSession
···3334 - The `newStdcpp` parameter was removed since NixOS 17.09 and should not be needed anymore.
35 - Steam ships statically linked with a version of libcrypto that conflics with the one dynamically loaded by radeonsi_dri.so. If you get the error
36+37 ```
38 steam.sh: line 713: 7842 Segmentation fault (core dumped)
39 ```
40+41 have a look at [this pull request](https://github.com/NixOS/nixpkgs/pull/20269).
4243- **Java**
4445 1. There is no java in steam chrootenv by default. If you get a message like
4647+ ```
48+ /home/foo/.local/share/Steam/SteamApps/common/towns/towns.sh: line 1: java: command not found
49+ ```
5051+ you need to add
5253+ ```nix
54+ steam.override { withJava = true; };
55+ ```
5657## steam-run {#sec-steam-run}
58···6061```nix
62pkgs.steam.override ({
63+ nativeOnly = true;
64+ newStdcpp = true;
65+}).run
66```
6768to your configuration, rebuild, and run the game with
+4-4
doc/builders/packages/xorg.section.md
···23The Nix expressions for the X.org packages reside in `pkgs/servers/x11/xorg/default.nix`. This file is automatically generated from lists of tarballs in an X.org release. As such it should not be modified directly; rather, you should modify the lists, the generator script or the file `pkgs/servers/x11/xorg/overrides.nix`, in which you can override or add to the derivations produced by the generator.
45-## Katamari Tarballs
67X.org upstream releases used to include [katamari](https://en.wiktionary.org/wiki/%E3%81%8B%E3%81%9F%E3%81%BE%E3%82%8A) releases, which included a holistic recommended version for each tarball, up until 7.7. To create a list of tarballs in a katamari release:
8···14 | sort > "tarballs-$release.list"
15```
1617-## Individual Tarballs
1819The upstream release process for [X11R7.8](https://x.org/wiki/Releases/7.8/) does not include a planned katamari. Instead, each component of X.org is released as its own tarball. We maintain `pkgs/servers/x11/xorg/tarballs.list` as a list of tarballs for each individual package. This list includes X.org core libraries and protocol descriptions, extra newer X11 interface libraries, like `xorg.libxcb`, and classic utilities which are largely unused but still available if needed, like `xorg.imake`.
2021-## Generating Nix Expressions
2223The generator is invoked as follows:
24···2930For each of the tarballs in the `.list` files, the script downloads it, unpacks it, and searches its `configure.ac` and `*.pc.in` files for dependencies. This information is used to generate `default.nix`. The generator caches downloaded tarballs between runs. Pay close attention to the `NOT FOUND: $NAME` messages at the end of the run, since they may indicate missing dependencies. (Some might be optional dependencies, however.)
3132-## Overriding the Generator
3334If the expression for a package requires derivation attributes that the generator cannot figure out automatically (say, `patches` or a `postInstall` hook), you should modify `pkgs/servers/x11/xorg/overrides.nix`.
···23The Nix expressions for the X.org packages reside in `pkgs/servers/x11/xorg/default.nix`. This file is automatically generated from lists of tarballs in an X.org release. As such it should not be modified directly; rather, you should modify the lists, the generator script or the file `pkgs/servers/x11/xorg/overrides.nix`, in which you can override or add to the derivations produced by the generator.
45+## Katamari Tarballs {#katamari-tarballs}
67X.org upstream releases used to include [katamari](https://en.wiktionary.org/wiki/%E3%81%8B%E3%81%9F%E3%81%BE%E3%82%8A) releases, which included a holistic recommended version for each tarball, up until 7.7. To create a list of tarballs in a katamari release:
8···14 | sort > "tarballs-$release.list"
15```
1617+## Individual Tarballs {#individual-tarballs}
1819The upstream release process for [X11R7.8](https://x.org/wiki/Releases/7.8/) does not include a planned katamari. Instead, each component of X.org is released as its own tarball. We maintain `pkgs/servers/x11/xorg/tarballs.list` as a list of tarballs for each individual package. This list includes X.org core libraries and protocol descriptions, extra newer X11 interface libraries, like `xorg.libxcb`, and classic utilities which are largely unused but still available if needed, like `xorg.imake`.
2021+## Generating Nix Expressions {#generating-nix-expressions}
2223The generator is invoked as follows:
24···2930For each of the tarballs in the `.list` files, the script downloads it, unpacks it, and searches its `configure.ac` and `*.pc.in` files for dependencies. This information is used to generate `default.nix`. The generator caches downloaded tarballs between runs. Pay close attention to the `NOT FOUND: $NAME` messages at the end of the run, since they may indicate missing dependencies. (Some might be optional dependencies, however.)
3132+## Overriding the Generator {#overriding-the-generator}
3334If the expression for a package requires derivation attributes that the generator cannot figure out automatically (say, `patches` or a `postInstall` hook), you should modify `pkgs/servers/x11/xorg/overrides.nix`.
+1-1
doc/builders/trivial-builders.chapter.md
···3738Variant of `runCommand` that forces the derivation to be built locally, it is not substituted. This is intended for very cheap commands (<1s execution time). It saves on the network roundrip and can speed up a build.
3940-::: note
41This sets [`allowSubstitutes` to `false`](https://nixos.org/nix/manual/#adv-attr-allowSubstitutes), so only use `runCommandLocal` if you are certain the user will always have a builder for the `system` of the derivation. This should be true for most trivial use cases (e.g. just copying some files to a different location or adding symlinks), because there the `system` is usually the same as `builtins.currentSystem`.
42:::
43
···3738Variant of `runCommand` that forces the derivation to be built locally, it is not substituted. This is intended for very cheap commands (<1s execution time). It saves on the network roundrip and can speed up a build.
3940+::: {.note}
41This sets [`allowSubstitutes` to `false`](https://nixos.org/nix/manual/#adv-attr-allowSubstitutes), so only use `runCommandLocal` if you are certain the user will always have a builder for the `system` of the derivation. This should be true for most trivial use cases (e.g. just copying some files to a different location or adding symlinks), because there the `system` is usually the same as `builtins.currentSystem`.
42:::
43
+4-4
doc/contributing/coding-conventions.chapter.md
···67- Do not use tab characters, i.e. configure your editor to use soft tabs. For instance, use `(setq-default indent-tabs-mode nil)` in Emacs. Everybody has different tab settings so it’s asking for trouble.
89-- Use `lowerCamelCase` for variable names, not `UpperCamelCase`. Note, this rule does not apply to package attribute names, which instead follow the rules in <xref linkend="sec-package-naming"/>.
1011- Function calls with attribute set arguments are written as
12···209210- Dashes in the package name _should_ be preserved in new variable names, rather than converted to underscores or camel cased — e.g., `http-parser` instead of `http_parser` or `httpParser`. The hyphenated style is preferred in all three package names.
211212-- If there are multiple versions of a package, this _should_ be reflected in the variable names in `all-packages.nix`, e.g. `json-c-0-9` and `json-c-0-11`. If there is an obvious “default” version, make an attribute like `json-c = json-c-0-9;`. See also <xref linkend="sec-versioning" />
213214## File naming and organisation {#sec-organisation}
215···462463 For package updates it is enough to change one symbol to make hash fake. For new packages, you can use `lib.fakeSha256`, `lib.fakeSha512` or any other fake hash.
464465- This is last resort method when reconstructing source URL is non-trivial and `nix-prefetch-url -A` isn't applicable (for example, [one of `kodi` dependencies](https://github.com/NixOS/nixpkgs/blob/d2ab091dd308b99e4912b805a5eb088dd536adb9/pkgs/applications/video/kodi/default.nix#L73")). The easiest way then would be replace hash with a fake one and rebuild. Nix build will fail and error message will contain desired hash.
466467-::: warning
468This method has security problems. Check below for details.
469:::
470
···67- Do not use tab characters, i.e. configure your editor to use soft tabs. For instance, use `(setq-default indent-tabs-mode nil)` in Emacs. Everybody has different tab settings so it’s asking for trouble.
89+- Use `lowerCamelCase` for variable names, not `UpperCamelCase`. Note, this rule does not apply to package attribute names, which instead follow the rules in [](#sec-package-naming).
1011- Function calls with attribute set arguments are written as
12···209210- Dashes in the package name _should_ be preserved in new variable names, rather than converted to underscores or camel cased — e.g., `http-parser` instead of `http_parser` or `httpParser`. The hyphenated style is preferred in all three package names.
211212+- If there are multiple versions of a package, this _should_ be reflected in the variable names in `all-packages.nix`, e.g. `json-c-0-9` and `json-c-0-11`. If there is an obvious “default” version, make an attribute like `json-c = json-c-0-9;`. See also [](#sec-versioning)
213214## File naming and organisation {#sec-organisation}
215···462463 For package updates it is enough to change one symbol to make hash fake. For new packages, you can use `lib.fakeSha256`, `lib.fakeSha512` or any other fake hash.
464465+ This is last resort method when reconstructing source URL is non-trivial and `nix-prefetch-url -A` isn’t applicable (for example, [one of `kodi` dependencies](https://github.com/NixOS/nixpkgs/blob/d2ab091dd308b99e4912b805a5eb088dd536adb9/pkgs/applications/video/kodi/default.nix#L73)). The easiest way then would be replace hash with a fake one and rebuild. Nix build will fail and error message will contain desired hash.
466467+::: {.warning}
468This method has security problems. Check below for details.
469:::
470
···1# Contributing to this documentation {#chap-contributing}
23-The DocBook sources of the Nixpkgs manual are in the [doc](https://github.com/NixOS/nixpkgs/tree/master/doc) subdirectory of the Nixpkgs repository.
45You can quickly check your edits with `make`:
6···22```
2324If the build succeeds, the manual will be in `./result/share/doc/nixpkgs/manual.html`.
000000000000000000000000000000000000000000000000000000000000000000000000000
···1# Contributing to this documentation {#chap-contributing}
23+The sources of the Nixpkgs manual are in the [doc](https://github.com/NixOS/nixpkgs/tree/master/doc) subdirectory of the Nixpkgs repository. The manual is still partially written in DocBook but it is progressively being converted to [Markdown](#sec-contributing-markup).
45You can quickly check your edits with `make`:
6···22```
2324If the build succeeds, the manual will be in `./result/share/doc/nixpkgs/manual.html`.
25+26+## Syntax {#sec-contributing-markup}
27+28+As per [RFC 0072](https://github.com/NixOS/rfcs/pull/72), all new documentation content should be written in [CommonMark](https://commonmark.org/) Markdown dialect.
29+30+Additionally, the following syntax extensions are currently used:
31+32+- []{#ssec-contributing-markup-anchors}
33+ Explicitly defined **anchors** on headings, to allow linking to sections. These should be always used, to ensure the anchors can be linked even when the heading text changes, and to prevent conflicts between [automatically assigned identifiers](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/auto_identifiers.md).
34+35+ It uses the widely compatible [header attributes](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/attributes.md) syntax:
36+37+ ```markdown
38+ ## Syntax {#sec-contributing-markup}
39+ ```
40+41+- []{#ssec-contributing-markup-anchors-inline}
42+ **Inline anchors**, which allow linking arbitrary place in the text (e.g. individual list items, sentences…).
43+44+ They are defined using a hybrid of the link syntax with the attributes syntax known from headings, called [bracketed spans](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/bracketed_spans.md):
45+46+ ```markdown
47+ - []{#ssec-gnome-hooks-glib} `glib` setup hook will populate `GSETTINGS_SCHEMAS_PATH` and then `wrapGAppsHook` will prepend it to `XDG_DATA_DIRS`.
48+ ```
49+50+- []{#ssec-contributing-markup-automatic-links}
51+ If you **omit a link text** for a link pointing to a section, the text will be substituted automatically. For example, `[](#chap-contributing)` will result in [](#chap-contributing).
52+53+ This syntax is taken from [MyST](https://myst-parser.readthedocs.io/en/latest/using/syntax.html#targets-and-cross-referencing).
54+55+- []{#ssec-contributing-markup-admonitions}
56+ **Admonitions**, set off from the text to bring attention to something.
57+58+ It uses pandoc’s [fenced `div`s syntax](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/fenced_divs.md):
59+60+ ```markdown
61+ ::: {.warning}
62+ This is a warning
63+ :::
64+ ```
65+66+ which renders as
67+68+ > ::: {.warning}
69+ > This is a warning.
70+ > :::
71+72+ The following are supported:
73+74+ - [`caution`](https://tdg.docbook.org/tdg/5.0/caution.html)
75+ - [`important`](https://tdg.docbook.org/tdg/5.0/important.html)
76+ - [`note`](https://tdg.docbook.org/tdg/5.0/note.html)
77+ - [`tip`](https://tdg.docbook.org/tdg/5.0/tip.html)
78+ - [`warning`](https://tdg.docbook.org/tdg/5.0/warning.html)
79+80+- []{#ssec-contributing-markup-definition-lists}
81+ [**Definition lists**](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/definition_lists.md), for defining a group of terms:
82+83+ ```markdown
84+ pear
85+ : green or yellow bulbous fruit
86+87+ watermelon
88+ : green fruit with red flesh
89+ ```
90+91+ which renders as
92+93+ > pear
94+ > : green or yellow bulbous fruit
95+ >
96+ > watermelon
97+ > : green fruit with red flesh
98+99+For contributing to the legacy parts, please see [DocBook: The Definitive Guide](https://tdg.docbook.org/) or the [DocBook rocks! primer](https://web.archive.org/web/20200816233747/https://docbook.rocks/).
+1-1
doc/contributing/quick-start.chapter.md
···9 $ cd nixpkgs
10 ```
1112-2. Find a good place in the Nixpkgs tree to add the Nix expression for your package. For instance, a library package typically goes into `pkgs/development/libraries/pkgname`, while a web browser goes into `pkgs/applications/networking/browsers/pkgname`. See <xref linkend="sec-organisation" /> for some hints on the tree organisation. Create a directory for your package, e.g.
1314 ```ShellSession
15 $ mkdir pkgs/development/libraries/libfoo
···9 $ cd nixpkgs
10 ```
1112+2. Find a good place in the Nixpkgs tree to add the Nix expression for your package. For instance, a library package typically goes into `pkgs/development/libraries/pkgname`, while a web browser goes into `pkgs/applications/networking/browsers/pkgname`. See [](#sec-organisation) for some hints on the tree organisation. Create a directory for your package, e.g.
1314 ```ShellSession
15 $ mkdir pkgs/development/libraries/libfoo
···1# Reviewing contributions {#chap-reviewing-contributions}
23-::: warning
4The following section is a draft, and the policy for reviewing is still being discussed in issues such as [#11166](https://github.com/NixOS/nixpkgs/issues/11166) and [#20836](https://github.com/NixOS/nixpkgs/issues/20836).
5:::
6···35- Building the package locally.
36 - pull requests are often targeted to the master or staging branch, and building the pull request locally when it is submitted can trigger many source builds.
37 - It is possible to rebase the changes on nixos-unstable or nixpkgs-unstable for easier review by running the following commands from a nixpkgs clone.
038 ```ShellSession
39 $ git fetch origin nixos-unstable
40 $ git fetch origin pull/PRNUMBER/head
41 $ git rebase --onto nixos-unstable BASEBRANCH FETCH_HEAD
42 ```
043 - The first command fetches the nixos-unstable branch.
44 - The second command fetches the pull request changes, `PRNUMBER` is the number at the end of the pull request title and `BASEBRANCH` the base branch of the pull request.
45 - The third command rebases the pull request changes to the nixos-unstable branch.
46 - The [nixpkgs-review](https://github.com/Mic92/nixpkgs-review) tool can be used to review a pull request content in a single command. `PRNUMBER` should be replaced by the number at the end of the pull request title. You can also provide the full github pull request url.
047 ```ShellSession
48 $ nix-shell -p nixpkgs-review --run "nixpkgs-review pr PRNUMBER"
49 ```
···1# Reviewing contributions {#chap-reviewing-contributions}
23+::: {.warning}
4The following section is a draft, and the policy for reviewing is still being discussed in issues such as [#11166](https://github.com/NixOS/nixpkgs/issues/11166) and [#20836](https://github.com/NixOS/nixpkgs/issues/20836).
5:::
6···35- Building the package locally.
36 - pull requests are often targeted to the master or staging branch, and building the pull request locally when it is submitted can trigger many source builds.
37 - It is possible to rebase the changes on nixos-unstable or nixpkgs-unstable for easier review by running the following commands from a nixpkgs clone.
38+39 ```ShellSession
40 $ git fetch origin nixos-unstable
41 $ git fetch origin pull/PRNUMBER/head
42 $ git rebase --onto nixos-unstable BASEBRANCH FETCH_HEAD
43 ```
44+45 - The first command fetches the nixos-unstable branch.
46 - The second command fetches the pull request changes, `PRNUMBER` is the number at the end of the pull request title and `BASEBRANCH` the base branch of the pull request.
47 - The third command rebases the pull request changes to the nixos-unstable branch.
48 - The [nixpkgs-review](https://github.com/Mic92/nixpkgs-review) tool can be used to review a pull request content in a single command. `PRNUMBER` should be replaced by the number at the end of the pull request title. You can also provide the full github pull request url.
49+50 ```ShellSession
51 $ nix-shell -p nixpkgs-review --run "nixpkgs-review pr PRNUMBER"
52 ```
+3-1
doc/contributing/submitting-changes.chapter.md
···71- If a new version fixing the vulnerability has been released, update the package;
72- If the security fix comes in the form of a patch and a CVE is available, then add the patch to the Nixpkgs tree, and apply it to the package.
73 The name of the patch should be the CVE identifier, so e.g. `CVE-2019-13636.patch`; If a patch is fetched the name needs to be set as well, e.g.:
074 ```nix
75 (fetchpatch {
76 name = "CVE-2019-11068.patch";
···8990Before removing a package, one should try to find a new maintainer or fix smaller issues first.
9192-### Steps to remove a package from Nixpkgs
9394We use jbidwatcher as an example for a discontinued project here.
95···1001. Add an alias for the package name in `pkgs/top-level/aliases.nix` (There is also `pkgs/misc/vim-plugins/aliases.nix`. Package sets typically do not have aliases, so we can't add them there.)
101102 For example in this case:
0103 ```
104 jbidwatcher = throw "jbidwatcher was discontinued in march 2021"; # added 2021-03-15
105 ```
···71- If a new version fixing the vulnerability has been released, update the package;
72- If the security fix comes in the form of a patch and a CVE is available, then add the patch to the Nixpkgs tree, and apply it to the package.
73 The name of the patch should be the CVE identifier, so e.g. `CVE-2019-13636.patch`; If a patch is fetched the name needs to be set as well, e.g.:
74+75 ```nix
76 (fetchpatch {
77 name = "CVE-2019-11068.patch";
···9091Before removing a package, one should try to find a new maintainer or fix smaller issues first.
9293+### Steps to remove a package from Nixpkgs {#steps-to-remove-a-package-from-nixpkgs}
9495We use jbidwatcher as an example for a discontinued project here.
96···1011. Add an alias for the package name in `pkgs/top-level/aliases.nix` (There is also `pkgs/misc/vim-plugins/aliases.nix`. Package sets typically do not have aliases, so we can't add them there.)
102103 For example in this case:
104+105 ```
106 jbidwatcher = throw "jbidwatcher was discontinued in march 2021"; # added 2021-03-15
107 ```
+2-2
doc/functions/library/attrsets.xml
···166 <xi:include href="./locations.xml" xpointer="lib.attrsets.getAttrFromPath" />
167168 <para>
169- Like <xref linkend="function-library-lib.attrsets.attrByPath" /> except without a default, and it will throw if the value doesn't exist.
170 </para>
171172 <variablelist>
···1480 <xi:include href="./locations.xml" xpointer="lib.attrsets.zipAttrs" />
14811482 <para>
1483- Merge sets of attributes and combine each attribute value in to a list. Similar to <xref linkend="function-library-lib.attrsets.zipAttrsWith" /> where the merge function returns a list of all values.
1484 </para>
14851486 <variablelist>
···166 <xi:include href="./locations.xml" xpointer="lib.attrsets.getAttrFromPath" />
167168 <para>
169+ Like [](#function-library-lib.attrsets.attrByPath) except without a default, and it will throw if the value doesn't exist.
170 </para>
171172 <variablelist>
···1480 <xi:include href="./locations.xml" xpointer="lib.attrsets.zipAttrs" />
14811482 <para>
1483+ Merge sets of attributes and combine each attribute value in to a list. Similar to [](#function-library-lib.attrsets.zipAttrsWith) where the merge function returns a list of all values.
1484 </para>
14851486 <variablelist>
+24
doc/labelless-link-is-xref.lua
···000000000000000000000000
···1+local function starts_with(start, str)
2+ return str:sub(1, #start) == start
3+end
4+5+local function escape_xml_arg(arg)
6+ amps = arg:gsub('&', '&')
7+ amps_quotes = amps:gsub('"', '"')
8+ amps_quotes_lt = amps_quotes:gsub('<', '<')
9+10+ return amps_quotes_lt
11+end
12+13+function Link(elem)
14+ has_no_content = #elem.content == 0
15+ targets_anchor = starts_with('#', elem.target)
16+ has_no_attributes = elem.title == '' and elem.identifier == '' and #elem.classes == 0 and #elem.attributes == 0
17+18+ if has_no_content and targets_anchor and has_no_attributes then
19+ -- xref expects idref without the pound-sign
20+ target_without_hash = elem.target:sub(2, #elem.target)
21+22+ return pandoc.RawInline('docbook', '<xref linkend="' .. escape_xml_arg(target_without_hash) .. '" />')
23+ end
24+end
+21-14
doc/languages-frameworks/agda.section.md
···1# Agda {#agda}
23-## How to use Agda
45Agda is available as the [agda](https://search.nixos.org/packages?channel=unstable&show=agda&from=0&size=30&sort=relevance&query=agda)
6package.
···43```
4445You can also reference a GitHub repository
046```nix
47agda.withPackages (p: [
48 (p.standard-library.overrideAttrs (oldAttrs: {
···5960If you want to use a library not added to Nixpkgs, you can add a
61dependency to a local library by calling `agdaPackages.mkDerivation`.
062```nix
63agda.withPackages (p: [
64 (p.mkDerivation {
···92Agda will not by default use these libraries. To tell Agda to use a library we have some options:
9394* Call `agda` with the library flag:
95-```ShellSession
96-$ agda -l standard-library -i . MyFile.agda
97-```
98* Write a `my-library.agda-lib` file for the project you are working on which may look like:
99-```
100-name: my-library
101-include: .
102-depend: standard-library
103-```
104* Create the file `~/.agda/defaults` and add any libraries you want to use by default.
105106More information can be found in the [official Agda documentation on library management](https://agda.readthedocs.io/en/v2.6.1/tools/package-system.html).
107108-## Compiling Agda
0109Agda modules can be compiled using the GHC backend with the `--compile` flag. A version of `ghc` with `ieee754` is made available to the Agda program via the `--with-compiler` flag.
110This can be overridden by a different version of `ghc` as follows:
111···116}
117```
118119-## Writing Agda packages
0120To write a nix derivation for an Agda library, first check that the library has a `*.agda-lib` file.
121122A derivation can then be written using `agdaPackages.mkDerivation`. This has similar arguments to `stdenv.mkDerivation` with the following additions:
···140}
141```
142143-### Building Agda packages
0144The default build phase for `agdaPackages.mkDerivation` simply runs `agda` on the `Everything.agda` file.
145If something else is needed to build the package (e.g. `make`) then the `buildPhase` should be overridden.
146Additionally, a `preBuild` or `configurePhase` can be used if there are steps that need to be done prior to checking the `Everything.agda` file.
147`agda` and the Agda libraries contained in `buildInputs` are made available during the build phase.
148149-### Installing Agda packages
0150The default install phase copies Agda source files, Agda interface files (`*.agdai`) and `*.agda-lib` files to the output directory.
151This can be overridden.
152153By default, Agda sources are files ending on `.agda`, or literate Agda files ending on `.lagda`, `.lagda.tex`, `.lagda.org`, `.lagda.md`, `.lagda.rst`. The list of recognised Agda source extensions can be extended by setting the `extraExtensions` config variable.
154155-## Adding Agda packages to Nixpkgs
156157To add an Agda package to `nixpkgs`, the derivation should be written to `pkgs/development/libraries/agda/${library-name}/` and an entry should be added to `pkgs/top-level/agda-packages.nix`. Here it is called in a scope with access to all other Agda libraries, so the top line of the `default.nix` can look like:
158···182 '';
183}
184```
0185This library has a file called `.agda-lib`, and so we give an empty string to `libraryFile` as nothing precedes `.agda-lib` in the filename. This file contains `name: IAL-1.3`, and so we let `libraryName = "IAL-1.3"`. This library does not use an `Everything.agda` file and instead has a Makefile, so there is no need to set `everythingFile` and we set a custom `buildPhase`.
186187When writing an Agda package it is essential to make sure that no `.agda-lib` file gets added to the store as a single file (for example by using `writeText`). This causes Agda to think that the nix store is a Agda library and it will attempt to write to it whenever it typechecks something. See [https://github.com/agda/agda/issues/4613](https://github.com/agda/agda/issues/4613).
···1# Agda {#agda}
23+## How to use Agda {#how-to-use-agda}
45Agda is available as the [agda](https://search.nixos.org/packages?channel=unstable&show=agda&from=0&size=30&sort=relevance&query=agda)
6package.
···43```
4445You can also reference a GitHub repository
46+47```nix
48agda.withPackages (p: [
49 (p.standard-library.overrideAttrs (oldAttrs: {
···6061If you want to use a library not added to Nixpkgs, you can add a
62dependency to a local library by calling `agdaPackages.mkDerivation`.
63+64```nix
65agda.withPackages (p: [
66 (p.mkDerivation {
···94Agda will not by default use these libraries. To tell Agda to use a library we have some options:
9596* Call `agda` with the library flag:
97+ ```ShellSession
98+ $ agda -l standard-library -i . MyFile.agda
99+ ```
100* Write a `my-library.agda-lib` file for the project you are working on which may look like:
101+ ```
102+ name: my-library
103+ include: .
104+ depend: standard-library
105+ ```
106* Create the file `~/.agda/defaults` and add any libraries you want to use by default.
107108More information can be found in the [official Agda documentation on library management](https://agda.readthedocs.io/en/v2.6.1/tools/package-system.html).
109110+## Compiling Agda {#compiling-agda}
111+112Agda modules can be compiled using the GHC backend with the `--compile` flag. A version of `ghc` with `ieee754` is made available to the Agda program via the `--with-compiler` flag.
113This can be overridden by a different version of `ghc` as follows:
114···119}
120```
121122+## Writing Agda packages {#writing-agda-packages}
123+124To write a nix derivation for an Agda library, first check that the library has a `*.agda-lib` file.
125126A derivation can then be written using `agdaPackages.mkDerivation`. This has similar arguments to `stdenv.mkDerivation` with the following additions:
···144}
145```
146147+### Building Agda packages {#building-agda-packages}
148+149The default build phase for `agdaPackages.mkDerivation` simply runs `agda` on the `Everything.agda` file.
150If something else is needed to build the package (e.g. `make`) then the `buildPhase` should be overridden.
151Additionally, a `preBuild` or `configurePhase` can be used if there are steps that need to be done prior to checking the `Everything.agda` file.
152`agda` and the Agda libraries contained in `buildInputs` are made available during the build phase.
153154+### Installing Agda packages {#installing-agda-packages}
155+156The default install phase copies Agda source files, Agda interface files (`*.agdai`) and `*.agda-lib` files to the output directory.
157This can be overridden.
158159By default, Agda sources are files ending on `.agda`, or literate Agda files ending on `.lagda`, `.lagda.tex`, `.lagda.org`, `.lagda.md`, `.lagda.rst`. The list of recognised Agda source extensions can be extended by setting the `extraExtensions` config variable.
160161+## Adding Agda packages to Nixpkgs {#adding-agda-packages-to-nixpkgs}
162163To add an Agda package to `nixpkgs`, the derivation should be written to `pkgs/development/libraries/agda/${library-name}/` and an entry should be added to `pkgs/top-level/agda-packages.nix`. Here it is called in a scope with access to all other Agda libraries, so the top line of the `default.nix` can look like:
164···188 '';
189}
190```
191+192This library has a file called `.agda-lib`, and so we give an empty string to `libraryFile` as nothing precedes `.agda-lib` in the filename. This file contains `name: IAL-1.3`, and so we let `libraryName = "IAL-1.3"`. This library does not use an `Everything.agda` file and instead has a Makefile, so there is no need to set `everythingFile` and we set a custom `buildPhase`.
193194When writing an Agda package it is essential to make sure that no `.agda-lib` file gets added to the store as a single file (for example by using `writeText`). This causes Agda to think that the nix store is a Agda library and it will attempt to write to it whenever it typechecks something. See [https://github.com/agda/agda/issues/4613](https://github.com/agda/agda/issues/4613).
+17-16
doc/languages-frameworks/android.section.md
···3The Android build environment provides three major features and a number of
4supporting features.
56-Deploying an Android SDK installation with plugins
7---------------------------------------------------
8The first use case is deploying the SDK with a desired set of plugins or subsets
9of an SDK.
10···136androidComposition.platform-tools
137```
138139-Using predefined Android package compositions
140----------------------------------------------
141In addition to composing an Android package set manually, it is also possible
142to use a predefined composition that contains all basic packages for a specific
143Android version, such as version 9.0 (API-level 28).
···159androidenv.androidPkgs_9_0.platform-tools
160```
161162-Building an Android application
163--------------------------------
164In addition to the SDK, it is also possible to build an Ant-based Android
165project and automatically deploy all the Android plugins that a project
166requires.
0167168```nix
169with import <nixpkgs> {};
···199installed on any Android device with a web browser by navigating to the build
200result page.
201202-Spawning emulator instances
203----------------------------
204For testing purposes, it can also be quite convenient to automatically generate
205scripts that spawn emulator instances with all desired configuration settings.
206···241In addition to prebuilt APKs, you can also bind the APK parameter to a
242`buildApp {}` function invocation shown in the previous example.
243244-Notes on environment variables in Android projects
245---------------------------------------------------
246* `ANDROID_SDK_ROOT` should point to the Android SDK. In your Nix expressions, this should be
247 `${androidComposition.androidsdk}/libexec/android-sdk`. Note that `ANDROID_HOME` is deprecated,
248 but if you rely on tools that need it, you can export it too.
···300sdk.dir and ndk.dir values. This will ensure that the SDK and NDK directories will
301both be correct when you run Android Studio inside nix-shell.
302303-Notes on improving build.gradle compatibility
304----------------------------------------------
305Ensure that your buildToolsVersion and ndkVersion match what is declared in androidenv.
306If you are using cmake, make sure its declared version is correct too.
307···321322```
323324-Querying the available versions of each plugin
325-----------------------------------------------
326repo.json provides all the options in one file now.
327328A shell script in the `pkgs/development/mobile/androidenv/` subdirectory can be used to retrieve all
···334335The above command-line instruction queries all package versions in repo.json.
336337-Updating the generated expressions
338-----------------------------------
339repo.json is generated from XML files that the Android Studio package manager uses.
340To update the expressions run the `generate.sh` script that is stored in the
341`pkgs/development/mobile/androidenv/` subdirectory:
···3The Android build environment provides three major features and a number of
4supporting features.
56+## Deploying an Android SDK installation with plugins {#deploying-an-android-sdk-installation-with-plugins}
7+8The first use case is deploying the SDK with a desired set of plugins or subsets
9of an SDK.
10···136androidComposition.platform-tools
137```
138139+## Using predefined Android package compositions {#using-predefined-android-package-compositions}
140+141In addition to composing an Android package set manually, it is also possible
142to use a predefined composition that contains all basic packages for a specific
143Android version, such as version 9.0 (API-level 28).
···159androidenv.androidPkgs_9_0.platform-tools
160```
161162+## Building an Android application {#building-an-android-application}
163+164In addition to the SDK, it is also possible to build an Ant-based Android
165project and automatically deploy all the Android plugins that a project
166requires.
167+168169```nix
170with import <nixpkgs> {};
···200installed on any Android device with a web browser by navigating to the build
201result page.
202203+## Spawning emulator instances {#spawning-emulator-instances}
204+205For testing purposes, it can also be quite convenient to automatically generate
206scripts that spawn emulator instances with all desired configuration settings.
207···242In addition to prebuilt APKs, you can also bind the APK parameter to a
243`buildApp {}` function invocation shown in the previous example.
244245+## Notes on environment variables in Android projects {#notes-on-environment-variables-in-android-projects}
246+247* `ANDROID_SDK_ROOT` should point to the Android SDK. In your Nix expressions, this should be
248 `${androidComposition.androidsdk}/libexec/android-sdk`. Note that `ANDROID_HOME` is deprecated,
249 but if you rely on tools that need it, you can export it too.
···301sdk.dir and ndk.dir values. This will ensure that the SDK and NDK directories will
302both be correct when you run Android Studio inside nix-shell.
303304+## Notes on improving build.gradle compatibility {#notes-on-improving-build.gradle-compatibility}
305+306Ensure that your buildToolsVersion and ndkVersion match what is declared in androidenv.
307If you are using cmake, make sure its declared version is correct too.
308···322323```
324325+## Querying the available versions of each plugin {#querying-the-available-versions-of-each-plugin}
326+327repo.json provides all the options in one file now.
328329A shell script in the `pkgs/development/mobile/androidenv/` subdirectory can be used to retrieve all
···335336The above command-line instruction queries all package versions in repo.json.
337338+## Updating the generated expressions {#updating-the-generated-expressions}
339+340repo.json is generated from XML files that the Android Studio package manager uses.
341To update the expressions run the `generate.sh` script that is stored in the
342`pkgs/development/mobile/androidenv/` subdirectory:
+5-5
doc/languages-frameworks/beam.section.md
···45In this document and related Nix expressions, we use the term, _BEAM_, to describe the environment. BEAM is the name of the Erlang Virtual Machine and, as far as we're concerned, from a packaging perspective, all languages that run on the BEAM are interchangeable. That which varies, like the build system, is transparent to users of any given BEAM package, so we make no distinction.
67-## Available versions and deprecations schedule
89-### Elixir
1011nixpkgs follows the [official elixir deprecation schedule](https://hexdocs.pm/elixir/compatibility-and-deprecations.html) and keeps the last 5 released versions of Elixir available.
12···6869`mixRelease` is used to make a release in the mix sense. Dependencies will need to be fetched with `fetchMixDeps` and passed to it.
7071-#### mixRelease - Elixir Phoenix example
7273Here is how your `default.nix` file would look.
74···148- you can now `nix-build .`
149- To run the release, set the `RELEASE_TMP` environment variable to a directory that your program has write access to. It will be used to store the BEAM settings.
150151-#### Example of creating a service for an Elixir - Phoenix project
152153In order to create a service with your release, you could add a `service.nix`
154in your project with the following
···228}
229```
230231-#### Elixir - Phoenix project
232233Here is an example `shell.nix`.
234
···45In this document and related Nix expressions, we use the term, _BEAM_, to describe the environment. BEAM is the name of the Erlang Virtual Machine and, as far as we're concerned, from a packaging perspective, all languages that run on the BEAM are interchangeable. That which varies, like the build system, is transparent to users of any given BEAM package, so we make no distinction.
67+## Available versions and deprecations schedule {#available-versions-and-deprecations-schedule}
89+### Elixir {#elixir}
1011nixpkgs follows the [official elixir deprecation schedule](https://hexdocs.pm/elixir/compatibility-and-deprecations.html) and keeps the last 5 released versions of Elixir available.
12···6869`mixRelease` is used to make a release in the mix sense. Dependencies will need to be fetched with `fetchMixDeps` and passed to it.
7071+#### mixRelease - Elixir Phoenix example {#mixrelease---elixir-phoenix-example}
7273Here is how your `default.nix` file would look.
74···148- you can now `nix-build .`
149- To run the release, set the `RELEASE_TMP` environment variable to a directory that your program has write access to. It will be used to store the BEAM settings.
150151+#### Example of creating a service for an Elixir - Phoenix project {#example-of-creating-a-service-for-an-elixir---phoenix-project}
152153In order to create a service with your release, you could add a `service.nix`
154in your project with the following
···228}
229```
230231+#### Elixir - Phoenix project {#elixir---phoenix-project}
232233Here is an example `shell.nix`.
234
+1-1
doc/languages-frameworks/bower.section.md
···149150## Troubleshooting {#ssec-bower2nix-troubleshooting}
151152-### ENOCACHE errors from buildBowerComponents
153154This means that Bower was looking for a package version which doesn't exist in the generated `bower-packages.nix`.
155
···149150## Troubleshooting {#ssec-bower2nix-troubleshooting}
151152+### ENOCACHE errors from buildBowerComponents {#enocache-errors-from-buildbowercomponents}
153154This means that Bower was looking for a package version which doesn't exist in the generated `bower-packages.nix`.
155
+2-2
doc/languages-frameworks/coq.section.md
···1# Coq and coq packages {#sec-language-coq}
23-## Coq derivation: `coq`
45The Coq derivation is overridable through the `coq.override overrides`, where overrides is an attribute set which contains the arguments to override. We recommend overriding either of the following
6···8* `customOCamlPackage` (optional, defaults to `null`, which lets Coq choose a version automatically), which can be set to any of the ocaml packages attribute of `ocaml-ng` (such as `ocaml-ng.ocamlPackages_4_10` which is the default for Coq 8.11 for example).
9* `coq-version` (optional, defaults to the short version e.g. "8.10"), is a version number of the form "x.y" that indicates which Coq's version build behavior to mimic when using a source which is not a release. E.g. `coq.override { version = "d370a9d1328a4e1cdb9d02ee032f605a9d94ec7a"; coq-version = "8.10"; }`.
1011-## Coq packages attribute sets: `coqPackages`
1213The recommended way of defining a derivation for a Coq library, is to use the `coqPackages.mkCoqDerivation` function, which is essentially a specialization of `mkDerivation` taking into account most of the specifics of Coq libraries. The following attributes are supported:
14
···1# Coq and coq packages {#sec-language-coq}
23+## Coq derivation: `coq` {#coq-derivation-coq}
45The Coq derivation is overridable through the `coq.override overrides`, where overrides is an attribute set which contains the arguments to override. We recommend overriding either of the following
6···8* `customOCamlPackage` (optional, defaults to `null`, which lets Coq choose a version automatically), which can be set to any of the ocaml packages attribute of `ocaml-ng` (such as `ocaml-ng.ocamlPackages_4_10` which is the default for Coq 8.11 for example).
9* `coq-version` (optional, defaults to the short version e.g. "8.10"), is a version number of the form "x.y" that indicates which Coq's version build behavior to mimic when using a source which is not a release. E.g. `coq.override { version = "d370a9d1328a4e1cdb9d02ee032f605a9d94ec7a"; coq-version = "8.10"; }`.
1011+## Coq packages attribute sets: `coqPackages` {#coq-packages-attribute-sets-coqpackages}
1213The recommended way of defining a derivation for a Coq library, is to use the `coqPackages.mkCoqDerivation` function, which is essentially a specialization of `mkDerivation` taking into account most of the specifics of Coq libraries. The following attributes are supported:
14
+3-1
doc/languages-frameworks/crystal.section.md
···1# Crystal {#crystal}
23-## Building a Crystal package
45This section uses [Mint](https://github.com/mint-lang/mint) as an example for how to build a Crystal package.
67If the Crystal project has any dependencies, the first step is to get a `shards.nix` file encoding those. Get a copy of the project and go to its root directory such that its `shard.lock` file is in the current directory, then run `crystal2nix` in it
08```bash
9$ git clone https://github.com/mint-lang/mint
10$ cd mint
···15This should have generated a `shards.nix` file.
1617Next create a Nix file for your derivation and use `pkgs.crystal.buildCrystalPackage` as follows:
018```nix
19with import <nixpkgs> {};
20crystal.buildCrystalPackage rec {
···1# Crystal {#crystal}
23+## Building a Crystal package {#building-a-crystal-package}
45This section uses [Mint](https://github.com/mint-lang/mint) as an example for how to build a Crystal package.
67If the Crystal project has any dependencies, the first step is to get a `shards.nix` file encoding those. Get a copy of the project and go to its root directory such that its `shard.lock` file is in the current directory, then run `crystal2nix` in it
8+9```bash
10$ git clone https://github.com/mint-lang/mint
11$ cd mint
···16This should have generated a `shards.nix` file.
1718Next create a Nix file for your derivation and use `pkgs.crystal.buildCrystalPackage` as follows:
19+20```nix
21with import <nixpkgs> {};
22crystal.buildCrystalPackage rec {
+7-7
doc/languages-frameworks/dotnet.section.md
···1-# Dotnet
23-## Local Development Workflow
45For local development, it's recommended to use nix-shell to create a dotnet environment:
6···16}
17```
1819-### Using many sdks in a workflow
2021It's very likely that more than one sdk will be needed on a given project. Dotnet provides several different frameworks (E.g dotnetcore, aspnetcore, etc.) as well as many versions for a given framework. Normally, dotnet is able to fetch a framework and install it relative to the executable. However, this would mean writing to the nix store in nixpkgs, which is read-only. To support the many-sdk use case, one can compose an environment using `dotnetCorePackages.combinePackages`:
22···3738This will produce a dotnet installation that has the dotnet 3.1, 3.0, and 2.1 sdk. The first sdk listed will have it's cli utility present in the resulting environment. Example info output:
3940-```ShellSesssion
41$ dotnet --info
42.NET Core SDK (reflecting any global.json):
43 Version: 3.1.101
···60 Microsoft.NETCore.App 3.1.1 [/nix/store/iiv98i2jdi226dgh4jzkkj2ww7f8jgpd-dotnet-core-combined/shared/Microsoft.NETCore.App]
61```
6263-## dotnet-sdk vs dotnetCorePackages.sdk
6465The `dotnetCorePackages.sdk_X_Y` is preferred over the old dotnet-sdk as both major and minor version are very important for a dotnet environment. If a given minor version isn't present (or was changed), then this will likely break your ability to build a project.
6667-## dotnetCorePackages.sdk vs dotnetCorePackages.net vs dotnetCorePackages.netcore vs dotnetCorePackages.aspnetcore
6869The `dotnetCorePackages.sdk` contains both a runtime and the full sdk of a given version. The `net`, `netcore` and `aspnetcore` packages are meant to serve as minimal runtimes to deploy alongside already built applications. For runtime versions >= .NET 5 `net` is used while `netcore` is used for older .NET Core runtime version.
7071-## Packaging a Dotnet Application
7273Ideally, we would like to build against the sdk, then only have the dotnet runtime available in the runtime closure.
74
···1+# Dotnet {#dotnet}
23+## Local Development Workflow {#local-development-workflow}
45For local development, it's recommended to use nix-shell to create a dotnet environment:
6···16}
17```
1819+### Using many sdks in a workflow {#using-many-sdks-in-a-workflow}
2021It's very likely that more than one sdk will be needed on a given project. Dotnet provides several different frameworks (E.g dotnetcore, aspnetcore, etc.) as well as many versions for a given framework. Normally, dotnet is able to fetch a framework and install it relative to the executable. However, this would mean writing to the nix store in nixpkgs, which is read-only. To support the many-sdk use case, one can compose an environment using `dotnetCorePackages.combinePackages`:
22···3738This will produce a dotnet installation that has the dotnet 3.1, 3.0, and 2.1 sdk. The first sdk listed will have it's cli utility present in the resulting environment. Example info output:
3940+```ShellSession
41$ dotnet --info
42.NET Core SDK (reflecting any global.json):
43 Version: 3.1.101
···60 Microsoft.NETCore.App 3.1.1 [/nix/store/iiv98i2jdi226dgh4jzkkj2ww7f8jgpd-dotnet-core-combined/shared/Microsoft.NETCore.App]
61```
6263+## dotnet-sdk vs dotnetCorePackages.sdk {#dotnet-sdk-vs-dotnetcorepackages.sdk}
6465The `dotnetCorePackages.sdk_X_Y` is preferred over the old dotnet-sdk as both major and minor version are very important for a dotnet environment. If a given minor version isn't present (or was changed), then this will likely break your ability to build a project.
6667+## dotnetCorePackages.sdk vs dotnetCorePackages.net vs dotnetCorePackages.netcore vs dotnetCorePackages.aspnetcore {#dotnetcorepackages.sdk-vs-dotnetcorepackages.net-vs-dotnetcorepackages.netcore-vs-dotnetcorepackages.aspnetcore}
6869The `dotnetCorePackages.sdk` contains both a runtime and the full sdk of a given version. The `net`, `netcore` and `aspnetcore` packages are meant to serve as minimal runtimes to deploy alongside already built applications. For runtime versions >= .NET 5 `net` is used while `netcore` is used for older .NET Core runtime version.
7071+## Packaging a Dotnet Application {#packaging-a-dotnet-application}
7273Ideally, we would like to build against the sdk, then only have the dotnet runtime available in the runtime closure.
74
+6-8
doc/languages-frameworks/emscripten.section.md
···27 * dev-shell for zlib implementation hacking:
28 * `nix-shell -A emscriptenPackages.zlib`
2930-31-## Imperative usage
3233A few things to note:
3435* `export EMCC_DEBUG=2` is nice for debugging
36* `~/.emscripten`, the build artifact cache sometimes creates issues and needs to be removed from time to time
3738-39-## Declarative usage
4041Let's see two different examples from `pkgs/top-level/emscripten-packages.nix`:
42···50* Use `export EMCC_DEBUG=2` from within a emscriptenPackage's `phase` to get more detailed debug output what is going wrong.
51* ~/.emscripten cache is requiring us to set `HOME=$TMPDIR` in individual phases. This makes compilation slower but also makes it more deterministic.
5253-### Usage 1: pkgs.zlib.override
5455This example uses `zlib` from nixpkgs but instead of compiling **C** to **ELF** it compiles **C** to **JS** since we were using `pkgs.zlib.override` and changed stdenv to `pkgs.emscriptenStdenv`. A few adaptions and hacks were set in place to make it working. One advantage is that when `pkgs.zlib` is updated, it will automatically update this package as well. However, this can also be the downside...
56···110 '';
111 });
112113-### Usage 2: pkgs.buildEmscriptenPackage
114115This `xmlmirror` example features a emscriptenPackage which is defined completely from this context and no `pkgs.zlib.override` is used.
116···165 '';
166 };
167168-### Declarative debugging
169170Use `nix-shell -I nixpkgs=/some/dir/nixpkgs -A emscriptenPackages.libz` and from there you can go trough the individual steps. This makes it easy to build a good `unit test` or list the files of the project.
171···1776. `buildPhase`
1787. ... happy hacking...
179180-## Summary
181182Using this toolchain makes it easy to leverage `nix` from NixOS, MacOSX or even Windows (WSL+ubuntu+nix). This toolchain is reproducible, behaves like the rest of the packages from nixpkgs and contains a set of well working examples to learn and adapt from.
183
···27 * dev-shell for zlib implementation hacking:
28 * `nix-shell -A emscriptenPackages.zlib`
2930+## Imperative usage {#imperative-usage}
03132A few things to note:
3334* `export EMCC_DEBUG=2` is nice for debugging
35* `~/.emscripten`, the build artifact cache sometimes creates issues and needs to be removed from time to time
3637+## Declarative usage {#declarative-usage}
03839Let's see two different examples from `pkgs/top-level/emscripten-packages.nix`:
40···48* Use `export EMCC_DEBUG=2` from within a emscriptenPackage's `phase` to get more detailed debug output what is going wrong.
49* ~/.emscripten cache is requiring us to set `HOME=$TMPDIR` in individual phases. This makes compilation slower but also makes it more deterministic.
5051+### Usage 1: pkgs.zlib.override {#usage-1-pkgs.zlib.override}
5253This example uses `zlib` from nixpkgs but instead of compiling **C** to **ELF** it compiles **C** to **JS** since we were using `pkgs.zlib.override` and changed stdenv to `pkgs.emscriptenStdenv`. A few adaptions and hacks were set in place to make it working. One advantage is that when `pkgs.zlib` is updated, it will automatically update this package as well. However, this can also be the downside...
54···108 '';
109 });
110111+### Usage 2: pkgs.buildEmscriptenPackage {#usage-2-pkgs.buildemscriptenpackage}
112113This `xmlmirror` example features a emscriptenPackage which is defined completely from this context and no `pkgs.zlib.override` is used.
114···163 '';
164 };
165166+### Declarative debugging {#declarative-debugging}
167168Use `nix-shell -I nixpkgs=/some/dir/nixpkgs -A emscriptenPackages.libz` and from there you can go trough the individual steps. This makes it easy to build a good `unit test` or list the files of the project.
169···1756. `buildPhase`
1767. ... happy hacking...
177178+## Summary {#summary}
179180Using this toolchain makes it easy to leverage `nix` from NixOS, MacOSX or even Windows (WSL+ubuntu+nix). This toolchain is reproducible, behaves like the rest of the packages from nixpkgs and contains a set of well working examples to learn and adapt from.
181
+1-1
doc/languages-frameworks/gnome.section.md
···8485- []{#ssec-gnome-hooks-gobject-introspection} `gobject-introspection` setup hook populates `GI_TYPELIB_PATH` variable with `lib/girepository-1.0` directories of dependencies, which is then added to wrapper by `wrapGAppsHook`. It also adds `share` directories of dependencies to `XDG_DATA_DIRS`, which is intended to promote GIR files but it also [pollutes the closures](https://github.com/NixOS/nixpkgs/issues/32790) of packages using `wrapGAppsHook`.
8687- ::: warning
88 The setup hook [currently](https://github.com/NixOS/nixpkgs/issues/56943) does not work in expressions with `strictDeps` enabled, like Python packages. In those cases, you will need to disable it with `strictDeps = false;`.
89 :::
90
···8485- []{#ssec-gnome-hooks-gobject-introspection} `gobject-introspection` setup hook populates `GI_TYPELIB_PATH` variable with `lib/girepository-1.0` directories of dependencies, which is then added to wrapper by `wrapGAppsHook`. It also adds `share` directories of dependencies to `XDG_DATA_DIRS`, which is intended to promote GIR files but it also [pollutes the closures](https://github.com/NixOS/nixpkgs/issues/32790) of packages using `wrapGAppsHook`.
8687+ ::: {.warning}
88 The setup hook [currently](https://github.com/NixOS/nixpkgs/issues/56943) does not work in expressions with `strictDeps` enabled, like Python packages. In those cases, you will need to disable it with `strictDeps = false;`.
89 :::
90
+2-2
doc/languages-frameworks/go.section.md
···4445The function `buildGoPackage` builds legacy Go programs, not supporting Go modules.
4647-### Example for `buildGoPackage`
4849In the following is an example expression using buildGoPackage, the following arguments are of special significance to the function:
50···140141### `subPackages` {#var-go-subPackages}
142143-Limits the builder from building child packages that have not been listed. If <varname>subPackages</varname> is not specified, all child packages will be built.
···4445The function `buildGoPackage` builds legacy Go programs, not supporting Go modules.
4647+### Example for `buildGoPackage` {#example-for-buildgopackage}
4849In the following is an example expression using buildGoPackage, the following arguments are of special significance to the function:
50···140141### `subPackages` {#var-go-subPackages}
142143+Limits the builder from building child packages that have not been listed. If `subPackages` is not specified, all child packages will be built.
+14-12
doc/languages-frameworks/idris.section.md
···1# Idris {#idris}
23-## Installing Idris
45The easiest way to get a working idris version is to install the `idris` attribute:
67-```ShellSesssion
8$ # On NixOS
9$ nix-env -i nixos.idris
10$ # On non-NixOS
···2122And then:
2324-```ShellSesssion
25$ # On NixOS
26$ nix-env -iA nixos.myIdris
27$ # On non-NixOS
···29```
3031To see all available Idris packages:
32-```ShellSesssion
033$ # On NixOS
34$ nix-env -qaPA nixos.idrisPackages
35$ # On non-NixOS
···37```
3839Similarly, entering a `nix-shell`:
40-```ShellSesssion
041$ nix-shell -p 'idrisPackages.with-packages (with idrisPackages; [ contrib pruviloj ])'
42```
4344-## Starting Idris with library support
4546To have access to these libraries in idris, call it with an argument `-p <library name>` for each library:
4748-```ShellSesssion
49$ nix-shell -p 'idrisPackages.with-packages (with idrisPackages; [ contrib pruviloj ])'
50[nix-shell:~]$ idris -p contrib -p pruviloj
51```
5253A listing of all available packages the Idris binary has access to is available via `--listlibs`:
5455-```ShellSesssion
56$ idris --listlibs
5700prelude-idx.ibc
58pruviloj
···6400contrib-idx.ibc
65```
6667-## Building an Idris project with Nix
6869As an example of how a Nix expression for an Idris package can be created, here is the one for `idrisPackages.yaml`:
70···105106Assuming this file is saved as `yaml.nix`, it's buildable using
107108-```ShellSesssion
109$ nix-build -E '(import <nixpkgs> {}).idrisPackages.callPackage ./yaml.nix {}'
110```
111···121122in another file (say `default.nix`) to be able to build it with
123124-```ShellSesssion
125$ nix-build -A yaml
126```
127128-## Passing options to `idris` commands
129130The `build-idris-package` function provides also optional input values to set additional options for the used `idris` commands.
131
···1# Idris {#idris}
23+## Installing Idris {#installing-idris}
45The easiest way to get a working idris version is to install the `idris` attribute:
67+```ShellSession
8$ # On NixOS
9$ nix-env -i nixos.idris
10$ # On non-NixOS
···2122And then:
2324+```ShellSession
25$ # On NixOS
26$ nix-env -iA nixos.myIdris
27$ # On non-NixOS
···29```
3031To see all available Idris packages:
32+33+```ShellSession
34$ # On NixOS
35$ nix-env -qaPA nixos.idrisPackages
36$ # On non-NixOS
···38```
3940Similarly, entering a `nix-shell`:
41+42+```ShellSession
43$ nix-shell -p 'idrisPackages.with-packages (with idrisPackages; [ contrib pruviloj ])'
44```
4546+## Starting Idris with library support {#starting-idris-with-library-support}
4748To have access to these libraries in idris, call it with an argument `-p <library name>` for each library:
4950+```ShellSession
51$ nix-shell -p 'idrisPackages.with-packages (with idrisPackages; [ contrib pruviloj ])'
52[nix-shell:~]$ idris -p contrib -p pruviloj
53```
5455A listing of all available packages the Idris binary has access to is available via `--listlibs`:
5657+```ShellSession
58$ idris --listlibs
5900prelude-idx.ibc
60pruviloj
···6600contrib-idx.ibc
67```
6869+## Building an Idris project with Nix {#building-an-idris-project-with-nix}
7071As an example of how a Nix expression for an Idris package can be created, here is the one for `idrisPackages.yaml`:
72···107108Assuming this file is saved as `yaml.nix`, it's buildable using
109110+```ShellSession
111$ nix-build -E '(import <nixpkgs> {}).idrisPackages.callPackage ./yaml.nix {}'
112```
113···123124in another file (say `default.nix`) to be able to build it with
125126+```ShellSession
127$ nix-build -A yaml
128```
129130+## Passing options to `idris` commands {#passing-options-to-idris-commands}
131132The `build-idris-package` function provides also optional input values to set additional options for the used `idris` commands.
133
+9-8
doc/languages-frameworks/ios.section.md
···2021The Xcode build environment implements a number of features.
2223-Deploying a proxy component wrapper exposing Xcode
24---------------------------------------------------
25The first use case is deploying a Nix package that provides symlinks to the Xcode
26installation on the host system. This package can be used as a build input to
27any build function implemented in the Nix expression language that requires
···55lrwxr-xr-x 1 sander staff 14 1 jan 1970 xcrun -> /usr/bin/xcrun
56```
5758-Building an iOS application
59----------------------------
60We can build an iOS app executable for the simulator, or an IPA/xcarchive file
61for release purposes, e.g. ad-hoc, enterprise or store installations, by
62executing the `xcodeenv.buildApp {}` function:
···99```
100101The above function takes a variety of parameters:
0102* The `name` and `src` parameters are mandatory and specify the name of the app
103 and the location where the source code resides
104* `sdkVersion` specifies which version of the iOS SDK to use.
···151`xcodeBaseDir` parameter can be overridden to refer to a different Xcode
152version.
153154-Spawning simulator instances
155-----------------------------
156In addition to building iOS apps, we can also automatically spawn simulator
157instances:
158···213By providing the result of an `xcode.buildApp {}` function and configuring the
214app bundle id, the app gets deployed automatically and started.
215216-Troubleshooting
217----------------
218In some rare cases, it may happen that after a failure, changes are not picked
219up. Most likely, this is caused by a derived data cache that Xcode maintains.
220To wipe it you can run:
···2021The Xcode build environment implements a number of features.
2223+## Deploying a proxy component wrapper exposing Xcode {#deploying-a-proxy-component-wrapper-exposing-xcode}
24+25The first use case is deploying a Nix package that provides symlinks to the Xcode
26installation on the host system. This package can be used as a build input to
27any build function implemented in the Nix expression language that requires
···55lrwxr-xr-x 1 sander staff 14 1 jan 1970 xcrun -> /usr/bin/xcrun
56```
5758+## Building an iOS application {#building-an-ios-application}
59+60We can build an iOS app executable for the simulator, or an IPA/xcarchive file
61for release purposes, e.g. ad-hoc, enterprise or store installations, by
62executing the `xcodeenv.buildApp {}` function:
···99```
100101The above function takes a variety of parameters:
102+103* The `name` and `src` parameters are mandatory and specify the name of the app
104 and the location where the source code resides
105* `sdkVersion` specifies which version of the iOS SDK to use.
···152`xcodeBaseDir` parameter can be overridden to refer to a different Xcode
153version.
154155+## Spawning simulator instances {#spawning-simulator-instances}
156+157In addition to building iOS apps, we can also automatically spawn simulator
158instances:
159···214By providing the result of an `xcode.buildApp {}` function and configuring the
215app bundle id, the app gets deployed automatically and started.
216217+## Troubleshooting {#troubleshooting}
218+219In some rare cases, it may happen that after a failure, changes are not picked
220up. Most likely, this is caused by a derived data cache that Xcode maintains.
221To wipe it you can run:
+33-23
doc/languages-frameworks/lua.section.md
···1-# User's Guide to Lua Infrastructure {#users-guide-to-lua-infrastructure}
23-## Using Lua
45-### Overview of Lua
67Several versions of the Lua interpreter are available: luajit, lua 5.1, 5.2, 5.3.
8The attribute `lua` refers to the default interpreter, it is also possible to refer to specific versions, e.g. `lua5_2` refers to Lua 5.2.
···17`luaPackages` refers to `lua5_1.pkgs` and `lua52Packages` to
18`lua5_2.pkgs`.
1920-### Installing Lua and packages
2122-#### Lua environment defined in separate `.nix` file
2324Create a file, e.g. `build.nix`, with the following expression
025```nix
26with import <nixpkgs> {};
2728lua5_2.withPackages (ps: with ps; [ busted luafilesystem ])
29```
030and install it in your profile with
031```shell
32nix-env -if build.nix
33```
34Now you can use the Lua interpreter, as well as the extra packages (`busted`,
35`luafilesystem`) that you added to the environment.
3637-#### Lua environment defined in `~/.config/nixpkgs/config.nix`
3839If you prefer to, you could also add the environment as a package override to the Nixpkgs set, e.g.
40using `config.nix`,
041```nix
42{ # ...
43···46 };
47}
48```
049and install it in your profile with
050```shell
51nix-env -iA nixpkgs.myLuaEnv
52```
53The environment is installed by referring to the attribute, and considering
54the `nixpkgs` channel was used.
5556-#### Lua environment defined in `/etc/nixos/configuration.nix`
5758For the sake of completeness, here's another example how to install the environment system-wide.
59···66}
67```
6869-### How to override a Lua package using overlays?
7071Use the following overlay template:
72···87}
88```
8990-### Temporary Lua environment with `nix-shell`
919293There are two methods for loading a shell with Lua packages. The first and recommended method
94is to create an environment with `lua.buildEnv` or `lua.withPackages` and load that. E.g.
095```sh
96$ nix-shell -p 'lua.withPackages(ps: with ps; [ busted luafilesystem ])'
97```
098opens a shell from which you can launch the interpreter
099```sh
100[nix-shell:~] lua
101```
0102The other method, which is not recommended, does not create an environment and requires you to list the packages directly,
103104```sh
···108The Lua interpreter has the attribute `pkgs` which contains all Lua libraries for that specific interpreter.
109110111-## Developing with Lua
112113Now that you know how to get a working Lua environment with Nix, it is time
114to go forward and start actually developing with Lua. There are two ways to
···116of by the luarocks2nix converter or the packaging has to be done manually.
117Let's present the luarocks way first and the manual one in a second time.
118119-### Packaging a library on luarocks
120121[Luarocks.org](www.luarocks.org) is the main repository of lua packages.
122The site proposes two types of packages, the rockspec and the src.rock
···135Nix rely on luarocks to install lua packages, basically it runs:
136`luarocks make --deps-mode=none --tree $out`
137138-#### Packaging a library manually
139140You can develop your package as you usually would, just don't forget to wrap it
141within a `toLuaModule` call, for instance
0142```nix
143mynewlib = toLuaModule ( stdenv.mkDerivation { ... });
144```
···146There is also the `buildLuaPackage` function that can be used when lua modules
147are not packaged for luarocks. You can see a few examples at `pkgs/top-level/lua-packages.nix`.
148149-## Lua Reference
150151-### Lua interpreters
152153Versions 5.1, 5.2 and 5.3 of the lua interpreter are available as
154respectively `lua5_1`, `lua5_2` and `lua5_3`. Luajit is available too.
155The Nix expressions for the interpreters can be found in `pkgs/development/interpreters/lua-5`.
156157-158-#### Attributes on lua interpreters packages
159160Each interpreter has the following attributes:
161···164- `withPackages`. Simpler interface to `buildEnv`.
165- `pkgs`. Set of Lua packages for that specific interpreter. The package set can be modified by overriding the interpreter and passing `packageOverrides`.
166167-168-#### `buildLuarocksPackage` function
169170The `buildLuarocksPackage` function is implemented in `pkgs/development/interpreters/lua-5/build-lua-package.nix`
171The following is an example:
···205206By default `meta.platforms` is set to the same value as the interpreter unless overridden otherwise.
207208-#### `buildLuaApplication` function
209210The `buildLuaApplication` function is practically the same as `buildLuaPackage`.
211The difference is that `buildLuaPackage` by default prefixes the names of the packages with the version of the interpreter.
212Because with an application we're not interested in multiple version the prefix is dropped.
213214-#### lua.withPackages function
215216The `lua.withPackages` takes a function as an argument that is passed the set of lua packages and returns the list of packages to be included in the environment.
217Using the `withPackages` function, the previous example for the luafilesystem environment can be written like this:
0218```nix
219with import <nixpkgs> {};
220···223224`withPackages` passes the correct package set for the specific interpreter version as an argument to the function. In the above example, `ps` equals `luaPackages`.
225But you can also easily switch to using `lua5_2`:
0226```nix
227with import <nixpkgs> {};
228···231232Now, `ps` is set to `lua52Packages`, matching the version of the interpreter.
233234-235-### Possible Todos
236237* export/use version specific variables such as `LUA_PATH_5_2`/`LUAROCKS_CONFIG_5_2`
238* let luarocks check for dependencies via exporting the different rocktrees in temporary config
239240-### Lua Contributing guidelines
241242Following rules should be respected:
243
···1+# User’s Guide to Lua Infrastructure {#users-guide-to-lua-infrastructure}
23+## Using Lua {#using-lua}
45+### Overview of Lua {#overview-of-lua}
67Several versions of the Lua interpreter are available: luajit, lua 5.1, 5.2, 5.3.
8The attribute `lua` refers to the default interpreter, it is also possible to refer to specific versions, e.g. `lua5_2` refers to Lua 5.2.
···17`luaPackages` refers to `lua5_1.pkgs` and `lua52Packages` to
18`lua5_2.pkgs`.
1920+### Installing Lua and packages {#installing-lua-and-packages}
2122+#### Lua environment defined in separate `.nix` file {#lua-environment-defined-in-separate-.nix-file}
2324Create a file, e.g. `build.nix`, with the following expression
25+26```nix
27with import <nixpkgs> {};
2829lua5_2.withPackages (ps: with ps; [ busted luafilesystem ])
30```
31+32and install it in your profile with
33+34```shell
35nix-env -if build.nix
36```
37Now you can use the Lua interpreter, as well as the extra packages (`busted`,
38`luafilesystem`) that you added to the environment.
3940+#### Lua environment defined in `~/.config/nixpkgs/config.nix` {#lua-environment-defined-in-.confignixpkgsconfig.nix}
4142If you prefer to, you could also add the environment as a package override to the Nixpkgs set, e.g.
43using `config.nix`,
44+45```nix
46{ # ...
47···50 };
51}
52```
53+54and install it in your profile with
55+56```shell
57nix-env -iA nixpkgs.myLuaEnv
58```
59The environment is installed by referring to the attribute, and considering
60the `nixpkgs` channel was used.
6162+#### Lua environment defined in `/etc/nixos/configuration.nix` {#lua-environment-defined-in-etcnixosconfiguration.nix}
6364For the sake of completeness, here's another example how to install the environment system-wide.
65···72}
73```
7475+### How to override a Lua package using overlays? {#how-to-override-a-lua-package-using-overlays}
7677Use the following overlay template:
78···93}
94```
9596+### Temporary Lua environment with `nix-shell` {#temporary-lua-environment-with-nix-shell}
979899There are two methods for loading a shell with Lua packages. The first and recommended method
100is to create an environment with `lua.buildEnv` or `lua.withPackages` and load that. E.g.
101+102```sh
103$ nix-shell -p 'lua.withPackages(ps: with ps; [ busted luafilesystem ])'
104```
105+106opens a shell from which you can launch the interpreter
107+108```sh
109[nix-shell:~] lua
110```
111+112The other method, which is not recommended, does not create an environment and requires you to list the packages directly,
113114```sh
···118The Lua interpreter has the attribute `pkgs` which contains all Lua libraries for that specific interpreter.
119120121+## Developing with Lua {#developing-with-lua}
122123Now that you know how to get a working Lua environment with Nix, it is time
124to go forward and start actually developing with Lua. There are two ways to
···126of by the luarocks2nix converter or the packaging has to be done manually.
127Let's present the luarocks way first and the manual one in a second time.
128129+### Packaging a library on luarocks {#packaging-a-library-on-luarocks}
130131[Luarocks.org](www.luarocks.org) is the main repository of lua packages.
132The site proposes two types of packages, the rockspec and the src.rock
···145Nix rely on luarocks to install lua packages, basically it runs:
146`luarocks make --deps-mode=none --tree $out`
147148+#### Packaging a library manually {#packaging-a-library-manually}
149150You can develop your package as you usually would, just don't forget to wrap it
151within a `toLuaModule` call, for instance
152+153```nix
154mynewlib = toLuaModule ( stdenv.mkDerivation { ... });
155```
···157There is also the `buildLuaPackage` function that can be used when lua modules
158are not packaged for luarocks. You can see a few examples at `pkgs/top-level/lua-packages.nix`.
159160+## Lua Reference {#lua-reference}
161162+### Lua interpreters {#lua-interpreters}
163164Versions 5.1, 5.2 and 5.3 of the lua interpreter are available as
165respectively `lua5_1`, `lua5_2` and `lua5_3`. Luajit is available too.
166The Nix expressions for the interpreters can be found in `pkgs/development/interpreters/lua-5`.
167168+#### Attributes on lua interpreters packages {#attributes-on-lua-interpreters-packages}
0169170Each interpreter has the following attributes:
171···174- `withPackages`. Simpler interface to `buildEnv`.
175- `pkgs`. Set of Lua packages for that specific interpreter. The package set can be modified by overriding the interpreter and passing `packageOverrides`.
176177+#### `buildLuarocksPackage` function {#buildluarockspackage-function}
0178179The `buildLuarocksPackage` function is implemented in `pkgs/development/interpreters/lua-5/build-lua-package.nix`
180The following is an example:
···214215By default `meta.platforms` is set to the same value as the interpreter unless overridden otherwise.
216217+#### `buildLuaApplication` function {#buildluaapplication-function}
218219The `buildLuaApplication` function is practically the same as `buildLuaPackage`.
220The difference is that `buildLuaPackage` by default prefixes the names of the packages with the version of the interpreter.
221Because with an application we're not interested in multiple version the prefix is dropped.
222223+#### lua.withPackages function {#lua.withpackages-function}
224225The `lua.withPackages` takes a function as an argument that is passed the set of lua packages and returns the list of packages to be included in the environment.
226Using the `withPackages` function, the previous example for the luafilesystem environment can be written like this:
227+228```nix
229with import <nixpkgs> {};
230···233234`withPackages` passes the correct package set for the specific interpreter version as an argument to the function. In the above example, `ps` equals `luaPackages`.
235But you can also easily switch to using `lua5_2`:
236+237```nix
238with import <nixpkgs> {};
239···242243Now, `ps` is set to `lua52Packages`, matching the version of the interpreter.
244245+### Possible Todos {#possible-todos}
0246247* export/use version specific variables such as `LUA_PATH_5_2`/`LUAROCKS_CONFIG_5_2`
248* let luarocks check for dependencies via exporting the different rocktrees in temporary config
249250+### Lua Contributing guidelines {#lua-contributing-guidelines}
251252Following rules should be respected:
253
+10-7
doc/languages-frameworks/maven.section.md
···4344You find this demo project at https://github.com/fzakaria/nixos-maven-example
4546-## Solving for dependencies
4748-### buildMaven with NixOS/mvn2nix-maven-plugin
4950> ⚠️ Although `buildMaven` is the "blessed" way within nixpkgs, as of 2020, it hasn't seen much activity in quite a while.
51···82 A simple derivation that runs through `mvn compile` & `mvn package` to build the JAR. You may use this as inspiration for more complicated derivations.
8384Here is an [example](https://github.com/fzakaria/nixos-maven-example/blob/main/build-maven-repository.nix) of building the Maven repository
085```nix
86{ pkgs ? import <nixpkgs> { } }:
87with pkgs;
···103│ └── 4.1.3
104│ ├── avalon-framework-4.1.3.jar -> /nix/store/iv5fp3955w3nq28ff9xfz86wvxbiw6n9-avalon-framework-4.1.3.jar
105```
106-### Double Invocation
0107108> ⚠️ This pattern is the simplest but may cause unnecessary rebuilds due to the output hash changing.
109···163164If your package uses _SNAPSHOT_ dependencies or _version ranges_; there is a strong likelihood that over-time your output hash will change since the resolved dependencies may change. Hence this method is less recommended then using `buildMaven`.
165166-## Building a JAR
167168Regardless of which strategy is chosen above, the step to build the derivation is the same.
169···2012 directories, 1 file
202```
203204-## Runnable JAR
205206The previous example builds a `jar` file but that's not a file one can run.
207···213214The following two methods are more suited to Nix then building an [UberJar](https://imagej.net/Uber-JAR) which may be the more traditional approach.
215216-### CLASSPATH
217218> This is ideal if you are providing a derivation for _nixpkgs_ and don't want to patch the project's `pom.xml`.
219···252}
253```
254255-### MANIFEST file via Maven Plugin
256257> This is ideal if you are the project owner and want to change your `pom.xml` to set the CLASSPATH within it.
258259Augment the `pom.xml` to create a JAR with the following manifest:
0260```xml
261<build>
262 <plugins>
···4344You find this demo project at https://github.com/fzakaria/nixos-maven-example
4546+## Solving for dependencies {#solving-for-dependencies}
4748+### buildMaven with NixOS/mvn2nix-maven-plugin {#buildmaven-with-nixosmvn2nix-maven-plugin}
4950> ⚠️ Although `buildMaven` is the "blessed" way within nixpkgs, as of 2020, it hasn't seen much activity in quite a while.
51···82 A simple derivation that runs through `mvn compile` & `mvn package` to build the JAR. You may use this as inspiration for more complicated derivations.
8384Here is an [example](https://github.com/fzakaria/nixos-maven-example/blob/main/build-maven-repository.nix) of building the Maven repository
85+86```nix
87{ pkgs ? import <nixpkgs> { } }:
88with pkgs;
···104│ └── 4.1.3
105│ ├── avalon-framework-4.1.3.jar -> /nix/store/iv5fp3955w3nq28ff9xfz86wvxbiw6n9-avalon-framework-4.1.3.jar
106```
107+108+### Double Invocation {#double-invocation}
109110> ⚠️ This pattern is the simplest but may cause unnecessary rebuilds due to the output hash changing.
111···165166If your package uses _SNAPSHOT_ dependencies or _version ranges_; there is a strong likelihood that over-time your output hash will change since the resolved dependencies may change. Hence this method is less recommended then using `buildMaven`.
167168+## Building a JAR {#building-a-jar}
169170Regardless of which strategy is chosen above, the step to build the derivation is the same.
171···2032 directories, 1 file
204```
205206+## Runnable JAR {#runnable-jar}
207208The previous example builds a `jar` file but that's not a file one can run.
209···215216The following two methods are more suited to Nix then building an [UberJar](https://imagej.net/Uber-JAR) which may be the more traditional approach.
217218+### CLASSPATH {#classpath}
219220> This is ideal if you are providing a derivation for _nixpkgs_ and don't want to patch the project's `pom.xml`.
221···254}
255```
256257+### MANIFEST file via Maven Plugin {#manifest-file-via-maven-plugin}
258259> This is ideal if you are the project owner and want to change your `pom.xml` to set the CLASSPATH within it.
260261Augment the `pom.xml` to create a JAR with the following manifest:
262+263```xml
264<build>
265 <plugins>
+64-57
doc/languages-frameworks/python.section.md
···1# Python {#python}
23-## User Guide
45-### Using Python
67-#### Overview
89Several versions of the Python interpreter are available on Nix, as well as a
10high amount of packages. The attribute `python3` refers to the default
···31`pythonPackages` refers to `python.pkgs` and `python38Packages` to
32`python38.pkgs`.
3334-#### Installing Python and packages
3536The Nix and NixOS manuals explain how packages are generally installed. In the
37case of Python and Nix, it is important to make a distinction between whether the
···62of development: individual projects create their own Python environments without
63impacting the global environment or each other.
6465-#### Ad-hoc temporary Python environment with `nix-shell`
6667The simplest way to start playing with the way nix wraps and sets up Python
68environments is with `nix-shell` at the cmdline. These environments create a
···131interpreter and dependencies work in Nix and NixOS, but to do some actual
132development, we'll want to make it a bit more persistent.
133134-##### Running Python scripts and using `nix-shell` as shebang
135136Sometimes, we have a script whose header looks like this:
137···146Executing this script requires a `python3` that has `numpy`. Using what we learned
147in the previous section, we could startup a shell and just run it like so:
148149-```ShellSesssion
150$ nix-shell -p 'python38.withPackages(ps: with ps; [ numpy ])' --run 'python3 foo.py'
151The dot product of [1 2] and [3 4] is: 11
152```
···203This is also a great way to ensure the script executes identically on different
204servers.
205206-##### Load environment from `.nix` expression
207208We've now seen how to create an ad-hoc temporary shell session, and how to
209create a single script with Python dependencies, but in the course of normal
···262like `libffi` the `openssl` in scope. This is generic and can span any number of
263tools or languages across the Nixpkgs ecosystem.
264265-##### Installing environments globally on the system
266267Up to now, we've been creating environments scoped to an ad-hoc shell session,
268or a single script, or a single project. This is generally advisable, as it
···315atomically *uninstall* all other imperatively installed packages and replace
316your profile with just `myEnv` by using the `--replace` flag.
317318-##### Environment defined in `/etc/nixos/configuration.nix`
319320For the sake of completeness, here's how to install the environment system-wide
321on NixOS.
···329}
330```
331332-### Developing with Python
333334Above, we were mostly just focused on use cases and what to do to get started
335creating working Python environments in nix.
···338back and take a deeper look at how Python packages are packaged on Nix. Then,
339we will look at how you can use development mode with your code.
340341-#### Python library packages in Nixpkgs
342343With Nix all packages are built by functions. The main function in Nix for
344building Python libraries is `buildPythonPackage`. Let's see how we can build the
···425`toolz` from the Nixpkgs package set this time, but instead took our own version
426that we introduced with the `let` expression.
427428-#### Handling dependencies
429430Our example, `toolz`, does not have any dependencies on other Python packages or
431system libraries. According to the manual, `buildPythonPackage` uses the
···537 };
538}
539```
0540Note also the line `doCheck = false;`, we explicitly disabled running the test-suite.
541542-#### Testing Python Packages
543544It is highly encouraged to have testing as part of the package build. This
545helps to avoid situations where the package was able to build and install,
···559as many tests should be enabled as possible. Failing tests can still be
560a good indication that the package is not in a valid state.
561562-#### Using pytest
563564Pytest is the most common test runner for python repositories. A trivial
565test run would be:
0566```
567 checkInputs = [ pytest ];
568 checkPhase = "pytest";
···572sandbox, and will generally need many tests to be disabled.
573574To filter tests using pytest, one can do the following:
0575```
576 checkInputs = [ pytest ];
577 # avoid tests which need additional data or touch network
···587588`-k` is used to define a predicate for test names. In this example, we are
589filtering out tests which contain `download` or `update` in their test case name.
590-Only one `-k` argument is allows, and thus a long predicate should be concatenated
591-with "\" and wrapped to the next line.
592593-*NOTE:* In pytest==6.0.1, the use of "\" to continue a line (e.g. `-k 'not download \'`) has
594been removed, in this case, it's recommended to use `pytestCheckHook`.
595596-#### Using pytestCheckHook
597598`pytestCheckHook` is a convenient hook which will substitute the setuptools
599`test` command for a checkPhase which runs `pytest`. This is also beneficial
600when a package may need many items disabled to run the test suite.
601602Using the example above, the analagous pytestCheckHook usage would be:
0603```
604 checkInputs = [ pytestCheckHook ];
605···637would be much harder to read. This also enables us to comment on why specific tests
638are disabled.
639640-#### Using pythonImportsCheck
641642Although unit tests are highly prefered to validate correctness of a package, not
643all packages have test suites that can be ran easily, and some have none at all.
···659This can also be useful in verifying that the package doesn't assume commonly
660present packages (e.g. `setuptools`)
661662-### Develop local package
663664As a Python developer you're likely aware of [development mode](http://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode)
665(`python setup.py develop`); instead of installing the package this command
···694It is important to note that due to how development mode is implemented on Nix
695it is not possible to have multiple packages simultaneously in development mode.
696697-### Organising your packages
698699So far we discussed how you can use Python on Nix, and how you can develop with
700it. We've looked at how you write expressions to package Python packages, and we
···706duplication we now look at how you can maintain a repository with your
707own packages. The important functions here are `import` and `callPackage`.
708709-### Including a derivation using `callPackage`
710711Earlier we created a Python environment using `withPackages`, and included the
712`toolz` package via a `let` expression.
···756example we use `buildPythonPackage` that is part of the set `python38Packages`,
757and in this case the `python38` interpreter is automatically used.
758759-## Reference
760761-### Interpreters
762763Versions 2.7, 3.6, 3.7, 3.8 and 3.9 of the CPython interpreter are available as
764respectively `python27`, `python36`, `python37`, `python38` and `python39`. The
···773`out/{python.sitePackages}` to `$PYTHONPATH` if such directory
774exists.
775776-#### Missing `tkinter` module standard library
777778To reduce closure size the `Tkinter`/`tkinter` is available as a separate package, `pythonPackages.tkinter`.
779780-#### Attributes on interpreters packages
781782Each interpreter has the following attributes:
783···789- `executable`. Name of the interpreter executable, e.g. `python3.8`.
790- `pkgs`. Set of Python packages for that specific interpreter. The package set can be modified by overriding the interpreter and passing `packageOverrides`.
791792-### Optimizations
793794The Python interpreters are by default not build with optimizations enabled, because
795the builds are in that case not reproducible. To enable optimizations, override the
···806in mypython
807```
808809-### Building packages and applications
810811Python libraries and applications that use `setuptools` or
812`distutils` are typically built with respectively the `buildPythonPackage` and
···838* `pkgs.python3Packages` pointing to `pkgs.python38Packages`
839* `pkgs.pythonPackages` pointing to `pkgs.python2Packages`
840841-#### `buildPythonPackage` function
842843The `buildPythonPackage` function is implemented in
844`pkgs/development/interpreters/python/mk-python-derivation`
···890By default `meta.platforms` is set to the same value
891as the interpreter unless overridden otherwise.
892893-##### `buildPythonPackage` parameters
894895All parameters from `stdenv.mkDerivation` function are still supported. The
896following are specific to `buildPythonPackage`:
···946 `buildPythonPackage` also injects code into and wraps executables with the
947 paths included in this list. Items listed in `install_requires` go here.
948949-##### Overriding Python packages
950951The `buildPythonPackage` function has a `overridePythonAttrs` method that can be
952used to override the package. In the following example we create an environment
···974in python.withPackages(ps: [ps.blaze])).env
975```
976977-#### `buildPythonApplication` function
978979The `buildPythonApplication` function is practically the same as
980`buildPythonPackage`. The main purpose of this function is to build a Python
···1019Since the package is an application, a consumer doesn't need to care about
1020Python versions or modules, which is why they don't go in `pythonPackages`.
10211022-#### `toPythonApplication` function
10231024A distinction is made between applications and libraries, however, sometimes a
1025package is used as both. In this case the package is added as a library to
···1031`python-packages.nix`. A reference shall be created from `all-packages.nix` to
1032the attribute in `python-packages.nix`, and the `toPythonApplication` shall be
1033applied to the reference:
01034```nix
1035youtube-dl = with pythonPackages; toPythonApplication youtube-dl;
1036```
10371038-#### `toPythonModule` function
10391040In some cases, such as bindings, a package is created using
1041`stdenv.mkDerivation` and added as attribute in `all-packages.nix`. The Python
···10521053Do pay attention to passing in the right Python version!
10541055-#### `python.buildEnv` function
10561057Python environments can be created using the low-level `pkgs.buildEnv` function.
1058This example shows how to create an environment that has the Pyramid Web Framework.
···1090will drop you into a shell where Python will have the
1091specified packages in its path.
1092010931094-##### `python.buildEnv` arguments
10951096* `extraLibs`: List of packages installed inside the environment.
1097* `postBuild`: Shell command executed after the build of environment.
···1099* `permitUserSite`: Skip setting the `PYTHONNOUSERSITE` environment variable in
1100 wrapped binaries in the environment.
11011102-#### `python.withPackages` function
11031104The `python.withPackages` function provides a simpler interface to the `python.buildEnv` functionality.
1105It takes a function as an argument that is passed the set of python packages and returns the list
···1141Python 2 namespace packages may provide `__init__.py` that collide. In that case
1142`python.buildEnv` should be used with `ignoreCollisions = true`.
11431144-#### Setup hooks
11451146The following are setup hooks specifically for Python packages. Most of these
1147are used in `buildPythonPackage`.
···1166- `wheelUnpackHook` to move a wheel to the correct folder so it can be installed
1167 with the `pipInstallHook`.
11681169-### Development mode
11701171Development or editable mode is supported. To develop Python packages
1172`buildPythonPackage` has additional logic inside `shellPhase` to run `pip
···1175Warning: `shellPhase` is executed only if `setup.py` exists.
11761177Given a `default.nix`:
01178```nix
1179with import <nixpkgs> {};
1180···11971198Note: There is a boolean value `lib.inNixShell` set to `true` if nix-shell is invoked.
11991200-### Tools
12011202Packages inside nixpkgs are written by hand. However many tools exist in
1203community to help save time. No tool is preferred at the moment.
···1209- [nixpkgs-pytools](https://github.com/nix-community/nixpkgs-pytools)
1210- [poetry2nix](https://github.com/nix-community/poetry2nix)
12111212-### Deterministic builds
12131214The Python interpreters are now built deterministically. Minor modifications had
1215to be made to the interpreters in order to generate deterministic bytecode. This
···1221and [PYTHONHASHSEED=0](https://docs.python.org/3.8/using/cmdline.html#envvar-PYTHONHASHSEED).
1222Both are also exported in `nix-shell`.
12231224-### Automatic tests
12251226It is recommended to test packages as part of the build process.
1227Source distributions (`sdist`) often include test files, but not always.
···1230`checkPhase`, but often it is necessary to pass a custom `checkPhase`. An
1231example of such a situation is when `py.test` is used.
12321233-#### Common issues
12341235* Non-working tests can often be deselected. By default `buildPythonPackage`
1236 runs `python setup.py test`. Most Python modules follows the standard test
···1247 '';
1248 }
1249 ```
01250* Tests that attempt to access `$HOME` can be fixed by using the following
1251 work-around before running tests (e.g. `preCheck`): `export HOME=$(mktemp -d)`
12521253-## FAQ
12541255-### How to solve circular dependencies?
12561257Consider the packages `A` and `B` that depend on each other. When packaging `B`,
1258a solution is to override package `A` not to depend on `B` as an input. The same
1259should also be done when packaging `A`.
12601261-### How to override a Python package?
12621263We can override the interpreter and pass `packageOverrides`. In the following
1264example we rename the `pandas` package and build it.
···1316in newpkgs.inkscape
1317```
13181319-### `python setup.py bdist_wheel` cannot create .whl
13201321Executing `python setup.py bdist_wheel` in a `nix-shell `fails with
1322```
···1349nix-shell --run "unset SOURCE_DATE_EPOCH; python3 setup.py bdist_wheel"
1350```
13511352-### `install_data` / `data_files` problems
13531354If you get the following error:
1355···1369sed -i '/ = data\_files/d' setup.py
1370```
13711372-### Rationale of non-existent global site-packages
13731374On most operating systems a global `site-packages` is maintained. This however
1375becomes problematic if you want to run multiple Python versions or have multiple
···1384method is to use `nix-shell`, either with or without the `python.buildEnv`
1385function.
13861387-### How to consume Python modules using pip in a virtual environment like I am used to on other Operating Systems?
13881389While this approach is not very idiomatic from Nix perspective, it can still be
1390useful when dealing with pre-existing projects or in situations where it's not
···1497requirements.txt. However these will be cached locally within the `virtualenv`
1498folder and not downloaded again.
14991500-### How to override a Python package from `configuration.nix`?
15011502If you need to change a package's attribute(s) from `configuration.nix` you could do:
1503···1535 }
1536```
15371538-### How to override a Python package using overlays?
15391540Use the following overlay template:
1541···1556}
1557```
15581559-### How to use Intel's MKL with numpy and scipy?
15601561MKL can be configured using an overlay. See the section "[Using overlays to
1562configure alternatives](#sec-overlays-alternatives-blas-lapack)".
15631564-### What inputs do `setup_requires`, `install_requires` and `tests_require` map to?
15651566In a `setup.py` or `setup.cfg` it is common to declare dependencies:
1567···1569* `install_requires` corresponds to `propagatedBuildInputs`
1570* `tests_require` corresponds to `checkInputs`
15711572-## Contributing
15731574-### Contributing guidelines
15751576The following rules are desired to be respected:
1577
···1# Python {#python}
23+## User Guide {#user-guide}
45+### Using Python {#using-python}
67+#### Overview {#overview}
89Several versions of the Python interpreter are available on Nix, as well as a
10high amount of packages. The attribute `python3` refers to the default
···31`pythonPackages` refers to `python.pkgs` and `python38Packages` to
32`python38.pkgs`.
3334+#### Installing Python and packages {#installing-python-and-packages}
3536The Nix and NixOS manuals explain how packages are generally installed. In the
37case of Python and Nix, it is important to make a distinction between whether the
···62of development: individual projects create their own Python environments without
63impacting the global environment or each other.
6465+#### Ad-hoc temporary Python environment with `nix-shell` {#ad-hoc-temporary-python-environment-with-nix-shell}
6667The simplest way to start playing with the way nix wraps and sets up Python
68environments is with `nix-shell` at the cmdline. These environments create a
···131interpreter and dependencies work in Nix and NixOS, but to do some actual
132development, we'll want to make it a bit more persistent.
133134+##### Running Python scripts and using `nix-shell` as shebang {#running-python-scripts-and-using-nix-shell-as-shebang}
135136Sometimes, we have a script whose header looks like this:
137···146Executing this script requires a `python3` that has `numpy`. Using what we learned
147in the previous section, we could startup a shell and just run it like so:
148149+```ShellSession
150$ nix-shell -p 'python38.withPackages(ps: with ps; [ numpy ])' --run 'python3 foo.py'
151The dot product of [1 2] and [3 4] is: 11
152```
···203This is also a great way to ensure the script executes identically on different
204servers.
205206+##### Load environment from `.nix` expression {#load-environment-from-.nix-expression}
207208We've now seen how to create an ad-hoc temporary shell session, and how to
209create a single script with Python dependencies, but in the course of normal
···262like `libffi` the `openssl` in scope. This is generic and can span any number of
263tools or languages across the Nixpkgs ecosystem.
264265+##### Installing environments globally on the system {#installing-environments-globally-on-the-system}
266267Up to now, we've been creating environments scoped to an ad-hoc shell session,
268or a single script, or a single project. This is generally advisable, as it
···315atomically *uninstall* all other imperatively installed packages and replace
316your profile with just `myEnv` by using the `--replace` flag.
317318+##### Environment defined in `/etc/nixos/configuration.nix` {#environment-defined-in-etcnixosconfiguration.nix}
319320For the sake of completeness, here's how to install the environment system-wide
321on NixOS.
···329}
330```
331332+### Developing with Python {#developing-with-python}
333334Above, we were mostly just focused on use cases and what to do to get started
335creating working Python environments in nix.
···338back and take a deeper look at how Python packages are packaged on Nix. Then,
339we will look at how you can use development mode with your code.
340341+#### Python library packages in Nixpkgs {#python-library-packages-in-nixpkgs}
342343With Nix all packages are built by functions. The main function in Nix for
344building Python libraries is `buildPythonPackage`. Let's see how we can build the
···425`toolz` from the Nixpkgs package set this time, but instead took our own version
426that we introduced with the `let` expression.
427428+#### Handling dependencies {#handling-dependencies}
429430Our example, `toolz`, does not have any dependencies on other Python packages or
431system libraries. According to the manual, `buildPythonPackage` uses the
···537 };
538}
539```
540+541Note also the line `doCheck = false;`, we explicitly disabled running the test-suite.
542543+#### Testing Python Packages {#testing-python-packages}
544545It is highly encouraged to have testing as part of the package build. This
546helps to avoid situations where the package was able to build and install,
···560as many tests should be enabled as possible. Failing tests can still be
561a good indication that the package is not in a valid state.
562563+#### Using pytest {#using-pytest}
564565Pytest is the most common test runner for python repositories. A trivial
566test run would be:
567+568```
569 checkInputs = [ pytest ];
570 checkPhase = "pytest";
···574sandbox, and will generally need many tests to be disabled.
575576To filter tests using pytest, one can do the following:
577+578```
579 checkInputs = [ pytest ];
580 # avoid tests which need additional data or touch network
···590591`-k` is used to define a predicate for test names. In this example, we are
592filtering out tests which contain `download` or `update` in their test case name.
593+Only one `-k` argument is allowed, and thus a long predicate should be concatenated
594+with “\\” and wrapped to the next line.
595596+*NOTE:* In pytest==6.0.1, the use of “\\” to continue a line (e.g. `-k 'not download \'`) has
597been removed, in this case, it's recommended to use `pytestCheckHook`.
598599+#### Using pytestCheckHook {#using-pytestcheckhook}
600601`pytestCheckHook` is a convenient hook which will substitute the setuptools
602`test` command for a checkPhase which runs `pytest`. This is also beneficial
603when a package may need many items disabled to run the test suite.
604605Using the example above, the analagous pytestCheckHook usage would be:
606+607```
608 checkInputs = [ pytestCheckHook ];
609···641would be much harder to read. This also enables us to comment on why specific tests
642are disabled.
643644+#### Using pythonImportsCheck {#using-pythonimportscheck}
645646Although unit tests are highly prefered to validate correctness of a package, not
647all packages have test suites that can be ran easily, and some have none at all.
···663This can also be useful in verifying that the package doesn't assume commonly
664present packages (e.g. `setuptools`)
665666+### Develop local package {#develop-local-package}
667668As a Python developer you're likely aware of [development mode](http://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode)
669(`python setup.py develop`); instead of installing the package this command
···698It is important to note that due to how development mode is implemented on Nix
699it is not possible to have multiple packages simultaneously in development mode.
700701+### Organising your packages {#organising-your-packages}
702703So far we discussed how you can use Python on Nix, and how you can develop with
704it. We've looked at how you write expressions to package Python packages, and we
···710duplication we now look at how you can maintain a repository with your
711own packages. The important functions here are `import` and `callPackage`.
712713+### Including a derivation using `callPackage` {#including-a-derivation-using-callpackage}
714715Earlier we created a Python environment using `withPackages`, and included the
716`toolz` package via a `let` expression.
···760example we use `buildPythonPackage` that is part of the set `python38Packages`,
761and in this case the `python38` interpreter is automatically used.
762763+## Reference {#reference}
764765+### Interpreters {#interpreters}
766767Versions 2.7, 3.6, 3.7, 3.8 and 3.9 of the CPython interpreter are available as
768respectively `python27`, `python36`, `python37`, `python38` and `python39`. The
···777`out/{python.sitePackages}` to `$PYTHONPATH` if such directory
778exists.
779780+#### Missing `tkinter` module standard library {#missing-tkinter-module-standard-library}
781782To reduce closure size the `Tkinter`/`tkinter` is available as a separate package, `pythonPackages.tkinter`.
783784+#### Attributes on interpreters packages {#attributes-on-interpreters-packages}
785786Each interpreter has the following attributes:
787···793- `executable`. Name of the interpreter executable, e.g. `python3.8`.
794- `pkgs`. Set of Python packages for that specific interpreter. The package set can be modified by overriding the interpreter and passing `packageOverrides`.
795796+### Optimizations {#optimizations}
797798The Python interpreters are by default not build with optimizations enabled, because
799the builds are in that case not reproducible. To enable optimizations, override the
···810in mypython
811```
812813+### Building packages and applications {#building-packages-and-applications}
814815Python libraries and applications that use `setuptools` or
816`distutils` are typically built with respectively the `buildPythonPackage` and
···842* `pkgs.python3Packages` pointing to `pkgs.python38Packages`
843* `pkgs.pythonPackages` pointing to `pkgs.python2Packages`
844845+#### `buildPythonPackage` function {#buildpythonpackage-function}
846847The `buildPythonPackage` function is implemented in
848`pkgs/development/interpreters/python/mk-python-derivation`
···894By default `meta.platforms` is set to the same value
895as the interpreter unless overridden otherwise.
896897+##### `buildPythonPackage` parameters {#buildpythonpackage-parameters}
898899All parameters from `stdenv.mkDerivation` function are still supported. The
900following are specific to `buildPythonPackage`:
···950 `buildPythonPackage` also injects code into and wraps executables with the
951 paths included in this list. Items listed in `install_requires` go here.
952953+##### Overriding Python packages {#overriding-python-packages}
954955The `buildPythonPackage` function has a `overridePythonAttrs` method that can be
956used to override the package. In the following example we create an environment
···978in python.withPackages(ps: [ps.blaze])).env
979```
980981+#### `buildPythonApplication` function {#buildpythonapplication-function}
982983The `buildPythonApplication` function is practically the same as
984`buildPythonPackage`. The main purpose of this function is to build a Python
···1023Since the package is an application, a consumer doesn't need to care about
1024Python versions or modules, which is why they don't go in `pythonPackages`.
10251026+#### `toPythonApplication` function {#topythonapplication-function}
10271028A distinction is made between applications and libraries, however, sometimes a
1029package is used as both. In this case the package is added as a library to
···1035`python-packages.nix`. A reference shall be created from `all-packages.nix` to
1036the attribute in `python-packages.nix`, and the `toPythonApplication` shall be
1037applied to the reference:
1038+1039```nix
1040youtube-dl = with pythonPackages; toPythonApplication youtube-dl;
1041```
10421043+#### `toPythonModule` function {#topythonmodule-function}
10441045In some cases, such as bindings, a package is created using
1046`stdenv.mkDerivation` and added as attribute in `all-packages.nix`. The Python
···10571058Do pay attention to passing in the right Python version!
10591060+#### `python.buildEnv` function {#python.buildenv-function}
10611062Python environments can be created using the low-level `pkgs.buildEnv` function.
1063This example shows how to create an environment that has the Pyramid Web Framework.
···1095will drop you into a shell where Python will have the
1096specified packages in its path.
10971098+##### `python.buildEnv` arguments {#python.buildenv-arguments}
1099011001101* `extraLibs`: List of packages installed inside the environment.
1102* `postBuild`: Shell command executed after the build of environment.
···1104* `permitUserSite`: Skip setting the `PYTHONNOUSERSITE` environment variable in
1105 wrapped binaries in the environment.
11061107+#### `python.withPackages` function {#python.withpackages-function}
11081109The `python.withPackages` function provides a simpler interface to the `python.buildEnv` functionality.
1110It takes a function as an argument that is passed the set of python packages and returns the list
···1146Python 2 namespace packages may provide `__init__.py` that collide. In that case
1147`python.buildEnv` should be used with `ignoreCollisions = true`.
11481149+#### Setup hooks {#setup-hooks}
11501151The following are setup hooks specifically for Python packages. Most of these
1152are used in `buildPythonPackage`.
···1171- `wheelUnpackHook` to move a wheel to the correct folder so it can be installed
1172 with the `pipInstallHook`.
11731174+### Development mode {#development-mode}
11751176Development or editable mode is supported. To develop Python packages
1177`buildPythonPackage` has additional logic inside `shellPhase` to run `pip
···1180Warning: `shellPhase` is executed only if `setup.py` exists.
11811182Given a `default.nix`:
1183+1184```nix
1185with import <nixpkgs> {};
1186···12031204Note: There is a boolean value `lib.inNixShell` set to `true` if nix-shell is invoked.
12051206+### Tools {#tools}
12071208Packages inside nixpkgs are written by hand. However many tools exist in
1209community to help save time. No tool is preferred at the moment.
···1215- [nixpkgs-pytools](https://github.com/nix-community/nixpkgs-pytools)
1216- [poetry2nix](https://github.com/nix-community/poetry2nix)
12171218+### Deterministic builds {#deterministic-builds}
12191220The Python interpreters are now built deterministically. Minor modifications had
1221to be made to the interpreters in order to generate deterministic bytecode. This
···1227and [PYTHONHASHSEED=0](https://docs.python.org/3.8/using/cmdline.html#envvar-PYTHONHASHSEED).
1228Both are also exported in `nix-shell`.
12291230+### Automatic tests {#automatic-tests}
12311232It is recommended to test packages as part of the build process.
1233Source distributions (`sdist`) often include test files, but not always.
···1236`checkPhase`, but often it is necessary to pass a custom `checkPhase`. An
1237example of such a situation is when `py.test` is used.
12381239+#### Common issues {#common-issues}
12401241* Non-working tests can often be deselected. By default `buildPythonPackage`
1242 runs `python setup.py test`. Most Python modules follows the standard test
···1253 '';
1254 }
1255 ```
1256+1257* Tests that attempt to access `$HOME` can be fixed by using the following
1258 work-around before running tests (e.g. `preCheck`): `export HOME=$(mktemp -d)`
12591260+## FAQ {#faq}
12611262+### How to solve circular dependencies? {#how-to-solve-circular-dependencies}
12631264Consider the packages `A` and `B` that depend on each other. When packaging `B`,
1265a solution is to override package `A` not to depend on `B` as an input. The same
1266should also be done when packaging `A`.
12671268+### How to override a Python package? {#how-to-override-a-python-package}
12691270We can override the interpreter and pass `packageOverrides`. In the following
1271example we rename the `pandas` package and build it.
···1323in newpkgs.inkscape
1324```
13251326+### `python setup.py bdist_wheel` cannot create .whl {#python-setup.py-bdist_wheel-cannot-create-.whl}
13271328Executing `python setup.py bdist_wheel` in a `nix-shell `fails with
1329```
···1356nix-shell --run "unset SOURCE_DATE_EPOCH; python3 setup.py bdist_wheel"
1357```
13581359+### `install_data` / `data_files` problems {#install_data-data_files-problems}
13601361If you get the following error:
1362···1376sed -i '/ = data\_files/d' setup.py
1377```
13781379+### Rationale of non-existent global site-packages {#rationale-of-non-existent-global-site-packages}
13801381On most operating systems a global `site-packages` is maintained. This however
1382becomes problematic if you want to run multiple Python versions or have multiple
···1391method is to use `nix-shell`, either with or without the `python.buildEnv`
1392function.
13931394+### How to consume Python modules using pip in a virtual environment like I am used to on other Operating Systems? {#how-to-consume-python-modules-using-pip-in-a-virtual-environment-like-i-am-used-to-on-other-operating-systems}
13951396While this approach is not very idiomatic from Nix perspective, it can still be
1397useful when dealing with pre-existing projects or in situations where it's not
···1504requirements.txt. However these will be cached locally within the `virtualenv`
1505folder and not downloaded again.
15061507+### How to override a Python package from `configuration.nix`? {#how-to-override-a-python-package-from-configuration.nix}
15081509If you need to change a package's attribute(s) from `configuration.nix` you could do:
1510···1542 }
1543```
15441545+### How to override a Python package using overlays? {#how-to-override-a-python-package-using-overlays}
15461547Use the following overlay template:
1548···1563}
1564```
15651566+### How to use Intel’s MKL with numpy and scipy? {#how-to-use-intels-mkl-with-numpy-and-scipy}
15671568MKL can be configured using an overlay. See the section "[Using overlays to
1569configure alternatives](#sec-overlays-alternatives-blas-lapack)".
15701571+### What inputs do `setup_requires`, `install_requires` and `tests_require` map to? {#what-inputs-do-setup_requires-install_requires-and-tests_require-map-to}
15721573In a `setup.py` or `setup.cfg` it is common to declare dependencies:
1574···1576* `install_requires` corresponds to `propagatedBuildInputs`
1577* `tests_require` corresponds to `checkInputs`
15781579+## Contributing {#contributing}
15801581+### Contributing guidelines {#contributing-guidelines}
15821583The following rules are desired to be respected:
1584
+8-3
doc/languages-frameworks/qt.section.md
···90}
91```
9293-::: note
94`wrapQtAppsHook` ignores files that are non-ELF executables.
95This means that scripts won't be automatically wrapped so you'll need to manually wrap them as previously mentioned.
96An example of when you'd always need to do this is with Python applications that use PyQt.
97:::
9899-## Adding a library to Nixpkgs
0100Add Qt libraries to `qt5-packages.nix` to make them available for every
101supported Qt version.
102103### Example adding a Qt library {#qt-library-all-packages-nix}
104105The following represents the contents of `qt5-packages.nix`.
0106```nix
107{
108 # ...
···126}
127```
128129-## Adding an application to Nixpkgs
0130Add Qt applications to `qt5-packages.nix`. Add an alias to `all-packages.nix`
131to select the Qt 5 version used for the application.
132133### Example adding a Qt application {#qt-application-all-packages-nix}
134135The following represents the contents of `qt5-packages.nix`.
0136```nix
137{
138 # ...
···144```
145146The following represents the contents of `all-packages.nix`.
0147```nix
148{
149 # ...
···90}
91```
9293+::: {.note}
94`wrapQtAppsHook` ignores files that are non-ELF executables.
95This means that scripts won't be automatically wrapped so you'll need to manually wrap them as previously mentioned.
96An example of when you'd always need to do this is with Python applications that use PyQt.
97:::
9899+## Adding a library to Nixpkgs {#adding-a-library-to-nixpkgs}
100+101Add Qt libraries to `qt5-packages.nix` to make them available for every
102supported Qt version.
103104### Example adding a Qt library {#qt-library-all-packages-nix}
105106The following represents the contents of `qt5-packages.nix`.
107+108```nix
109{
110 # ...
···128}
129```
130131+## Adding an application to Nixpkgs {#adding-an-application-to-nixpkgs}
132+133Add Qt applications to `qt5-packages.nix`. Add an alias to `all-packages.nix`
134to select the Qt 5 version used for the application.
135136### Example adding a Qt application {#qt-application-all-packages-nix}
137138The following represents the contents of `qt5-packages.nix`.
139+140```nix
141{
142 # ...
···148```
149150The following represents the contents of `all-packages.nix`.
151+152```nix
153{
154 # ...
+5-5
doc/languages-frameworks/r.section.md
···1# R {#r}
23-## Installation
45Define an environment for R that contains all the libraries that you'd like to
6use by adding the following snippet to your $HOME/.config/nixpkgs/config.nix file:
···31However, if you'd like to add a file to your project source to make the
32environment available for other contributors, you can create a `default.nix`
33file like so:
034```nix
35with import <nixpkgs> {};
36{
···50and then run `nix-shell .` to be dropped into a shell with those packages
51available.
5253-## RStudio
5455RStudio uses a standard set of packages and ignores any custom R
56environments or installed packages you may have. To create a custom
···93one above. If you need additional packages just add them to the list and
94re-enter the shell.
9596-## Updating the package set
9798```bash
99nix-shell generate-shell.nix
···113114`generate-r-packages.R <repo>` reads `<repo>-packages.nix`, therefor the renaming.
115116-117-## Testing if the Nix-expression could be evaluated
118119```bash
120nix-build test-evaluation.nix --dry-run
···1# R {#r}
23+## Installation {#installation}
45Define an environment for R that contains all the libraries that you'd like to
6use by adding the following snippet to your $HOME/.config/nixpkgs/config.nix file:
···31However, if you'd like to add a file to your project source to make the
32environment available for other contributors, you can create a `default.nix`
33file like so:
34+35```nix
36with import <nixpkgs> {};
37{
···51and then run `nix-shell .` to be dropped into a shell with those packages
52available.
5354+## RStudio {#rstudio}
5556RStudio uses a standard set of packages and ignores any custom R
57environments or installed packages you may have. To create a custom
···94one above. If you need additional packages just add them to the list and
95re-enter the shell.
9697+## Updating the package set {#updating-the-package-set}
9899```bash
100nix-shell generate-shell.nix
···114115`generate-r-packages.R <repo>` reads `<repo>-packages.nix`, therefor the renaming.
116117+## Testing if the Nix-expression could be evaluated {#testing-if-the-nix-expression-could-be-evaluated}
0118119```bash
120nix-build test-evaluation.nix --dry-run
+11-11
doc/languages-frameworks/ruby.section.md
···1# Ruby {#sec-language-ruby}
23-## Using Ruby
45Several versions of Ruby interpreters are available on Nix, as well as over 250 gems and many applications written in Ruby. The attribute `ruby` refers to the default Ruby interpreter, which is currently MRI 2.6. It's also possible to refer to specific versions, e.g. `ruby_2_y`, `jruby`, or `mruby`.
6···1213Since not all gems have executables like `nokogiri`, it's usually more convenient to use the `withPackages` function like this: `ruby.withPackages (p: with p; [ nokogiri ])`. This will also make sure that the Ruby in your environment will be able to find the gem and it can be used in your Ruby code (for example via `ruby` or `irb` executables) via `require "nokogiri"` as usual.
1415-### Temporary Ruby environment with `nix-shell`
1617Rather than having a single Ruby environment shared by all Ruby development projects on a system, Nix allows you to create separate environments per project. `nix-shell` gives you the possibility to temporarily load another environment akin to a combined `chruby` or `rvm` and `bundle exec`.
18···3031Again, it's possible to launch the interpreter from the shell. The Ruby interpreter has the attribute `gems` which contains all Ruby gems for that specific interpreter.
3233-#### Load Ruby environment from `.nix` expression
3435As explained in the Nix manual, `nix-shell` can also load an expression from a `.nix` file. Say we want to have Ruby 2.6, `nokogori`, and `pry`. Consider a `shell.nix` file with:
36···452. Then we create a Ruby environment with the `withPackages` function.
463. The `withPackages` function expects us to provide a function as an argument that takes the set of all ruby gems and returns a list of packages to include in the environment. Here, we select the packages `nokogiri` and `pry` from the package set.
4748-#### Execute command with `--run`
4950A convenient flag for `nix-shell` is `--run`. It executes a command in the `nix-shell`. We can e.g. directly open a `pry` REPL:
51···65$ nix-shell -p "ruby.withPackages (ps: with ps; [ nokogiri pry ])" --run "ruby example.rb"
66```
6768-#### Using `nix-shell` as shebang
6970In fact, for the last case, there is a more convenient method. You can add a [shebang](<https://en.wikipedia.org/wiki/Shebang_(Unix)>) to your script specifying which dependencies `nix-shell` needs. With the following shebang, you can just execute `./example.rb`, and it will run with all dependencies.
71···80puts Nokogiri::HTML(body).at('h1').text
81```
8283-## Developing with Ruby
8485-### Using an existing Gemfile
8687In most cases, you'll already have a `Gemfile.lock` listing all your dependencies. This can be used to generate a `gemset.nix` which is used to fetch the gems and combine them into a single environment. The reason why you need to have a separate file for this, is that Nix requires you to have a checksum for each input to your build. Since the `Gemfile.lock` that `bundler` generates doesn't provide us with checksums, we have to first download each gem, calculate its SHA256, and store it in this separate file.
88···120mkShell { buildInputs = [ gems (lowPrio gems.wrappedRuby) ]; }
121```
122123-### Gem-specific configurations and workarounds
124125In some cases, especially if the gem has native extensions, you might need to modify the way the gem is built.
126···201202Of course for this use-case one could also use overlays since the configuration for `pg` depends on the `postgresql` alias, but for demonstration purposes this has to suffice.
203204-### Adding a gem to the default gemset
205206Now that you know how to get a working Ruby environment with Nix, it's time to go forward and start actually developing with Ruby. We will first have a look at how Ruby gems are packaged on Nix. Then, we will look at how you can use development mode with your code.
207···215NIX_PATH=nixpkgs=$PWD nix-shell -p "ruby.withPackages (ps: with ps; [ name-of-your-gem ])"
216```
217218-### Packaging applications
219220A common task is to add a ruby executable to nixpkgs, popular examples would be `chef`, `jekyll`, or `sass`. A good way to do that is to use the `bundlerApp` function, that allows you to make a package that only exposes the listed executables, otherwise the package may cause conflicts through common paths like `bin/rake` or `bin/bundler` that aren't meant to be used.
221···243244All that's left to do is to generate the corresponding `Gemfile.lock` and `gemset.nix` as described above in the `Using an existing Gemfile` section.
245246-#### Packaging executables that require wrapping
247248Sometimes your app will depend on other executables at runtime, and tries to find it through the `PATH` environment variable.
249
···1# Ruby {#sec-language-ruby}
23+## Using Ruby {#using-ruby}
45Several versions of Ruby interpreters are available on Nix, as well as over 250 gems and many applications written in Ruby. The attribute `ruby` refers to the default Ruby interpreter, which is currently MRI 2.6. It's also possible to refer to specific versions, e.g. `ruby_2_y`, `jruby`, or `mruby`.
6···1213Since not all gems have executables like `nokogiri`, it's usually more convenient to use the `withPackages` function like this: `ruby.withPackages (p: with p; [ nokogiri ])`. This will also make sure that the Ruby in your environment will be able to find the gem and it can be used in your Ruby code (for example via `ruby` or `irb` executables) via `require "nokogiri"` as usual.
1415+### Temporary Ruby environment with `nix-shell` {#temporary-ruby-environment-with-nix-shell}
1617Rather than having a single Ruby environment shared by all Ruby development projects on a system, Nix allows you to create separate environments per project. `nix-shell` gives you the possibility to temporarily load another environment akin to a combined `chruby` or `rvm` and `bundle exec`.
18···3031Again, it's possible to launch the interpreter from the shell. The Ruby interpreter has the attribute `gems` which contains all Ruby gems for that specific interpreter.
3233+#### Load Ruby environment from `.nix` expression {#load-ruby-environment-from-.nix-expression}
3435As explained in the Nix manual, `nix-shell` can also load an expression from a `.nix` file. Say we want to have Ruby 2.6, `nokogori`, and `pry`. Consider a `shell.nix` file with:
36···452. Then we create a Ruby environment with the `withPackages` function.
463. The `withPackages` function expects us to provide a function as an argument that takes the set of all ruby gems and returns a list of packages to include in the environment. Here, we select the packages `nokogiri` and `pry` from the package set.
4748+#### Execute command with `--run` {#execute-command-with---run}
4950A convenient flag for `nix-shell` is `--run`. It executes a command in the `nix-shell`. We can e.g. directly open a `pry` REPL:
51···65$ nix-shell -p "ruby.withPackages (ps: with ps; [ nokogiri pry ])" --run "ruby example.rb"
66```
6768+#### Using `nix-shell` as shebang {#using-nix-shell-as-shebang}
6970In fact, for the last case, there is a more convenient method. You can add a [shebang](<https://en.wikipedia.org/wiki/Shebang_(Unix)>) to your script specifying which dependencies `nix-shell` needs. With the following shebang, you can just execute `./example.rb`, and it will run with all dependencies.
71···80puts Nokogiri::HTML(body).at('h1').text
81```
8283+## Developing with Ruby {#developing-with-ruby}
8485+### Using an existing Gemfile {#using-an-existing-gemfile}
8687In most cases, you'll already have a `Gemfile.lock` listing all your dependencies. This can be used to generate a `gemset.nix` which is used to fetch the gems and combine them into a single environment. The reason why you need to have a separate file for this, is that Nix requires you to have a checksum for each input to your build. Since the `Gemfile.lock` that `bundler` generates doesn't provide us with checksums, we have to first download each gem, calculate its SHA256, and store it in this separate file.
88···120mkShell { buildInputs = [ gems (lowPrio gems.wrappedRuby) ]; }
121```
122123+### Gem-specific configurations and workarounds {#gem-specific-configurations-and-workarounds}
124125In some cases, especially if the gem has native extensions, you might need to modify the way the gem is built.
126···201202Of course for this use-case one could also use overlays since the configuration for `pg` depends on the `postgresql` alias, but for demonstration purposes this has to suffice.
203204+### Adding a gem to the default gemset {#adding-a-gem-to-the-default-gemset}
205206Now that you know how to get a working Ruby environment with Nix, it's time to go forward and start actually developing with Ruby. We will first have a look at how Ruby gems are packaged on Nix. Then, we will look at how you can use development mode with your code.
207···215NIX_PATH=nixpkgs=$PWD nix-shell -p "ruby.withPackages (ps: with ps; [ name-of-your-gem ])"
216```
217218+### Packaging applications {#packaging-applications}
219220A common task is to add a ruby executable to nixpkgs, popular examples would be `chef`, `jekyll`, or `sass`. A good way to do that is to use the `bundlerApp` function, that allows you to make a package that only exposes the listed executables, otherwise the package may cause conflicts through common paths like `bin/rake` or `bin/bundler` that aren't meant to be used.
221···243244All that's left to do is to generate the corresponding `Gemfile.lock` and `gemset.nix` as described above in the `Using an existing Gemfile` section.
245246+#### Packaging executables that require wrapping {#packaging-executables-that-require-wrapping}
247248Sometimes your app will depend on other executables at runtime, and tries to find it through the `PATH` environment variable.
249
+59-43
doc/languages-frameworks/rust.section.md
···15use either `rustup` from nixpkgs (which will manage the rust installation in your home directory),
16or use Mozilla's [Rust nightlies overlay](#using-the-rust-nightlies-overlay).
1718-## Compiling Rust applications with Cargo
1920Rust applications are packaged by using the `buildRustPackage` helper from `rustPlatform`:
21···107}
108```
109110-### Importing a `Cargo.lock` file
111112Using `cargoSha256` or `cargoHash` is tedious when using
113`buildRustPackage` within a project, since it requires that the hash
···156`lib.fakeHash` as a stub hash. Building the package (and thus the
157vendored dependencies) will then inform you of the correct hash.
158159-### Cross compilation
160161By default, Rust packages are compiled for the host platform, just like any
162other package is. The `--target` passed to rust tools is computed from this.
···168 name will be used instead.
169170 For example:
0171 ```nix
172 import <nixpkgs> {
173 crossSystem = (import <nixpkgs/lib>).systems.examples.armhf-embedded // {
···175 };
176 }
177 ```
0178 will result in:
0179 ```shell
180 --target thumbv7em-none-eabi
181 ```
···188 will be used instead.
189190 For example:
0191 ```nix
192 import <nixpkgs> {
193 crossSystem = (import <nixpkgs/lib>).systems.examples.armhf-embedded // {
···196 };
197 }
198 ```
0199 will result in:
0200 ```shell
201 --target /nix/store/asdfasdfsadf-thumb-crazy.json # contains {"foo":"","bar":""}
202 ```
···220Note that currently custom targets aren't compiled with `std`, so `cargo test`
221will fail. This can be ignored by adding `doCheck = false;` to your derivation.
222223-### Running package tests
224225When using `buildRustPackage`, the `checkPhase` is enabled by default and runs
226`cargo test` on the package to build. To make sure that we don't compile the
···248binary itself, as stated
249(here)[https://doc.rust-lang.org/cargo/commands/cargo-test.html].
250251-#### Tests relying on the structure of the `target/` directory
252253Some tests may rely on the structure of the `target/` directory. Those tests
254are likely to fail because we use `cargo --target` during the build. This means that
···258259This can only be worked around by patching the affected tests accordingly.
260261-#### Disabling package-tests
262263In some instances, it may be necessary to disable testing altogether (with `doCheck = false;`):
264···272However, please check if it's possible to disable a problematic subset of the
273test suite and leave a comment explaining your reasoning.
274275-#### Setting `test-threads`
276277`buildRustPackage` will use parallel test threads by default,
278sometimes it may be necessary to disable this so the tests run consecutively.
···284}
285```
286287-### Building a package in `debug` mode
288289By default, `buildRustPackage` will use `release` mode for builds. If a package
290should be built in `debug` mode, it can be configured like so:
···298299In this scenario, the `checkPhase` will be ran in `debug` mode as well.
300301-### Custom `build`/`install`-procedures
302303Some packages may use custom scripts for building/installing, e.g. with a `Makefile`.
304In these cases, it's recommended to override the `buildPhase`/`installPhase`/`checkPhase`.
305306Otherwise, some steps may fail because of the modified directory structure of `target/`.
307308-### Building a crate with an absent or out-of-date Cargo.lock file
309310`buildRustPackage` needs a `Cargo.lock` file to get all dependencies in the
311source code in a reproducible way. If it is missing or out-of-date one can use
···321}
322```
323324-## Compiling non-Rust packages that include Rust code
325326Several non-Rust packages incorporate Rust code for performance- or
327security-sensitive parts. `rustPlatform` exposes several functions and
328hooks that can be used to integrate Cargo in non-Rust packages.
329330-### Vendoring of dependencies
331332Since network access is not allowed in sandboxed builds, Rust crate
333dependencies need to be retrieved using a fetcher. `rustPlatform`
···387`lib.fakeHash` as a stub hash. Building `cargoDeps` will then inform
388you of the correct hash.
389390-### Hooks
391392`rustPlatform` provides the following hooks to automate Cargo builds:
393···416* `cargoInstallHook`: install binaries and static/shared libraries
417 that were built using `cargoBuildHook`.
418419-### Examples
420421-#### Python package using `setuptools-rust`
422423For Python packages using `setuptools-rust`, you can use
424`fetchCargoTarball` and `cargoSetupHook` to retrieve and set up Cargo
···504}
505```
506507-#### Python package using `maturin`
508509Python packages that use [Maturin](https://github.com/PyO3/maturin)
510can be built with `fetchCargoTarball`, `cargoSetupHook`, and
···545}
546```
547548-## Compiling Rust crates using Nix instead of Cargo
549550-### Simple operation
551552When run, `cargo build` produces a file called `Cargo.lock`,
553containing pinned versions of all dependencies. Nixpkgs contains a
···558and can be used to compile a crate and all its dependencies. Here is
559an example for a minimal `hello` crate:
560561-562- $ cargo new hello
563- $ cd hello
564- $ cargo build
565 Compiling hello v0.1.0 (file:///tmp/hello)
566- Finished dev [unoptimized + debuginfo] target(s) in 0.20 secs
567- $ carnix -o hello.nix --src ./. Cargo.lock --standalone
568- $ nix-build hello.nix -A hello_0_1_0
0569570Now, the file produced by the call to `carnix`, called `hello.nix`, looks like:
571···644will fetch it from [crates.io](https://crates.io). A `sha256`
645attribute is still needed for Nix purity.
646647-### Handling external dependencies
648649Some crates require external libraries. For crates from
650[crates.io](https://crates.io), such libraries can be specified in
···703}
704```
705706-### Options and phases configuration
707708Actually, the overrides introduced in the previous section are more
709general. A number of other parameters can be overridden:
···750 };
751 ```
752753-### Features
754755One can also supply features switches. For example, if we want to
756compile `diesel_cli` only with the `postgres` feature, and no default
···765766Where `diesel.nix` is the file generated by Carnix, as explained above.
7670768769-## Setting Up `nix-shell`
770Oftentimes you want to develop code from within `nix-shell`. Unfortunately
771`buildRustCrate` does not support common `nix-shell` operations directly
772(see [this issue](https://github.com/NixOS/nixpkgs/issues/37945))
773so we will use `stdenv.mkDerivation` instead.
774775Using the example `hello` project above, we want to do the following:
0776- Have access to `cargo` and `rustc`
777- Have the `openssl` library available to a crate through it's _normal_
778 compilation mechanism (`pkg-config`).
···801```
802803You should now be able to run the following:
804-```ShellSesssion
0805$ nix-shell --pure
806$ cargo build
807$ cargo test
808```
809810-### Controlling Rust Version Inside `nix-shell`
0811To control your rust version (i.e. use nightly) from within `shell.nix` (or
812other nix expressions) you can use the following `shell.nix`
813···839```
840841Now run:
0842```ShellSession
843$ rustc --version
844rustc 1.26.0-nightly (188e693b3 2018-03-26)
···846847To see that you are using nightly.
848849-850-## Using the Rust nightlies overlay
851852Mozilla provides an overlay for nixpkgs to bring a nightly version of Rust into scope.
853This overlay can _also_ be used to install recent unstable or stable versions
854of Rust, if desired.
855856-### Rust overlay installation
857858You can use this overlay by either changing your local nixpkgs configuration,
859or by adding the overlay declaratively in a nix expression, e.g. in `configuration.nix`.
860-For more information see [#sec-overlays-install](the manual on installing overlays).
861862-#### Imperative rust overlay installation
863864Clone [nixpkgs-mozilla](https://github.com/mozilla/nixpkgs-mozilla),
865and create a symbolic link to the file
866[rust-overlay.nix](https://github.com/mozilla/nixpkgs-mozilla/blob/master/rust-overlay.nix)
867in the `~/.config/nixpkgs/overlays` directory.
868869- $ git clone https://github.com/mozilla/nixpkgs-mozilla.git
870- $ mkdir -p ~/.config/nixpkgs/overlays
871- $ ln -s $(pwd)/nixpkgs-mozilla/rust-overlay.nix ~/.config/nixpkgs/overlays/rust-overlay.nix
00872873-### Declarative rust overlay installation
874875Add the following to your `configuration.nix`, `home-configuration.nix`, `shell.nix`, or similar:
876···886887Note that this will fetch the latest overlay version when rebuilding your system.
888889-### Rust overlay usage
890891The overlay contains attribute sets corresponding to different versions of the rust toolchain, such as:
892···900901Imperatively, the latest stable version can be installed with the following command:
902903- $ nix-env -Ai nixpkgs.latest.rustChannels.stable.rust
00904905Or using the attribute with nix-shell:
906907- $ nix-shell -p nixpkgs.latest.rustChannels.stable.rust
00908909Substitute the `nixpkgs` prefix with `nixos` on NixOS.
910To install the beta or nightly channel, "stable" should be substituted by
···15use either `rustup` from nixpkgs (which will manage the rust installation in your home directory),
16or use Mozilla's [Rust nightlies overlay](#using-the-rust-nightlies-overlay).
1718+## Compiling Rust applications with Cargo {#compiling-rust-applications-with-cargo}
1920Rust applications are packaged by using the `buildRustPackage` helper from `rustPlatform`:
21···107}
108```
109110+### Importing a `Cargo.lock` file {#importing-a-cargo.lock-file}
111112Using `cargoSha256` or `cargoHash` is tedious when using
113`buildRustPackage` within a project, since it requires that the hash
···156`lib.fakeHash` as a stub hash. Building the package (and thus the
157vendored dependencies) will then inform you of the correct hash.
158159+### Cross compilation {#cross-compilation}
160161By default, Rust packages are compiled for the host platform, just like any
162other package is. The `--target` passed to rust tools is computed from this.
···168 name will be used instead.
169170 For example:
171+172 ```nix
173 import <nixpkgs> {
174 crossSystem = (import <nixpkgs/lib>).systems.examples.armhf-embedded // {
···176 };
177 }
178 ```
179+180 will result in:
181+182 ```shell
183 --target thumbv7em-none-eabi
184 ```
···191 will be used instead.
192193 For example:
194+195 ```nix
196 import <nixpkgs> {
197 crossSystem = (import <nixpkgs/lib>).systems.examples.armhf-embedded // {
···200 };
201 }
202 ```
203+204 will result in:
205+206 ```shell
207 --target /nix/store/asdfasdfsadf-thumb-crazy.json # contains {"foo":"","bar":""}
208 ```
···226Note that currently custom targets aren't compiled with `std`, so `cargo test`
227will fail. This can be ignored by adding `doCheck = false;` to your derivation.
228229+### Running package tests {#running-package-tests}
230231When using `buildRustPackage`, the `checkPhase` is enabled by default and runs
232`cargo test` on the package to build. To make sure that we don't compile the
···254binary itself, as stated
255(here)[https://doc.rust-lang.org/cargo/commands/cargo-test.html].
256257+#### Tests relying on the structure of the `target/` directory {#tests-relying-on-the-structure-of-the-target-directory}
258259Some tests may rely on the structure of the `target/` directory. Those tests
260are likely to fail because we use `cargo --target` during the build. This means that
···264265This can only be worked around by patching the affected tests accordingly.
266267+#### Disabling package-tests {#disabling-package-tests}
268269In some instances, it may be necessary to disable testing altogether (with `doCheck = false;`):
270···278However, please check if it's possible to disable a problematic subset of the
279test suite and leave a comment explaining your reasoning.
280281+#### Setting `test-threads` {#setting-test-threads}
282283`buildRustPackage` will use parallel test threads by default,
284sometimes it may be necessary to disable this so the tests run consecutively.
···290}
291```
292293+### Building a package in `debug` mode {#building-a-package-in-debug-mode}
294295By default, `buildRustPackage` will use `release` mode for builds. If a package
296should be built in `debug` mode, it can be configured like so:
···304305In this scenario, the `checkPhase` will be ran in `debug` mode as well.
306307+### Custom `build`/`install`-procedures {#custom-buildinstall-procedures}
308309Some packages may use custom scripts for building/installing, e.g. with a `Makefile`.
310In these cases, it's recommended to override the `buildPhase`/`installPhase`/`checkPhase`.
311312Otherwise, some steps may fail because of the modified directory structure of `target/`.
313314+### Building a crate with an absent or out-of-date Cargo.lock file {#building-a-crate-with-an-absent-or-out-of-date-cargo.lock-file}
315316`buildRustPackage` needs a `Cargo.lock` file to get all dependencies in the
317source code in a reproducible way. If it is missing or out-of-date one can use
···327}
328```
329330+## Compiling non-Rust packages that include Rust code {#compiling-non-rust-packages-that-include-rust-code}
331332Several non-Rust packages incorporate Rust code for performance- or
333security-sensitive parts. `rustPlatform` exposes several functions and
334hooks that can be used to integrate Cargo in non-Rust packages.
335336+### Vendoring of dependencies {#vendoring-of-dependencies}
337338Since network access is not allowed in sandboxed builds, Rust crate
339dependencies need to be retrieved using a fetcher. `rustPlatform`
···393`lib.fakeHash` as a stub hash. Building `cargoDeps` will then inform
394you of the correct hash.
395396+### Hooks {#hooks}
397398`rustPlatform` provides the following hooks to automate Cargo builds:
399···422* `cargoInstallHook`: install binaries and static/shared libraries
423 that were built using `cargoBuildHook`.
424425+### Examples {#examples}
426427+#### Python package using `setuptools-rust` {#python-package-using-setuptools-rust}
428429For Python packages using `setuptools-rust`, you can use
430`fetchCargoTarball` and `cargoSetupHook` to retrieve and set up Cargo
···510}
511```
512513+#### Python package using `maturin` {#python-package-using-maturin}
514515Python packages that use [Maturin](https://github.com/PyO3/maturin)
516can be built with `fetchCargoTarball`, `cargoSetupHook`, and
···551}
552```
553554+## Compiling Rust crates using Nix instead of Cargo {#compiling-rust-crates-using-nix-instead-of-cargo}
555556+### Simple operation {#simple-operation}
557558When run, `cargo build` produces a file called `Cargo.lock`,
559containing pinned versions of all dependencies. Nixpkgs contains a
···564and can be used to compile a crate and all its dependencies. Here is
565an example for a minimal `hello` crate:
566567+```ShellSession
568+$ cargo new hello
569+$ cd hello
570+$ cargo build
571 Compiling hello v0.1.0 (file:///tmp/hello)
572+ Finished dev [unoptimized + debuginfo] target(s) in 0.20 secs
573+$ carnix -o hello.nix --src ./. Cargo.lock --standalone
574+$ nix-build hello.nix -A hello_0_1_0
575+```
576577Now, the file produced by the call to `carnix`, called `hello.nix`, looks like:
578···651will fetch it from [crates.io](https://crates.io). A `sha256`
652attribute is still needed for Nix purity.
653654+### Handling external dependencies {#handling-external-dependencies}
655656Some crates require external libraries. For crates from
657[crates.io](https://crates.io), such libraries can be specified in
···710}
711```
712713+### Options and phases configuration {#options-and-phases-configuration}
714715Actually, the overrides introduced in the previous section are more
716general. A number of other parameters can be overridden:
···757 };
758 ```
759760+### Features {#features}
761762One can also supply features switches. For example, if we want to
763compile `diesel_cli` only with the `postgres` feature, and no default
···772773Where `diesel.nix` is the file generated by Carnix, as explained above.
774775+## Setting Up `nix-shell` {#setting-up-nix-shell}
7760777Oftentimes you want to develop code from within `nix-shell`. Unfortunately
778`buildRustCrate` does not support common `nix-shell` operations directly
779(see [this issue](https://github.com/NixOS/nixpkgs/issues/37945))
780so we will use `stdenv.mkDerivation` instead.
781782Using the example `hello` project above, we want to do the following:
783+784- Have access to `cargo` and `rustc`
785- Have the `openssl` library available to a crate through it's _normal_
786 compilation mechanism (`pkg-config`).
···809```
810811You should now be able to run the following:
812+813+```ShellSession
814$ nix-shell --pure
815$ cargo build
816$ cargo test
817```
818819+### Controlling Rust Version Inside `nix-shell` {#controlling-rust-version-inside-nix-shell}
820+821To control your rust version (i.e. use nightly) from within `shell.nix` (or
822other nix expressions) you can use the following `shell.nix`
823···849```
850851Now run:
852+853```ShellSession
854$ rustc --version
855rustc 1.26.0-nightly (188e693b3 2018-03-26)
···857858To see that you are using nightly.
859860+## Using the Rust nightlies overlay {#using-the-rust-nightlies-overlay}
0861862Mozilla provides an overlay for nixpkgs to bring a nightly version of Rust into scope.
863This overlay can _also_ be used to install recent unstable or stable versions
864of Rust, if desired.
865866+### Rust overlay installation {#rust-overlay-installation}
867868You can use this overlay by either changing your local nixpkgs configuration,
869or by adding the overlay declaratively in a nix expression, e.g. in `configuration.nix`.
870+For more information see [the manual on installing overlays](#sec-overlays-install).
871872+#### Imperative rust overlay installation {#imperative-rust-overlay-installation}
873874Clone [nixpkgs-mozilla](https://github.com/mozilla/nixpkgs-mozilla),
875and create a symbolic link to the file
876[rust-overlay.nix](https://github.com/mozilla/nixpkgs-mozilla/blob/master/rust-overlay.nix)
877in the `~/.config/nixpkgs/overlays` directory.
878879+```ShellSession
880+$ git clone https://github.com/mozilla/nixpkgs-mozilla.git
881+$ mkdir -p ~/.config/nixpkgs/overlays
882+$ ln -s $(pwd)/nixpkgs-mozilla/rust-overlay.nix ~/.config/nixpkgs/overlays/rust-overlay.nix
883+```
884885+### Declarative rust overlay installation {#declarative-rust-overlay-installation}
886887Add the following to your `configuration.nix`, `home-configuration.nix`, `shell.nix`, or similar:
888···898899Note that this will fetch the latest overlay version when rebuilding your system.
900901+### Rust overlay usage {#rust-overlay-usage}
902903The overlay contains attribute sets corresponding to different versions of the rust toolchain, such as:
904···912913Imperatively, the latest stable version can be installed with the following command:
914915+```ShellSession
916+$ nix-env -Ai nixpkgs.latest.rustChannels.stable.rust
917+```
918919Or using the attribute with nix-shell:
920921+```ShellSession
922+$ nix-shell -p nixpkgs.latest.rustChannels.stable.rust
923+```
924925Substitute the `nixpkgs` prefix with `nixos` on NixOS.
926To install the beta or nightly channel, "stable" should be substituted by
+2
doc/languages-frameworks/texlive.section.md
···5## User's guide {#sec-language-texlive-user-guide}
67- For basic usage just pull `texlive.combined.scheme-basic` for an environment with basic LaTeX support.
08- It typically won't work to use separately installed packages together. Instead, you can build a custom set of packages like this:
910 ```nix
···14 ```
1516- There are all the schemes, collections and a few thousand packages, as defined upstream (perhaps with tiny differences).
017- By default you only get executables and files needed during runtime, and a little documentation for the core packages. To change that, you need to add `pkgFilter` function to `combine`.
1819 ```nix
···5## User's guide {#sec-language-texlive-user-guide}
67- For basic usage just pull `texlive.combined.scheme-basic` for an environment with basic LaTeX support.
8+9- It typically won't work to use separately installed packages together. Instead, you can build a custom set of packages like this:
1011 ```nix
···15 ```
1617- There are all the schemes, collections and a few thousand packages, as defined upstream (perhaps with tiny differences).
18+19- By default you only get executables and files needed during runtime, and a little documentation for the core packages. To change that, you need to add `pkgFilter` function to `combine`.
2021 ```nix
+4-4
doc/languages-frameworks/titanium.section.md
···9Not all Titanium features supported -- currently, it can only be used to build
10Android and iOS apps.
1112-Building a Titanium app
13------------------------
14We can build a Titanium app from source for Android or iOS and for debugging or
15release purposes by invoking the `titaniumenv.buildApp {}` function:
16···103path of the PHP script (`installURL`) (that is included with the iOS build
104environment) to enable wireless ad-hoc installations.
105106-Emulating or simulating the app
107--------------------------------
108It is also possible to simulate the correspond iOS simulator build by using
109`xcodeenv.simulateApp {}` and emulate an Android APK by using
110`androidenv.emulateApp {}`.
···9Not all Titanium features supported -- currently, it can only be used to build
10Android and iOS apps.
1112+## Building a Titanium app {#building-a-titanium-app}
13+14We can build a Titanium app from source for Android or iOS and for debugging or
15release purposes by invoking the `titaniumenv.buildApp {}` function:
16···103path of the PHP script (`installURL`) (that is included with the iOS build
104environment) to enable wireless ad-hoc installations.
105106+## Emulating or simulating the app {#emulating-or-simulating-the-app}
107+108It is also possible to simulate the correspond iOS simulator build by using
109`xcodeenv.simulateApp {}` and emulate an Android APK by using
110`androidenv.emulateApp {}`.
+10-10
doc/languages-frameworks/vim.section.md
···12- Pathogen
13- vim-plug
1415-## Custom configuration
1617Adding custom .vimrc lines can be done using the following code:
18···56}
57```
5859-## Managing plugins with Vim packages
6061To store you plugins in Vim packages (the native Vim plugin manager, see `:help packages`) the following example can be used:
62···116117After that you can install your special grafted `myVim` or `myNeovim` packages.
118119-### What if your favourite Vim plugin isn't already packaged?
120121If one of your favourite plugins isn't packaged, you can package it yourself:
122···154}
155```
156157-## Managing plugins with vim-plug
158159To use [vim-plug](https://github.com/junegunn/vim-plug) to manage your Vim
160plugins the following example can be used:
···183}
184```
185186-## Managing plugins with VAM
187188-### Handling dependencies of Vim plugins
189190VAM introduced .json files supporting dependencies without versioning
191assuming that "using latest version" is ok most of the time.
192193-### Example
194195First create a vim-scripts file having one plugin name per line. Example:
196···280]
281```
282283-## Adding new plugins to nixpkgs
284285Nix expressions for Vim plugins are stored in [pkgs/misc/vim-plugins](/pkgs/misc/vim-plugins). For the vast majority of plugins, Nix expressions are automatically generated by running [`./update.py`](/pkgs/misc/vim-plugins/update.py). This creates a [generated.nix](/pkgs/misc/vim-plugins/generated.nix) file based on the plugins listed in [vim-plugin-names](/pkgs/misc/vim-plugins/vim-plugin-names). Plugins are listed in alphabetical order in `vim-plugin-names` using the format `[github username]/[repository]`. For example https://github.com/scrooloose/nerdtree becomes `scrooloose/nerdtree`.
286···298299Finally, there are some plugins that are also packaged in nodePackages because they have Javascript-related build steps, such as running webpack. Those plugins are not listed in `vim-plugin-names` or managed by `update.py` at all, and are included separately in `overrides.nix`. Currently, all these plugins are related to the `coc.nvim` ecosystem of Language Server Protocol integration with vim/neovim.
300301-## Updating plugins in nixpkgs
302303Run the update script with a GitHub API token that has at least `public_repo` access. Running the script without the token is likely to result in rate-limiting (429 errors). For steps on creating an API token, please refer to [GitHub's token documentation](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token).
304···312./pkgs/misc/vim-plugins/update.py --proc 1
313```
314315-## Important repositories
316317- [vim-pi](https://bitbucket.org/vimcommunity/vim-pi) is a plugin repository
318 from VAM plugin manager meant to be used by others as well used by
···12- Pathogen
13- vim-plug
1415+## Custom configuration {#custom-configuration}
1617Adding custom .vimrc lines can be done using the following code:
18···56}
57```
5859+## Managing plugins with Vim packages {#managing-plugins-with-vim-packages}
6061To store you plugins in Vim packages (the native Vim plugin manager, see `:help packages`) the following example can be used:
62···116117After that you can install your special grafted `myVim` or `myNeovim` packages.
118119+### What if your favourite Vim plugin isn’t already packaged? {#what-if-your-favourite-vim-plugin-isnt-already-packaged}
120121If one of your favourite plugins isn't packaged, you can package it yourself:
122···154}
155```
156157+## Managing plugins with vim-plug {#managing-plugins-with-vim-plug}
158159To use [vim-plug](https://github.com/junegunn/vim-plug) to manage your Vim
160plugins the following example can be used:
···183}
184```
185186+## Managing plugins with VAM {#managing-plugins-with-vam}
187188+### Handling dependencies of Vim plugins {#handling-dependencies-of-vim-plugins}
189190VAM introduced .json files supporting dependencies without versioning
191assuming that "using latest version" is ok most of the time.
192193+### Example {#example}
194195First create a vim-scripts file having one plugin name per line. Example:
196···280]
281```
282283+## Adding new plugins to nixpkgs {#adding-new-plugins-to-nixpkgs}
284285Nix expressions for Vim plugins are stored in [pkgs/misc/vim-plugins](/pkgs/misc/vim-plugins). For the vast majority of plugins, Nix expressions are automatically generated by running [`./update.py`](/pkgs/misc/vim-plugins/update.py). This creates a [generated.nix](/pkgs/misc/vim-plugins/generated.nix) file based on the plugins listed in [vim-plugin-names](/pkgs/misc/vim-plugins/vim-plugin-names). Plugins are listed in alphabetical order in `vim-plugin-names` using the format `[github username]/[repository]`. For example https://github.com/scrooloose/nerdtree becomes `scrooloose/nerdtree`.
286···298299Finally, there are some plugins that are also packaged in nodePackages because they have Javascript-related build steps, such as running webpack. Those plugins are not listed in `vim-plugin-names` or managed by `update.py` at all, and are included separately in `overrides.nix`. Currently, all these plugins are related to the `coc.nvim` ecosystem of Language Server Protocol integration with vim/neovim.
300301+## Updating plugins in nixpkgs {#updating-plugins-in-nixpkgs}
302303Run the update script with a GitHub API token that has at least `public_repo` access. Running the script without the token is likely to result in rate-limiting (429 errors). For steps on creating an API token, please refer to [GitHub's token documentation](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token).
304···312./pkgs/misc/vim-plugins/update.py --proc 1
313```
314315+## Important repositories {#important-repositories}
316317- [vim-pi](https://bitbucket.org/vimcommunity/vim-pi) is a plugin repository
318 from VAM plugin manager meant to be used by others as well used by
+1-1
doc/preface.chapter.md
···12expression language, then you are kindly referred to the [Nix manual](https://nixos.org/nix/manual/).
13The NixOS distribution is documented in the [NixOS manual](https://nixos.org/nixos/manual/).
1415-## Overview of Nixpkgs
1617Nix expressions describe how to build packages from source and are collected in
18the [nixpkgs repository](https://github.com/NixOS/nixpkgs). Also included in the
···12expression language, then you are kindly referred to the [Nix manual](https://nixos.org/nix/manual/).
13The NixOS distribution is documented in the [NixOS manual](https://nixos.org/nixos/manual/).
1415+## Overview of Nixpkgs {#overview-of-nixpkgs}
1617Nix expressions describe how to build packages from source and are collected in
18the [nixpkgs repository](https://github.com/NixOS/nixpkgs). Also included in the
+19-16
doc/stdenv/cross-compilation.chapter.md
···67This chapter will be organized in three parts. First, it will describe the basics of how to package software in a way that supports cross-compilation. Second, it will describe how to use Nixpkgs when cross-compiling. Third, it will describe the internal infrastructure supporting cross-compilation.
89-10## Packaging in a cross-friendly manner {#sec-cross-packaging}
1112### Platform parameters {#ssec-cross-platform-parameters}
···6566### Theory of dependency categorization {#ssec-cross-dependency-categorization}
6768-::: note
69-This is a rather philosophical description that isn't very Nixpkgs-specific. For an overview of all the relevant attributes given to `mkDerivation`, see <xref linkend="ssec-stdenv-dependencies"/>. For a description of how everything is implemented, see <xref linkend="ssec-cross-dependency-implementation"/>.
70:::
7172In this section we explore the relationship between both runtime and build-time dependencies and the 3 Autoconf platforms.
···8182Putting this all together, that means we have dependencies in the form "host → target", in at most the following six combinations:
8308485-#### Possible dependency types
86-| Dependency's host platform | Dependency's target platform |
87-| -- | -- |
88| build | build |
89| build | host |
90| build | target |
···113$ nix-build '<nixpkgs>' -A pkgsCross.raspberryPi.hello
114```
115116-#### What if my package's build system needs to build a C program to be run under the build environment? {#cross-qa-build-c-program-in-build-environment}
0117Add the following to your `mkDerivation` invocation.
0118```nix
119depsBuildBuild = [ buildPackages.stdenv.cc ];
120```
121122-#### My package's testsuite needs to run host platform code. {#cross-testsuite-runs-host-code}
123124Add the following to your `mkDerivation` invocation.
0125```nix
126doCheck = stdenv.hostPlatform == stdenv.buildPlatform;
127```
···134$ nix-build '<nixpkgs>' --arg crossSystem '(import <nixpkgs/lib>).systems.examples.fooBarBaz' -A whatever
135```
136137-::: note
138Eventually we would like to make these platform examples an unnecessary convenience so that
139140```ShellSession
···146147While one is free to pass both parameters in full, there's a lot of logic to fill in missing fields. As discussed in the previous section, only one of `system`, `config`, and `parsed` is needed to infer the other two. Additionally, `libc` will be inferred from `parse`. Finally, `localSystem.system` is also _impurely_ inferred based on the platform evaluation occurs. This means it is often not necessary to pass `localSystem` at all, as in the command-line example in the previous paragraph.
148149-::: note
150Many sources (manual, wiki, etc) probably mention passing `system`, `platform`, along with the optional `crossSystem` to Nixpkgs: `import <nixpkgs> { system = ..; platform = ..; crossSystem = ..; }`. Passing those two instead of `localSystem` is still supported for compatibility, but is discouraged. Indeed, much of the inference we do for these parameters is motivated by compatibility as much as convenience.
151:::
152···156157### Implementation of dependencies {#ssec-cross-dependency-implementation}
158159-The categories of dependencies developed in <xref linkend="ssec-cross-dependency-categorization"/> are specified as lists of derivations given to `mkDerivation`, as documented in <xref linkend="ssec-stdenv-dependencies"/>. In short, each list of dependencies for "host → target" of "foo → bar" is called `depsFooBar`, with exceptions for backwards compatibility that `depsBuildHost` is instead called `nativeBuildInputs` and `depsHostTarget` is instead called `buildInputs`. Nixpkgs is now structured so that each `depsFooBar` is automatically taken from `pkgsFooBar`. (These `pkgsFooBar`s are quite new, so there is no special case for `nativeBuildInputs` and `buildInputs`.) For example, `pkgsBuildHost.gcc` should be used at build-time, while `pkgsHostTarget.gcc` should be used at run-time.
160161Now, for most of Nixpkgs's history, there were no `pkgsFooBar` attributes, and most packages have not been refactored to use it explicitly. Prior to those, there were just `buildPackages`, `pkgs`, and `targetPackages`. Those are now redefined as aliases to `pkgsBuildHost`, `pkgsHostTarget`, and `pkgsTargetTarget`. It is acceptable, even recommended, to use them for libraries to show that the host platform is irrelevant.
162···178179In each stage, `pkgsBuildHost` refers to the previous stage, `pkgsBuildBuild` refers to the one before that, and `pkgsHostTarget` refers to the current one, and `pkgsTargetTarget` refers to the next one. When there is no previous or next stage, they instead refer to the current stage. Note how all the invariants regarding the mapping between dependency and depending packages' build host and target platforms are preserved. `pkgsBuildTarget` and `pkgsHostHost` are more complex in that the stage fitting the requirements isn't always a fixed chain of "prevs" and "nexts" away (modulo the "saturating" self-references at the ends). We just special case each instead. All the primary edges are implemented is in `pkgs/stdenv/booter.nix`, and secondarily aliases in `pkgs/top-level/stage.nix`.
180181-::: note
182The native stages are bootstrapped in legacy ways that predate the current cross implementation. This is why the bootstrapping stages leading up to the final stages are ignored in the previous paragraph.
183:::
184···186```
187(native, native, native, foreign, foreign)
188```
0189If one imagines the saturating self references at the end being replaced with infinite stages, and then overlays those platform triples, one ends up with the infinite tuple:
190```
191(native..., native, native, native, foreign, foreign, foreign...)
···193One can then imagine any sequence of platforms such that there are bootstrap stages with their 3 platforms determined by "sliding a window" that is the 3 tuple through the sequence. This was the original model for bootstrapping. Without a target platform (assume a better world where all compilers are multi-target and all standard libraries are built in their own derivation), this is sufficient. Conversely if one wishes to cross compile "faster", with a "Canadian Cross" bootstrapping stage where `build != host != target`, more bootstrapping stages are needed since no sliding window provides the pesky `pkgsBuildTarget` package set since it skips the Canadian cross stage's "host".
194195196-::: note
197-It is much better to refer to `buildPackages` than `targetPackages`, or more broadly package sets that do not mention "target". There are three reasons for this.
198199First, it is because bootstrapping stages do not have a unique `targetPackages`. For example a `(x86-linux, x86-linux, arm-linux)` and `(x86-linux, x86-linux, x86-windows)` package set both have a `(x86-linux, x86-linux, x86-linux)` package set. Because there is no canonical `targetPackages` for such a native (`build == host == target`) package set, we set their `targetPackages`
200···203Thirdly, it is because everything target-mentioning only exists to accommodate compilers with lousy build systems that insist on the compiler itself and standard library being built together. Of course that is bad because bigger derivations means longer rebuilds. It is also problematic because it tends to make the standard libraries less like other libraries than they could be, complicating code and build systems alike. Because of the other problems, and because of these innate disadvantages, compilers ought to be packaged another way where possible.
204:::
205206-::: note
207-If one explores Nixpkgs, they will see derivations with names like `gccCross`. Such `*Cross` derivations is a holdover from before we properly distinguished between the host and target platforms—the derivation with "Cross" in the name covered the `build = host != target` case, while the other covered the `host = target`, with build platform the same or not based on whether one was using its `.nativeDrv` or `.crossDrv`. This ugliness will disappear soon.
208:::
···67This chapter will be organized in three parts. First, it will describe the basics of how to package software in a way that supports cross-compilation. Second, it will describe how to use Nixpkgs when cross-compiling. Third, it will describe the internal infrastructure supporting cross-compilation.
809## Packaging in a cross-friendly manner {#sec-cross-packaging}
1011### Platform parameters {#ssec-cross-platform-parameters}
···6465### Theory of dependency categorization {#ssec-cross-dependency-categorization}
6667+::: {.note}
68+This is a rather philosophical description that isn't very Nixpkgs-specific. For an overview of all the relevant attributes given to `mkDerivation`, see [](#ssec-stdenv-dependencies). For a description of how everything is implemented, see [](#ssec-cross-dependency-implementation).
69:::
7071In this section we explore the relationship between both runtime and build-time dependencies and the 3 Autoconf platforms.
···8081Putting this all together, that means we have dependencies in the form "host → target", in at most the following six combinations:
8283+#### Possible dependency types {#possible-dependency-types}
8485+| Dependency’s host platform | Dependency’s target platform |
86+|----------------------------|------------------------------|
087| build | build |
88| build | host |
89| build | target |
···112$ nix-build '<nixpkgs>' -A pkgsCross.raspberryPi.hello
113```
114115+#### What if my package’s build system needs to build a C program to be run under the build environment? {#cross-qa-build-c-program-in-build-environment}
116+117Add the following to your `mkDerivation` invocation.
118+119```nix
120depsBuildBuild = [ buildPackages.stdenv.cc ];
121```
122123+#### My package’s testsuite needs to run host platform code. {#cross-testsuite-runs-host-code}
124125Add the following to your `mkDerivation` invocation.
126+127```nix
128doCheck = stdenv.hostPlatform == stdenv.buildPlatform;
129```
···136$ nix-build '<nixpkgs>' --arg crossSystem '(import <nixpkgs/lib>).systems.examples.fooBarBaz' -A whatever
137```
138139+::: {.note}
140Eventually we would like to make these platform examples an unnecessary convenience so that
141142```ShellSession
···148149While one is free to pass both parameters in full, there's a lot of logic to fill in missing fields. As discussed in the previous section, only one of `system`, `config`, and `parsed` is needed to infer the other two. Additionally, `libc` will be inferred from `parse`. Finally, `localSystem.system` is also _impurely_ inferred based on the platform evaluation occurs. This means it is often not necessary to pass `localSystem` at all, as in the command-line example in the previous paragraph.
150151+::: {.note}
152Many sources (manual, wiki, etc) probably mention passing `system`, `platform`, along with the optional `crossSystem` to Nixpkgs: `import <nixpkgs> { system = ..; platform = ..; crossSystem = ..; }`. Passing those two instead of `localSystem` is still supported for compatibility, but is discouraged. Indeed, much of the inference we do for these parameters is motivated by compatibility as much as convenience.
153:::
154···158159### Implementation of dependencies {#ssec-cross-dependency-implementation}
160161+The categories of dependencies developed in [](#ssec-cross-dependency-categorization) are specified as lists of derivations given to `mkDerivation`, as documented in [](#ssec-stdenv-dependencies). In short, each list of dependencies for "host → target" of "foo → bar" is called `depsFooBar`, with exceptions for backwards compatibility that `depsBuildHost` is instead called `nativeBuildInputs` and `depsHostTarget` is instead called `buildInputs`. Nixpkgs is now structured so that each `depsFooBar` is automatically taken from `pkgsFooBar`. (These `pkgsFooBar`s are quite new, so there is no special case for `nativeBuildInputs` and `buildInputs`.) For example, `pkgsBuildHost.gcc` should be used at build-time, while `pkgsHostTarget.gcc` should be used at run-time.
162163Now, for most of Nixpkgs's history, there were no `pkgsFooBar` attributes, and most packages have not been refactored to use it explicitly. Prior to those, there were just `buildPackages`, `pkgs`, and `targetPackages`. Those are now redefined as aliases to `pkgsBuildHost`, `pkgsHostTarget`, and `pkgsTargetTarget`. It is acceptable, even recommended, to use them for libraries to show that the host platform is irrelevant.
164···180181In each stage, `pkgsBuildHost` refers to the previous stage, `pkgsBuildBuild` refers to the one before that, and `pkgsHostTarget` refers to the current one, and `pkgsTargetTarget` refers to the next one. When there is no previous or next stage, they instead refer to the current stage. Note how all the invariants regarding the mapping between dependency and depending packages' build host and target platforms are preserved. `pkgsBuildTarget` and `pkgsHostHost` are more complex in that the stage fitting the requirements isn't always a fixed chain of "prevs" and "nexts" away (modulo the "saturating" self-references at the ends). We just special case each instead. All the primary edges are implemented is in `pkgs/stdenv/booter.nix`, and secondarily aliases in `pkgs/top-level/stage.nix`.
182183+::: {.note}
184The native stages are bootstrapped in legacy ways that predate the current cross implementation. This is why the bootstrapping stages leading up to the final stages are ignored in the previous paragraph.
185:::
186···188```
189(native, native, native, foreign, foreign)
190```
191+192If one imagines the saturating self references at the end being replaced with infinite stages, and then overlays those platform triples, one ends up with the infinite tuple:
193```
194(native..., native, native, native, foreign, foreign, foreign...)
···196One can then imagine any sequence of platforms such that there are bootstrap stages with their 3 platforms determined by "sliding a window" that is the 3 tuple through the sequence. This was the original model for bootstrapping. Without a target platform (assume a better world where all compilers are multi-target and all standard libraries are built in their own derivation), this is sufficient. Conversely if one wishes to cross compile "faster", with a "Canadian Cross" bootstrapping stage where `build != host != target`, more bootstrapping stages are needed since no sliding window provides the pesky `pkgsBuildTarget` package set since it skips the Canadian cross stage's "host".
197198199+::: {.note}
200+It is much better to refer to `buildPackages` than `targetPackages`, or more broadly package sets that do not mention “target”. There are three reasons for this.
201202First, it is because bootstrapping stages do not have a unique `targetPackages`. For example a `(x86-linux, x86-linux, arm-linux)` and `(x86-linux, x86-linux, x86-windows)` package set both have a `(x86-linux, x86-linux, x86-linux)` package set. Because there is no canonical `targetPackages` for such a native (`build == host == target`) package set, we set their `targetPackages`
203···206Thirdly, it is because everything target-mentioning only exists to accommodate compilers with lousy build systems that insist on the compiler itself and standard library being built together. Of course that is bad because bigger derivations means longer rebuilds. It is also problematic because it tends to make the standard libraries less like other libraries than they could be, complicating code and build systems alike. Because of the other problems, and because of these innate disadvantages, compilers ought to be packaged another way where possible.
207:::
208209+::: {.note}
210+If one explores Nixpkgs, they will see derivations with names like `gccCross`. Such `*Cross` derivations is a holdover from before we properly distinguished between the host and target platforms—the derivation with “Cross” in the name covered the `build = host != target` case, while the other covered the `host = target`, with build platform the same or not based on whether one was using its `.nativeDrv` or `.crossDrv`. This ugliness will disappear soon.
211:::
+5-5
doc/stdenv/meta.chapter.md
···130131### `tests` {#var-meta-tests}
132133-::: warning
134This attribute is special in that it is not actually under the `meta` attribute set but rather under the `passthru` attribute set. This is due to how `meta` attributes work, and the fact that they are supposed to contain only metadata, not derivations.
135:::
136···175176Although it’s typically better to indicate the specific license, a few generic options are available:
177178-### `lib.licenses.free`, `"free"`
179180Catch-all for free software licenses not listed above.
181182-### `lib.licenses.unfreeRedistributable`, `"unfree-redistributable"`
183184Unfree package that can be redistributed in binary form. That is, it’s legal to redistribute the *output* of the derivation. This means that the package can be included in the Nixpkgs channel.
185186Sometimes proprietary software can only be redistributed unmodified. Make sure the builder doesn’t actually modify the original binaries; otherwise we’re breaking the license. For instance, the NVIDIA X11 drivers can be redistributed unmodified, but our builder applies `patchelf` to make them work. Thus, its license is `"unfree"` and it cannot be included in the Nixpkgs channel.
187188-### `lib.licenses.unfree`, `"unfree"`
189190Unfree package that cannot be redistributed. You can build it yourself, but you cannot redistribute the output of the derivation. Thus it cannot be included in the Nixpkgs channel.
191192-### `lib.licenses.unfreeRedistributableFirmware`, `"unfree-redistributable-firmware"`
193194This package supplies unfree, redistributable firmware. This is a separate value from `unfree-redistributable` because not everybody cares whether firmware is free.
···130131### `tests` {#var-meta-tests}
132133+::: {.warning}
134This attribute is special in that it is not actually under the `meta` attribute set but rather under the `passthru` attribute set. This is due to how `meta` attributes work, and the fact that they are supposed to contain only metadata, not derivations.
135:::
136···175176Although it’s typically better to indicate the specific license, a few generic options are available:
177178+### `lib.licenses.free`, `"free"` {#lib.licenses.free-free}
179180Catch-all for free software licenses not listed above.
181182+### `lib.licenses.unfreeRedistributable`, `"unfree-redistributable"` {#lib.licenses.unfreeredistributable-unfree-redistributable}
183184Unfree package that can be redistributed in binary form. That is, it’s legal to redistribute the *output* of the derivation. This means that the package can be included in the Nixpkgs channel.
185186Sometimes proprietary software can only be redistributed unmodified. Make sure the builder doesn’t actually modify the original binaries; otherwise we’re breaking the license. For instance, the NVIDIA X11 drivers can be redistributed unmodified, but our builder applies `patchelf` to make them work. Thus, its license is `"unfree"` and it cannot be included in the Nixpkgs channel.
187188+### `lib.licenses.unfree`, `"unfree"` {#lib.licenses.unfree-unfree}
189190Unfree package that cannot be redistributed. You can build it yourself, but you cannot redistribute the output of the derivation. Thus it cannot be included in the Nixpkgs channel.
191192+### `lib.licenses.unfreeRedistributableFirmware`, `"unfree-redistributable-firmware"` {#lib.licenses.unfreeredistributablefirmware-unfree-redistributable-firmware}
193194This package supplies unfree, redistributable firmware. This is a separate value from `unfree-redistributable` because not everybody cares whether firmware is free.
+14-14
doc/stdenv/multiple-output.chapter.md
···67The main motivation is to save disk space by reducing runtime closure sizes; consequently also sizes of substituted binaries get reduced. Splitting can be used to have more granular runtime dependencies, for example the typical reduction is to split away development-only files, as those are typically not needed during runtime. As a result, closure sizes of many packages can get reduced to a half or even much less.
89-::: note
10The reduction effects could be instead achieved by building the parts in completely separate derivations. That would often additionally reduce build-time closures, but it tends to be much harder to write such derivations, as build systems typically assume all parts are being built at once. This compromise approach of single source package producing multiple binary packages is also utilized often by rpm and deb.
11:::
12···2829`nix-env` lacks an easy way to select the outputs to install. When installing a package, `nix-env` always installs the outputs listed in `meta.outputsToInstall`, even when the user explicitly selects an output.
3031-::: warning
32`nix-env` silenty disregards the outputs selected by the user, and instead installs the outputs from `meta.outputsToInstall`. For example,
3334```ShellSession
···38installs the `"out"` output (`coreutils.meta.outputsToInstall` is `[ "out" ]`) instead of the requested `"info"`.
39:::
4041-The only recourse to select an output with `nix-env` is to override the package’s `meta.outputsToInstall`, using the functions described in <xref linkend="chap-overrides" />. For example, the following overlay adds the `"info"` output for the `coreutils` package:
4243```nix
44self: super:
···5354In the Nix language the individual outputs can be reached explicitly as attributes, e.g. `coreutils.info`, but the typical case is just using packages as build inputs.
5556-When a multiple-output derivation gets into a build input of another derivation, the `dev` output is added if it exists, otherwise the first output is added. In addition to that, `propagatedBuildOutputs` of that package which by default contain `$outputBin` and `$outputLib` are also added. (See <xref linkend="multiple-output-file-type-groups" />.)
5758In some cases it may be desirable to combine different outputs under a single store path. A function `symlinkJoin` can be used to do this. (Note that it may negate some closure size benefits of using a multiple-output package.)
59···6970Often such a single line is enough. For each output an equally named environment variable is passed to the builder and contains the path in nix store for that output. Typically you also want to have the main `out` output, as it catches any files that didn’t get elsewhere.
7172-::: note
73-There is a special handling of the `debug` output, described at <xref linkend="stdenv-separateDebugInfo" />.
74:::
7576### “Binaries first” {#multiple-output-file-binaries-first-convention}
···8586The support code currently recognizes some particular kinds of outputs and either instructs the build system of the package to put files into their desired outputs or it moves the files during the fixup phase. Each group of file types has an `outputFoo` variable specifying the output name where they should go. If that variable isn’t defined by the derivation writer, it is guessed – a default output name is defined, falling back to other possibilities if the output isn’t defined.
8788-#### ` $outputDev`
8990is for development-only files. These include C(++) headers (`include/`), pkg-config (`lib/pkgconfig/`), cmake (`lib/cmake/`) and aclocal files (`share/aclocal/`). They go to `dev` or `out` by default.
9192-#### ` $outputBin`
9394is meant for user-facing binaries, typically residing in `bin/`. They go to `bin` or `out` by default.
9596-#### ` $outputLib`
9798is meant for libraries, typically residing in `lib/` and `libexec/`. They go to `lib` or `out` by default.
99100-#### ` $outputDoc`
101102is for user documentation, typically residing in `share/doc/`. It goes to `doc` or `out` by default.
103104-#### ` $outputDevdoc`
105106is for _developer_ documentation. Currently we count gtk-doc and devhelp books, typically residing in `share/gtk-doc/` and `share/devhelp/`, in there. It goes to `devdoc` or is removed (!) by default. This is because e.g. gtk-doc tends to be rather large and completely unused by nixpkgs users.
107108-#### ` $outputMan`
109110is for man pages (except for section 3), typically residing in `share/man/man[0-9]/`. They go to `man` or `$outputBin` by default.
111112-#### ` $outputDevman`
113114is for section 3 man pages, typically residing in `share/man/man[0-9]/`. They go to `devman` or `$outputMan` by default.
115116-#### ` $outputInfo`
117118is for info pages, typically residing in `share/info/`. They go to `info` or `$outputBin` by default.
119
···67The main motivation is to save disk space by reducing runtime closure sizes; consequently also sizes of substituted binaries get reduced. Splitting can be used to have more granular runtime dependencies, for example the typical reduction is to split away development-only files, as those are typically not needed during runtime. As a result, closure sizes of many packages can get reduced to a half or even much less.
89+::: {.note}
10The reduction effects could be instead achieved by building the parts in completely separate derivations. That would often additionally reduce build-time closures, but it tends to be much harder to write such derivations, as build systems typically assume all parts are being built at once. This compromise approach of single source package producing multiple binary packages is also utilized often by rpm and deb.
11:::
12···2829`nix-env` lacks an easy way to select the outputs to install. When installing a package, `nix-env` always installs the outputs listed in `meta.outputsToInstall`, even when the user explicitly selects an output.
3031+::: {.warning}
32`nix-env` silenty disregards the outputs selected by the user, and instead installs the outputs from `meta.outputsToInstall`. For example,
3334```ShellSession
···38installs the `"out"` output (`coreutils.meta.outputsToInstall` is `[ "out" ]`) instead of the requested `"info"`.
39:::
4041+The only recourse to select an output with `nix-env` is to override the package’s `meta.outputsToInstall`, using the functions described in [](#chap-overrides). For example, the following overlay adds the `"info"` output for the `coreutils` package:
4243```nix
44self: super:
···5354In the Nix language the individual outputs can be reached explicitly as attributes, e.g. `coreutils.info`, but the typical case is just using packages as build inputs.
5556+When a multiple-output derivation gets into a build input of another derivation, the `dev` output is added if it exists, otherwise the first output is added. In addition to that, `propagatedBuildOutputs` of that package which by default contain `$outputBin` and `$outputLib` are also added. (See [](#multiple-output-file-type-groups).)
5758In some cases it may be desirable to combine different outputs under a single store path. A function `symlinkJoin` can be used to do this. (Note that it may negate some closure size benefits of using a multiple-output package.)
59···6970Often such a single line is enough. For each output an equally named environment variable is passed to the builder and contains the path in nix store for that output. Typically you also want to have the main `out` output, as it catches any files that didn’t get elsewhere.
7172+::: {.note}
73+There is a special handling of the `debug` output, described at [](#stdenv-separateDebugInfo).
74:::
7576### “Binaries first” {#multiple-output-file-binaries-first-convention}
···8586The support code currently recognizes some particular kinds of outputs and either instructs the build system of the package to put files into their desired outputs or it moves the files during the fixup phase. Each group of file types has an `outputFoo` variable specifying the output name where they should go. If that variable isn’t defined by the derivation writer, it is guessed – a default output name is defined, falling back to other possibilities if the output isn’t defined.
8788+#### `$outputDev` {#outputdev}
8990is for development-only files. These include C(++) headers (`include/`), pkg-config (`lib/pkgconfig/`), cmake (`lib/cmake/`) and aclocal files (`share/aclocal/`). They go to `dev` or `out` by default.
9192+#### `$outputBin` {#outputbin}
9394is meant for user-facing binaries, typically residing in `bin/`. They go to `bin` or `out` by default.
9596+#### `$outputLib` {#outputlib}
9798is meant for libraries, typically residing in `lib/` and `libexec/`. They go to `lib` or `out` by default.
99100+#### `$outputDoc` {#outputdoc}
101102is for user documentation, typically residing in `share/doc/`. It goes to `doc` or `out` by default.
103104+#### `$outputDevdoc` {#outputdevdoc}
105106is for _developer_ documentation. Currently we count gtk-doc and devhelp books, typically residing in `share/gtk-doc/` and `share/devhelp/`, in there. It goes to `devdoc` or is removed (!) by default. This is because e.g. gtk-doc tends to be rather large and completely unused by nixpkgs users.
107108+#### `$outputMan` {#outputman}
109110is for man pages (except for section 3), typically residing in `share/man/man[0-9]/`. They go to `man` or `$outputBin` by default.
111112+#### `$outputDevman` {#outputdevman}
113114is for section 3 man pages, typically residing in `share/man/man[0-9]/`. They go to `devman` or `$outputMan` by default.
115116+#### `$outputInfo` {#outputinfo}
117118is for info pages, typically residing in `share/info/`. They go to `info` or `$outputBin` by default.
119
+74-72
doc/stdenv/stdenv.chapter.md
···39}
40```
4142-This attribute ensures that the `bin` subdirectories of these packages appear in the `PATH` environment variable during the build, that their `include` subdirectories are searched by the C compiler, and so on. (See <xref linkend="ssec-setup-hooks" /> for details.)
4344-Often it is necessary to override or modify some aspect of the build. To make this easier, the standard environment breaks the package build into a number of *phases*, all of which can be overridden or modified individually: unpacking the sources, applying patches, configuring, building, and installing. (There are some others; see <xref linkend="sec-stdenv-phases" />.) For instance, a package that doesn’t supply a makefile but instead has to be compiled "manually" could be handled like this:
4546```nix
47stdenv.mkDerivation {
···5960(Note the use of `''`-style string literals, which are very convenient for large multi-line script fragments because they don’t need escaping of `"` and `\`, and because indentation is intelligently removed.)
6162-There are many other attributes to customise the build. These are listed in <xref linkend="ssec-stdenv-attributes" />.
6364While the standard environment provides a generic builder, you can still supply your own build script:
65···116117## Specifying dependencies {#ssec-stdenv-dependencies}
118119-As described in the Nix manual, almost any `*.drv` store path in a derivation’s attribute set will induce a dependency on that derivation. `mkDerivation`, however, takes a few attributes intended to, between them, include all the dependencies of a package. This is done both for structure and consistency, but also so that certain other setup can take place. For example, certain dependencies need their bin directories added to the `PATH`. That is built-in, but other setup is done via a pluggable mechanism that works in conjunction with these dependency attributes. See <xref linkend="ssec-setup-hooks" /> for details.
120121-Dependencies can be broken down along three axes: their host and target platforms relative to the new derivation’s, and whether they are propagated. The platform distinctions are motivated by cross compilation; see <xref linkend="chap-cross" /> for exactly what each platform means. [^footnote-stdenv-ignored-build-platform] But even if one is not cross compiling, the platforms imply whether or not the dependency is needed at run-time or build-time, a concept that makes perfect sense outside of cross compilation. By default, the run-time/build-time distinction is just a hint for mental clarity, but with `strictDeps` set it is mostly enforced even in the native case.
122123The extension of `PATH` with dependencies, alluded to above, proceeds according to the relative platforms alone. The process is carried out only for dependencies whose host platform matches the new derivation’s build platform i.e. dependencies which run on the platform where the new derivation will be built. [^footnote-stdenv-native-dependencies-in-path] For each dependency \<dep\> of those dependencies, `dep/bin`, if present, is added to the `PATH` environment variable.
124···175176Overall, the unifying theme here is that propagation shouldn’t be introducing transitive dependencies involving platforms the depending package is unaware of. \[One can imagine the dependending package asking for dependencies with the platforms it knows about; other platforms it doesn’t know how to ask for. The platform description in that scenario is a kind of unforagable capability.\] The offset bounds checking and definition of `mapOffset` together ensure that this is the case. Discovering a new offset is discovering a new platform, and since those platforms weren’t in the derivation “spec” of the needing package, they cannot be relevant. From a capability perspective, we can imagine that the host and target platforms of a package are the capabilities a package requires, and the depending package must provide the capability to the dependency.
177178-### Variables specifying dependencies
0179#### `depsBuildBuild` {#var-stdenv-depsBuildBuild}
180181A list of dependencies whose host and target platforms are the new derivation’s build platform. This means a `-1` host and `-1` target offset from the new derivation’s platforms. These are programs and libraries used at build time that produce programs and libraries also used at build time. If the dependency doesn’t care about the target platform (i.e. isn’t a compiler or similar tool), put it in `nativeBuildInputs` instead. The most common use of this `buildPackages.stdenv.cc`, the default C compiler for this role. That example crops up more than one might think in old commonly used C libraries.
···236237## Attributes {#ssec-stdenv-attributes}
238239-### Variables affecting `stdenv` initialisation
240241#### `NIX_DEBUG` {#var-stdenv-NIX_DEBUG}
242243A natural number indicating how much information to log. If set to 1 or higher, `stdenv` will print moderate debugging information during the build. In particular, the `gcc` and `ld` wrapper scripts will print out the complete command line passed to the wrapped tools. If set to 6 or higher, the `stdenv` setup script will be run with `set -x` tracing. If set to 7 or higher, the `gcc` and `ld` wrapper scripts will also be run with `set -x` tracing.
244245-### Attributes affecting build properties
246247#### `enableParallelBuilding` {#var-stdenv-enableParallelBuilding}
248···250251Unless set to `false`, some build systems with good support for parallel building including `cmake`, `meson`, and `qmake` will set it to `true`.
252253-### Special variables
254255#### `passthru` {#var-stdenv-passthru}
256···298299The script will be run with `UPDATE_NIX_ATTR_PATH` environment variable set to the attribute path it is supposed to update.
300301-::: note
302The script will be usually run from the root of the Nixpkgs repository but you should not rely on that. Also note that the update scripts will be run in parallel by default; you should avoid running `git commit` or any other commands that cannot handle that.
303:::
304···314315There are a number of variables that control what phases are executed and in what order:
316317-#### Variables affecting phase control
318319##### `phases` {#var-stdenv-phases}
320···354355The unpack phase is responsible for unpacking the source code of the package. The default implementation of `unpackPhase` unpacks the source files listed in the `src` environment variable to the current directory. It supports the following files by default:
356357-#### Tar files
358359These can optionally be compressed using `gzip` (`.tar.gz`, `.tgz` or `.tar.Z`), `bzip2` (`.tar.bz2`, `.tbz2` or `.tbz`) or `xz` (`.tar.xz`, `.tar.lzma` or `.txz`).
360361-#### Zip files
362363Zip files are unpacked using `unzip`. However, `unzip` is not in the standard environment, so you should add it to `nativeBuildInputs` yourself.
364365-#### Directories in the Nix store
366367These are simply copied to the current directory. The hash part of the file name is stripped, e.g. `/nix/store/1wydxgby13cz...-my-sources` would be copied to `my-sources`.
368369Additional file types can be supported by setting the `unpackCmd` variable (see below).
370371-#### Variables controlling the unpack phase
0372##### `srcs` / `src` {#var-stdenv-src}
373374The list of source files or directories to be unpacked or copied. One of these must be set.
···405406The patch phase applies the list of patches defined in the `patches` variable.
407408-#### Variables controlling the patch phase
409410##### `dontPatch` {#var-stdenv-dontPatch}
411···431432The configure phase prepares the source tree for building. The default `configurePhase` runs `./configure` (typically an Autoconf-generated script) if it exists.
433434-#### Variables controlling the configure phase
435436##### `configureScript` {#var-stdenv-configureScript}
437···491492The build phase is responsible for actually building the package (e.g. compiling it). The default `buildPhase` simply calls `make` if a file named `Makefile`, `makefile` or `GNUmakefile` exists in the current directory (or the `makefile` is explicitly set); otherwise it does nothing.
493494-#### Variables controlling the build phase
495496##### `dontBuild` {#var-stdenv-dontBuild}
497···509makeFlags = [ "PREFIX=$(out)" ];
510```
511512-::: note
513The flags are quoted in bash, but environment variables can be specified by using the make syntax.
514:::
515···545546The check phase checks whether the package was built correctly by running its test suite. The default `checkPhase` calls `make check`, but only if the `doCheck` variable is enabled.
547548-#### Variables controlling the check phase
549550##### `doCheck` {#var-stdenv-doCheck}
551···557558in the derivation to enable checks. The exception is cross compilation. Cross compiled builds never run tests, no matter how `doCheck` is set, as the newly-built program won’t run on the platform used to build it.
559560-##### `makeFlags` / `makeFlagsArray` / `makefile`
561562See the [build phase](#var-stdenv-makeFlags) for details.
563···585586The install phase is responsible for installing the package in the Nix store under `out`. The default `installPhase` creates the directory `$out` and calls `make install`.
587588-#### Variables controlling the install phase
589590##### `dontInstall` {#var-stdenv-dontInstall}
591592Set to true to skip the install phase.
593594-##### `makeFlags` / `makeFlagsArray` / `makefile`
595596See the [build phase](#var-stdenv-makeFlags) for details.
597···624- On Linux, it applies the `patchelf` command to ELF executables and libraries to remove unused directories from the `RPATH` in order to prevent unnecessary runtime dependencies.
625- It rewrites the interpreter paths of shell scripts to paths found in `PATH`. E.g., `/usr/bin/perl` will be rewritten to `/nix/store/some-perl/bin/perl` found in `PATH`.
626627-#### Variables controlling the fixup phase
628629##### `dontFixup` {#var-stdenv-dontFixup}
630···706707The installCheck phase checks whether the package was installed correctly by running its test suite against the installed directories. The default `installCheck` calls `make installcheck`.
708709-#### Variables controlling the installCheck phase
710711##### `doInstallCheck` {#var-stdenv-doInstallCheck}
712···742743The distribution phase is intended to produce a source distribution of the package. The default `distPhase` first calls `make dist`, then it copies the resulting source tarballs to `$out/tarballs/`. This phase is only executed if the attribute `doDist` is set.
744745-#### Variables controlling the distribution phase
746747##### `distTarget` {#var-stdenv-distTarget}
748···879880Packages adding a hook should not hard code a specific hook, but rather choose a variable *relative* to how they are included. Returning to the C compiler wrapper example, if the wrapper itself is an `n` dependency, then it only wants to accumulate flags from `n + 1` dependencies, as only those ones match the compiler’s target platform. The `hostOffset` variable is defined with the current dependency’s host offset `targetOffset` with its target offset, before its setup hook is sourced. Additionally, since most environment hooks don’t care about the target platform, that means the setup hook can append to the right bash array by doing something like
881882-```{.bash}
883addEnvHooks "$hostOffset" myBashFunction
884```
885···887888First, 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`. Some of these are platform specific, so they may run on Linux but not Darwin or vice-versa.
889890-### `move-docs.sh`
891892This 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.
893894-### `compress-man-pages.sh`
895896This 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.
897898-### `strip.sh`
899900This 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.
901902-### `patch-shebangs.sh`
903904This setup hook patches installed scripts to use the full path to the shebang interpreter. A shebang interpreter is the first commented line of a script telling the operating system which program will run the script (e.g `#!/bin/bash`). In Nix, we want an exact path to that interpreter to be used. This often replaces `/bin/sh` with a path in the Nix store.
905906-### `audit-tmpdir.sh`
907908This 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.
909910-### `multiple-outputs.sh`
911912-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 <xref linkend="chap-multiple-output" /> for more information.
913914-### `move-sbin.sh`
915916This setup hook moves any binaries installed in the `sbin/` subdirectory into `bin/`. In addition, a link is provided from `sbin/` to `bin/` for compatibility.
917918-### `move-lib64.sh`
919920This setup hook moves any libraries installed in the `lib64/` subdirectory into `lib/`. In addition, a link is provided from `lib64/` to `lib/` for compatibility.
921922-### `move-systemd-user-units.sh`
923924This 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.
925926-### `set-source-date-epoch-to-latest.sh`
927928This sets `SOURCE_DATE_EPOCH` to the modification time of the most recent file.
929930-### Bintools Wrapper
931932The 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.
933···937938A problem with this final task is that the Bintools Wrapper is honest and defines `LD` as `ld`. Most packages, however, firstly use the C compiler for linking, secondly use `LD` anyways, defining it as the C compiler, and thirdly, only so define `LD` when it is undefined as a fallback. This triple-threat means Bintools Wrapper will break those packages, as LD is already defined as the actual linker which the package won’t override yet doesn’t want to use. The workaround is to define, just for the problematic package, `LD` as the C compiler. A good way to do this would be `preConfigure = "LD=$CC"`.
939940-### CC Wrapper
941942The CC Wrapper wraps a C toolchain for a bunch of miscellaneous purposes. Specifically, a C compiler (GCC or Clang), wrapped binary tools, 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 CC Wrapper. Packages typically depend on the CC Wrapper, which in turn (at run-time) depends on the Bintools Wrapper.
943···971972Adds 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.
973974-### teTeX / TeX Live
975976Adds the `share/texmf-nix` subdirectory of each build input to the `TEXINPUTS` environment variable.
977978-### Qt 4
979980Sets the `QTDIR` environment variable to Qt’s path.
981···983984Exports `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).
985986-### GHC
987988Creates a temporary package database and registers every Haskell build input in it (TODO: how?).
989990-### GNOME platform
991992-Hooks related to GNOME platform and related libraries like GLib, GTK and GStreamer are described in <xref linkend="sec-language-gnome" />.
993994### autoPatchelfHook {#setup-hook-autopatchelfhook}
995···10031004The `autoPatchelf` command also recognizes a `--no-recurse` command line flag, which prevents it from recursing into subdirectories.
10051006-### breakpointHook
10071008This 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`.
1009···10131014When a build failure happens there will be an instruction printed that shows how to attach with `cntr` to the build sandbox.
10151016-::: note
1017-::: title
1018Caution with remote builds
1019:::
10201021This 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`.
1022:::
10231024-### installShellFiles
10251026This 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.
1027···1047'';
1048```
10491050-### libiconv, libintl
10511052A 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`.
10531054-### validatePkgConfig
10551056The `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.
10571058-### cmake
10591060Overrides 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.
10611062-### xcbuildHook
10631064Overrides 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.
10651066-### Meson
10671068Overrides 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.
10691070-#### Variables controlling Meson
10711072-##### `mesonFlags`
10731074Controls the flags passed to meson.
10751076-##### `mesonBuildType`
10771078Which [`--buildtype`](https://mesonbuild.com/Builtin-options.html#core-options) to pass to Meson. We default to `plain`.
10791080-##### `mesonAutoFeatures`
10811082What value to set [`-Dauto_features=`](https://mesonbuild.com/Builtin-options.html#core-options) to. We default to `enabled`.
10831084-##### `mesonWrapMode`
10851086What value to set [`-Dwrap_mode=`](https://mesonbuild.com/Builtin-options.html#core-options) to. We default to `nodownload` as we disallow network access.
10871088-##### `dontUseMesonConfigure`
10891090Disables using Meson’s `configurePhase`.
10911092-### ninja
10931094Overrides 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.
10951096-### unzip
10971098This setup hook will allow you to unzip .zip files specified in `$src`. There are many similar packages like `unrar`, `undmg`, etc.
10991100-### wafHook
11011102Overrides 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.
11031104-### scons
11051106Overrides 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.
1107···11191120The following flags are enabled by default and might require disabling with `hardeningDisable` if the program to package is incompatible.
11211122-### `format`
11231124Adds the `-Wformat -Wformat-security -Werror=format-security` compiler options. At present, this warns about calls to `printf` and `scanf` functions where the format string is not a string literal and there are no format arguments, as in `printf(foo);`. This may be a security hole if the format string came from untrusted input and contains `%n`.
1125···1132cc1plus: some warnings being treated as errors
1133```
11341135-### `stackprotector`
11361137Adds the `-fstack-protector-strong --param ssp-buffer-size=4` compiler options. This adds safety checks against stack overwrites rendering many potential code injection attacks into aborting situations. In the best case this turns code injection vulnerabilities into denial of service or into non-issues (depending on the application).
1138···1143/tmp/nix-build-ipxe-20141124-5cbdc41.drv-0/ipxe-5cbdc41/src/arch/i386/firmware/pcbios/bios_console.c:86: undefined reference to `__stack_chk_fail'
1144```
11451146-### `fortify`
11471148Adds the `-O2 -D_FORTIFY_SOURCE=2` compiler options. During code generation the compiler knows a great deal of information about buffer sizes (where possible), and attempts to replace insecure unlimited length buffer function calls with length-limited ones. This is especially useful for old, crufty code. Additionally, format strings in writable memory that contain `%n` are blocked. If an application depends on such a format string, it will need to be worked around.
1149···1164fcntl2.h:50:4: error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments
1165```
11661167-### `pic`
11681169Adds the `-fPIC` compiler options. This options adds support for position independent code in shared libraries and thus making ASLR possible.
1170···1177ccbLfRgg.s:33: Error: missing or invalid displacement expression `private_key_len@GOTOFF'
1178```
11791180-### `strictoverflow`
11811182Signed integer overflow is undefined behaviour according to the C standard. If it happens, it is an error in the program as it should check for overflow before it can happen, not afterwards. GCC provides built-in functions to perform arithmetic with overflow checking, which are correct and faster than any custom implementation. As a workaround, the option `-fno-strict-overflow` makes gcc behave as if signed integer overflows were defined.
11831184This flag should not trigger any build or runtime errors.
11851186-### `relro`
11871188Adds the `-z relro` linker option. During program load, several ELF memory sections need to be written to by the linker, but can be turned read-only before turning over control to the program. This prevents some GOT (and .dtors) overwrite attacks, but at least the part of the GOT used by the dynamic linker (.got.plt) is still vulnerable.
11891190This flag can break dynamic shared object loading. For instance, the module systems of Xorg and OpenCV are incompatible with this flag. In almost all cases the `bindnow` flag must also be disabled and incompatible programs typically fail with similar errors at runtime.
11911192-### `bindnow`
11931194Adds the `-z bindnow` linker option. During program load, all dynamic symbols are resolved, allowing for the complete GOT to be marked read-only (due to `relro`). This prevents GOT overwrite attacks. For very large applications, this can incur some performance loss during initial load while symbols are resolved, but this shouldn’t be an issue for daemons.
1195···12011202The following flags are disabled by default and should be enabled with `hardeningEnable` for packages that take untrusted input like network services.
12031204-### `pie`
12051206Adds the `-fPIE` compiler and `-pie` linker options. Position Independent Executables are needed to take advantage of Address Space Layout Randomization, supported by modern kernel versions. While ASLR can already be enforced for data areas in the stack and heap (brk and mmap), the code areas must be compiled as position-independent. Shared libraries already do this with the `pic` flag, so they gain ASLR automatically, but binary .text regions need to be build with `pie` to gain ASLR. When this happens, ROP attacks are much harder since there are no static locations to bounce off of during a memory corruption attack.
1207
···39}
40```
4142+This attribute ensures that the `bin` subdirectories of these packages appear in the `PATH` environment variable during the build, that their `include` subdirectories are searched by the C compiler, and so on. (See [](#ssec-setup-hooks) for details.)
4344+Often it is necessary to override or modify some aspect of the build. To make this easier, the standard environment breaks the package build into a number of *phases*, all of which can be overridden or modified individually: unpacking the sources, applying patches, configuring, building, and installing. (There are some others; see [](#sec-stdenv-phases).) For instance, a package that doesn’t supply a makefile but instead has to be compiled "manually" could be handled like this:
4546```nix
47stdenv.mkDerivation {
···5960(Note the use of `''`-style string literals, which are very convenient for large multi-line script fragments because they don’t need escaping of `"` and `\`, and because indentation is intelligently removed.)
6162+There are many other attributes to customise the build. These are listed in [](#ssec-stdenv-attributes).
6364While the standard environment provides a generic builder, you can still supply your own build script:
65···116117## Specifying dependencies {#ssec-stdenv-dependencies}
118119+As described in the Nix manual, almost any `*.drv` store path in a derivation’s attribute set will induce a dependency on that derivation. `mkDerivation`, however, takes a few attributes intended to, between them, include all the dependencies of a package. This is done both for structure and consistency, but also so that certain other setup can take place. For example, certain dependencies need their bin directories added to the `PATH`. That is built-in, but other setup is done via a pluggable mechanism that works in conjunction with these dependency attributes. See [](#ssec-setup-hooks) for details.
120121+Dependencies can be broken down along three axes: their host and target platforms relative to the new derivation’s, and whether they are propagated. The platform distinctions are motivated by cross compilation; see [](#chap-cross) for exactly what each platform means. [^footnote-stdenv-ignored-build-platform] But even if one is not cross compiling, the platforms imply whether or not the dependency is needed at run-time or build-time, a concept that makes perfect sense outside of cross compilation. By default, the run-time/build-time distinction is just a hint for mental clarity, but with `strictDeps` set it is mostly enforced even in the native case.
122123The extension of `PATH` with dependencies, alluded to above, proceeds according to the relative platforms alone. The process is carried out only for dependencies whose host platform matches the new derivation’s build platform i.e. dependencies which run on the platform where the new derivation will be built. [^footnote-stdenv-native-dependencies-in-path] For each dependency \<dep\> of those dependencies, `dep/bin`, if present, is added to the `PATH` environment variable.
124···175176Overall, the unifying theme here is that propagation shouldn’t be introducing transitive dependencies involving platforms the depending package is unaware of. \[One can imagine the dependending package asking for dependencies with the platforms it knows about; other platforms it doesn’t know how to ask for. The platform description in that scenario is a kind of unforagable capability.\] The offset bounds checking and definition of `mapOffset` together ensure that this is the case. Discovering a new offset is discovering a new platform, and since those platforms weren’t in the derivation “spec” of the needing package, they cannot be relevant. From a capability perspective, we can imagine that the host and target platforms of a package are the capabilities a package requires, and the depending package must provide the capability to the dependency.
177178+### Variables specifying dependencies {#variables-specifying-dependencies}
179+180#### `depsBuildBuild` {#var-stdenv-depsBuildBuild}
181182A list of dependencies whose host and target platforms are the new derivation’s build platform. This means a `-1` host and `-1` target offset from the new derivation’s platforms. These are programs and libraries used at build time that produce programs and libraries also used at build time. If the dependency doesn’t care about the target platform (i.e. isn’t a compiler or similar tool), put it in `nativeBuildInputs` instead. The most common use of this `buildPackages.stdenv.cc`, the default C compiler for this role. That example crops up more than one might think in old commonly used C libraries.
···237238## Attributes {#ssec-stdenv-attributes}
239240+### Variables affecting `stdenv` initialisation {#variables-affecting-stdenv-initialisation}
241242#### `NIX_DEBUG` {#var-stdenv-NIX_DEBUG}
243244A natural number indicating how much information to log. If set to 1 or higher, `stdenv` will print moderate debugging information during the build. In particular, the `gcc` and `ld` wrapper scripts will print out the complete command line passed to the wrapped tools. If set to 6 or higher, the `stdenv` setup script will be run with `set -x` tracing. If set to 7 or higher, the `gcc` and `ld` wrapper scripts will also be run with `set -x` tracing.
245246+### Attributes affecting build properties {#attributes-affecting-build-properties}
247248#### `enableParallelBuilding` {#var-stdenv-enableParallelBuilding}
249···251252Unless set to `false`, some build systems with good support for parallel building including `cmake`, `meson`, and `qmake` will set it to `true`.
253254+### Special variables {#special-variables}
255256#### `passthru` {#var-stdenv-passthru}
257···299300The script will be run with `UPDATE_NIX_ATTR_PATH` environment variable set to the attribute path it is supposed to update.
301302+::: {.note}
303The script will be usually run from the root of the Nixpkgs repository but you should not rely on that. Also note that the update scripts will be run in parallel by default; you should avoid running `git commit` or any other commands that cannot handle that.
304:::
305···315316There are a number of variables that control what phases are executed and in what order:
317318+#### Variables affecting phase control {#variables-affecting-phase-control}
319320##### `phases` {#var-stdenv-phases}
321···355356The unpack phase is responsible for unpacking the source code of the package. The default implementation of `unpackPhase` unpacks the source files listed in the `src` environment variable to the current directory. It supports the following files by default:
357358+#### Tar files {#tar-files}
359360These can optionally be compressed using `gzip` (`.tar.gz`, `.tgz` or `.tar.Z`), `bzip2` (`.tar.bz2`, `.tbz2` or `.tbz`) or `xz` (`.tar.xz`, `.tar.lzma` or `.txz`).
361362+#### Zip files {#zip-files}
363364Zip files are unpacked using `unzip`. However, `unzip` is not in the standard environment, so you should add it to `nativeBuildInputs` yourself.
365366+#### Directories in the Nix store {#directories-in-the-nix-store}
367368These are simply copied to the current directory. The hash part of the file name is stripped, e.g. `/nix/store/1wydxgby13cz...-my-sources` would be copied to `my-sources`.
369370Additional file types can be supported by setting the `unpackCmd` variable (see below).
371372+#### Variables controlling the unpack phase {#variables-controlling-the-unpack-phase}
373+374##### `srcs` / `src` {#var-stdenv-src}
375376The list of source files or directories to be unpacked or copied. One of these must be set.
···407408The patch phase applies the list of patches defined in the `patches` variable.
409410+#### Variables controlling the patch phase {#variables-controlling-the-patch-phase}
411412##### `dontPatch` {#var-stdenv-dontPatch}
413···433434The configure phase prepares the source tree for building. The default `configurePhase` runs `./configure` (typically an Autoconf-generated script) if it exists.
435436+#### Variables controlling the configure phase {#variables-controlling-the-configure-phase}
437438##### `configureScript` {#var-stdenv-configureScript}
439···493494The build phase is responsible for actually building the package (e.g. compiling it). The default `buildPhase` simply calls `make` if a file named `Makefile`, `makefile` or `GNUmakefile` exists in the current directory (or the `makefile` is explicitly set); otherwise it does nothing.
495496+#### Variables controlling the build phase {#variables-controlling-the-build-phase}
497498##### `dontBuild` {#var-stdenv-dontBuild}
499···511makeFlags = [ "PREFIX=$(out)" ];
512```
513514+::: {.note}
515The flags are quoted in bash, but environment variables can be specified by using the make syntax.
516:::
517···547548The check phase checks whether the package was built correctly by running its test suite. The default `checkPhase` calls `make check`, but only if the `doCheck` variable is enabled.
549550+#### Variables controlling the check phase {#variables-controlling-the-check-phase}
551552##### `doCheck` {#var-stdenv-doCheck}
553···559560in the derivation to enable checks. The exception is cross compilation. Cross compiled builds never run tests, no matter how `doCheck` is set, as the newly-built program won’t run on the platform used to build it.
561562+##### `makeFlags` / `makeFlagsArray` / `makefile` {#makeflags-makeflagsarray-makefile}
563564See the [build phase](#var-stdenv-makeFlags) for details.
565···587588The install phase is responsible for installing the package in the Nix store under `out`. The default `installPhase` creates the directory `$out` and calls `make install`.
589590+#### Variables controlling the install phase {#variables-controlling-the-install-phase}
591592##### `dontInstall` {#var-stdenv-dontInstall}
593594Set to true to skip the install phase.
595596+##### `makeFlags` / `makeFlagsArray` / `makefile` {#makeflags-makeflagsarray-makefile-1}
597598See the [build phase](#var-stdenv-makeFlags) for details.
599···626- On Linux, it applies the `patchelf` command to ELF executables and libraries to remove unused directories from the `RPATH` in order to prevent unnecessary runtime dependencies.
627- It rewrites the interpreter paths of shell scripts to paths found in `PATH`. E.g., `/usr/bin/perl` will be rewritten to `/nix/store/some-perl/bin/perl` found in `PATH`.
628629+#### Variables controlling the fixup phase {#variables-controlling-the-fixup-phase}
630631##### `dontFixup` {#var-stdenv-dontFixup}
632···708709The installCheck phase checks whether the package was installed correctly by running its test suite against the installed directories. The default `installCheck` calls `make installcheck`.
710711+#### Variables controlling the installCheck phase {#variables-controlling-the-installcheck-phase}
712713##### `doInstallCheck` {#var-stdenv-doInstallCheck}
714···744745The distribution phase is intended to produce a source distribution of the package. The default `distPhase` first calls `make dist`, then it copies the resulting source tarballs to `$out/tarballs/`. This phase is only executed if the attribute `doDist` is set.
746747+#### Variables controlling the distribution phase {#variables-controlling-the-distribution-phase}
748749##### `distTarget` {#var-stdenv-distTarget}
750···881882Packages adding a hook should not hard code a specific hook, but rather choose a variable *relative* to how they are included. Returning to the C compiler wrapper example, if the wrapper itself is an `n` dependency, then it only wants to accumulate flags from `n + 1` dependencies, as only those ones match the compiler’s target platform. The `hostOffset` variable is defined with the current dependency’s host offset `targetOffset` with its target offset, before its setup hook is sourced. Additionally, since most environment hooks don’t care about the target platform, that means the setup hook can append to the right bash array by doing something like
883884+```bash
885addEnvHooks "$hostOffset" myBashFunction
886```
887···889890First, 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`. Some of these are platform specific, so they may run on Linux but not Darwin or vice-versa.
891892+### `move-docs.sh` {#move-docs.sh}
893894This 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.
895896+### `compress-man-pages.sh` {#compress-man-pages.sh}
897898This 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.
899900+### `strip.sh` {#strip.sh}
901902This 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.
903904+### `patch-shebangs.sh` {#patch-shebangs.sh}
905906This setup hook patches installed scripts to use the full path to the shebang interpreter. A shebang interpreter is the first commented line of a script telling the operating system which program will run the script (e.g `#!/bin/bash`). In Nix, we want an exact path to that interpreter to be used. This often replaces `/bin/sh` with a path in the Nix store.
907908+### `audit-tmpdir.sh` {#audit-tmpdir.sh}
909910This 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.
911912+### `multiple-outputs.sh` {#multiple-outputs.sh}
913914+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.
915916+### `move-sbin.sh` {#move-sbin.sh}
917918This setup hook moves any binaries installed in the `sbin/` subdirectory into `bin/`. In addition, a link is provided from `sbin/` to `bin/` for compatibility.
919920+### `move-lib64.sh` {#move-lib64.sh}
921922This setup hook moves any libraries installed in the `lib64/` subdirectory into `lib/`. In addition, a link is provided from `lib64/` to `lib/` for compatibility.
923924+### `move-systemd-user-units.sh` {#move-systemd-user-units.sh}
925926This 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.
927928+### `set-source-date-epoch-to-latest.sh` {#set-source-date-epoch-to-latest.sh}
929930This sets `SOURCE_DATE_EPOCH` to the modification time of the most recent file.
931932+### Bintools Wrapper {#bintools-wrapper}
933934The 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.
935···939940A problem with this final task is that the Bintools Wrapper is honest and defines `LD` as `ld`. Most packages, however, firstly use the C compiler for linking, secondly use `LD` anyways, defining it as the C compiler, and thirdly, only so define `LD` when it is undefined as a fallback. This triple-threat means Bintools Wrapper will break those packages, as LD is already defined as the actual linker which the package won’t override yet doesn’t want to use. The workaround is to define, just for the problematic package, `LD` as the C compiler. A good way to do this would be `preConfigure = "LD=$CC"`.
941942+### CC Wrapper {#cc-wrapper}
943944The CC Wrapper wraps a C toolchain for a bunch of miscellaneous purposes. Specifically, a C compiler (GCC or Clang), wrapped binary tools, 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 CC Wrapper. Packages typically depend on the CC Wrapper, which in turn (at run-time) depends on the Bintools Wrapper.
945···973974Adds 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.
975976+### teTeX / TeX Live {#tetex-tex-live}
977978Adds the `share/texmf-nix` subdirectory of each build input to the `TEXINPUTS` environment variable.
979980+### Qt 4 {#qt-4}
981982Sets the `QTDIR` environment variable to Qt’s path.
983···985986Exports `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).
987988+### GHC {#ghc}
989990Creates a temporary package database and registers every Haskell build input in it (TODO: how?).
991992+### GNOME platform {#gnome-platform}
993994+Hooks related to GNOME platform and related libraries like GLib, GTK and GStreamer are described in [](#sec-language-gnome).
995996### autoPatchelfHook {#setup-hook-autopatchelfhook}
997···10051006The `autoPatchelf` command also recognizes a `--no-recurse` command line flag, which prevents it from recursing into subdirectories.
10071008+### breakpointHook {#breakpointhook}
10091010This 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`.
1011···10151016When a build failure happens there will be an instruction printed that shows how to attach with `cntr` to the build sandbox.
10171018+::: {.note}
1019+::: {.title}
1020Caution with remote builds
1021:::
10221023This 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`.
1024:::
10251026+### installShellFiles {#installshellfiles}
10271028This 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.
1029···1049'';
1050```
10511052+### libiconv, libintl {#libiconv-libintl}
10531054A 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`.
10551056+### validatePkgConfig {#validatepkgconfig}
10571058The `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.
10591060+### cmake {#cmake}
10611062Overrides 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.
10631064+### xcbuildHook {#xcbuildhook}
10651066Overrides 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.
10671068+### Meson {#meson}
10691070Overrides 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.
10711072+#### Variables controlling Meson {#variables-controlling-meson}
10731074+##### `mesonFlags` {#mesonflags}
10751076Controls the flags passed to meson.
10771078+##### `mesonBuildType` {#mesonbuildtype}
10791080Which [`--buildtype`](https://mesonbuild.com/Builtin-options.html#core-options) to pass to Meson. We default to `plain`.
10811082+##### `mesonAutoFeatures` {#mesonautofeatures}
10831084What value to set [`-Dauto_features=`](https://mesonbuild.com/Builtin-options.html#core-options) to. We default to `enabled`.
10851086+##### `mesonWrapMode` {#mesonwrapmode}
10871088What value to set [`-Dwrap_mode=`](https://mesonbuild.com/Builtin-options.html#core-options) to. We default to `nodownload` as we disallow network access.
10891090+##### `dontUseMesonConfigure` {#dontusemesonconfigure}
10911092Disables using Meson’s `configurePhase`.
10931094+### ninja {#ninja}
10951096Overrides 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.
10971098+### unzip {#unzip}
10991100This setup hook will allow you to unzip .zip files specified in `$src`. There are many similar packages like `unrar`, `undmg`, etc.
11011102+### wafHook {#wafhook}
11031104Overrides 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.
11051106+### scons {#scons}
11071108Overrides 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.
1109···11211122The following flags are enabled by default and might require disabling with `hardeningDisable` if the program to package is incompatible.
11231124+### `format` {#format}
11251126Adds the `-Wformat -Wformat-security -Werror=format-security` compiler options. At present, this warns about calls to `printf` and `scanf` functions where the format string is not a string literal and there are no format arguments, as in `printf(foo);`. This may be a security hole if the format string came from untrusted input and contains `%n`.
1127···1134cc1plus: some warnings being treated as errors
1135```
11361137+### `stackprotector` {#stackprotector}
11381139Adds the `-fstack-protector-strong --param ssp-buffer-size=4` compiler options. This adds safety checks against stack overwrites rendering many potential code injection attacks into aborting situations. In the best case this turns code injection vulnerabilities into denial of service or into non-issues (depending on the application).
1140···1145/tmp/nix-build-ipxe-20141124-5cbdc41.drv-0/ipxe-5cbdc41/src/arch/i386/firmware/pcbios/bios_console.c:86: undefined reference to `__stack_chk_fail'
1146```
11471148+### `fortify` {#fortify}
11491150Adds the `-O2 -D_FORTIFY_SOURCE=2` compiler options. During code generation the compiler knows a great deal of information about buffer sizes (where possible), and attempts to replace insecure unlimited length buffer function calls with length-limited ones. This is especially useful for old, crufty code. Additionally, format strings in writable memory that contain `%n` are blocked. If an application depends on such a format string, it will need to be worked around.
1151···1166fcntl2.h:50:4: error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments
1167```
11681169+### `pic` {#pic}
11701171Adds the `-fPIC` compiler options. This options adds support for position independent code in shared libraries and thus making ASLR possible.
1172···1179ccbLfRgg.s:33: Error: missing or invalid displacement expression `private_key_len@GOTOFF'
1180```
11811182+### `strictoverflow` {#strictoverflow}
11831184Signed integer overflow is undefined behaviour according to the C standard. If it happens, it is an error in the program as it should check for overflow before it can happen, not afterwards. GCC provides built-in functions to perform arithmetic with overflow checking, which are correct and faster than any custom implementation. As a workaround, the option `-fno-strict-overflow` makes gcc behave as if signed integer overflows were defined.
11851186This flag should not trigger any build or runtime errors.
11871188+### `relro` {#relro}
11891190Adds the `-z relro` linker option. During program load, several ELF memory sections need to be written to by the linker, but can be turned read-only before turning over control to the program. This prevents some GOT (and .dtors) overwrite attacks, but at least the part of the GOT used by the dynamic linker (.got.plt) is still vulnerable.
11911192This flag can break dynamic shared object loading. For instance, the module systems of Xorg and OpenCV are incompatible with this flag. In almost all cases the `bindnow` flag must also be disabled and incompatible programs typically fail with similar errors at runtime.
11931194+### `bindnow` {#bindnow}
11951196Adds the `-z bindnow` linker option. During program load, all dynamic symbols are resolved, allowing for the complete GOT to be marked read-only (due to `relro`). This prevents GOT overwrite attacks. For very large applications, this can incur some performance loss during initial load while symbols are resolved, but this shouldn’t be an issue for daemons.
1197···12031204The following flags are disabled by default and should be enabled with `hardeningEnable` for packages that take untrusted input like network services.
12051206+### `pie` {#pie}
12071208Adds the `-fPIE` compiler and `-pie` linker options. Position Independent Executables are needed to take advantage of Address Space Layout Randomization, supported by modern kernel versions. While ASLR can already be enforced for data areas in the stack and heap (brk and mmap), the code areas must be compiled as position-independent. Shared libraries already do this with the `pic` flag, so they gain ASLR automatically, but binary .text regions need to be build with `pie` to gain ASLR. When this happens, ROP attacks are much harder since there are no static locations to bounce off of during a memory corruption attack.
1209
+1-1
doc/using/overlays.chapter.md
···6364The value returned by this function should be a set similar to `pkgs/top-level/all-packages.nix`, containing overridden and/or new packages.
6566-Overlays are similar to other methods for customizing Nixpkgs, in particular the `packageOverrides` attribute described in <xref linkend="sec-modify-via-packageOverrides"/>. Indeed, `packageOverrides` acts as an overlay with only the `super` argument. It is therefore appropriate for basic use, but overlays are more powerful and easier to distribute.
6768## Using overlays to configure alternatives {#sec-overlays-alternatives}
69
···6364The value returned by this function should be a set similar to `pkgs/top-level/all-packages.nix`, containing overridden and/or new packages.
6566+Overlays are similar to other methods for customizing Nixpkgs, in particular the `packageOverrides` attribute described in [](#sec-modify-via-packageOverrides). Indeed, `packageOverrides` acts as an overlay with only the `super` argument. It is therefore appropriate for basic use, but overlays are more powerful and easier to distribute.
6768## Using overlays to configure alternatives {#sec-overlays-alternatives}
69
+6-6
doc/using/overrides.chapter.md
···4849The argument `oldAttrs` is conventionally used to refer to the attr set originally passed to `stdenv.mkDerivation`.
5051-::: note
52-Note that `separateDebugInfo` is processed only by the `stdenv.mkDerivation` function, not the generated, raw Nix derivation. Thus, using `overrideDerivation` will not work in this case, as it overrides only the attributes of the final derivation. It is for this reason that `overrideAttrs` should be preferred in (almost) all cases to `overrideDerivation`, i.e. to allow using `stdenv.mkDerivation` to process input arguments, as well as the fact that it is easier to use (you can use the same attribute names you see in your Nix code, instead of the ones generated (e.g. `buildInputs` vs `nativeBuildInputs`), and it involves less typing).
53:::
5455## <pkg>.overrideDerivation {#sec-pkg-overrideDerivation}
5657-::: warning
58You should prefer `overrideAttrs` in almost all cases, see its documentation for the reasons why. `overrideDerivation` is not deprecated and will continue to work, but is less nice to use and does not have as many abilities as `overrideAttrs`.
59:::
6061-::: warning
62Do not use this function in Nixpkgs as it evaluates a Derivation before modifying it, which breaks package abstraction and removes error-checking of function arguments. In addition, this evaluation-per-function application incurs a performance penalty, which can become a problem if many overrides are used. It is only intended for ad-hoc customisation, such as in `~/.config/nixpkgs/config.nix`.
63:::
64···8182The argument `oldAttrs` is used to refer to the attribute set of the original derivation.
8384-::: note
85-A package's attributes are evaluated *before* being modified by the `overrideDerivation` function. For example, the `name` attribute reference in `url = "mirror://gnu/hello/${name}.tar.gz";` is filled-in *before* the `overrideDerivation` function modifies the attribute set. This means that overriding the `name` attribute, in this example, *will not* change the value of the `url` attribute. Instead, we need to override both the `name` *and* `url` attributes.
86:::
8788## lib.makeOverridable {#sec-lib-makeOverridable}
···4849The argument `oldAttrs` is conventionally used to refer to the attr set originally passed to `stdenv.mkDerivation`.
5051+::: {.note}
52+Note that `separateDebugInfo` is processed only by the `stdenv.mkDerivation` function, not the generated, raw Nix derivation. Thus, using `overrideDerivation` will not work in this case, as it overrides only the attributes of the final derivation. It is for this reason that `overrideAttrs` should be preferred in (almost) all cases to `overrideDerivation`, i.e. to allow using `stdenv.mkDerivation` to process input arguments, as well as the fact that it is easier to use (you can use the same attribute names you see in your Nix code, instead of the ones generated (e.g. `buildInputs` vs `nativeBuildInputs`), and it involves less typing).
53:::
5455## <pkg>.overrideDerivation {#sec-pkg-overrideDerivation}
5657+::: {.warning}
58You should prefer `overrideAttrs` in almost all cases, see its documentation for the reasons why. `overrideDerivation` is not deprecated and will continue to work, but is less nice to use and does not have as many abilities as `overrideAttrs`.
59:::
6061+::: {.warning}
62Do not use this function in Nixpkgs as it evaluates a Derivation before modifying it, which breaks package abstraction and removes error-checking of function arguments. In addition, this evaluation-per-function application incurs a performance penalty, which can become a problem if many overrides are used. It is only intended for ad-hoc customisation, such as in `~/.config/nixpkgs/config.nix`.
63:::
64···8182The argument `oldAttrs` is used to refer to the attribute set of the original derivation.
8384+::: {.note}
85+A package's attributes are evaluated *before* being modified by the `overrideDerivation` function. For example, the `name` attribute reference in `url = "mirror://gnu/hello/${name}.tar.gz";` is filled-in *before* the `overrideDerivation` function modifies the attribute set. This means that overriding the `name` attribute, in this example, *will not* change the value of the `url` attribute. Instead, we need to override both the `name` *and* `url` attributes.
86:::
8788## lib.makeOverridable {#sec-lib-makeOverridable}
···24 </section>
25 <section xml:id="new-services">
26 <title>New Services</title>
27- <itemizedlist spacing="compact">
28 <listitem>
29 <para>
30 <link xlink:href="https://github.com/maxmind/geoipupdate">geoipupdate</link>,
31 a GeoIP database updater from MaxMind. Available as
32 <link xlink:href="options.html#opt-services.geoipupdate.enable">services.geoipupdate</link>.
0000000033 </para>
34 </listitem>
35 </itemizedlist>
···24 </section>
25 <section xml:id="new-services">
26 <title>New Services</title>
27+ <itemizedlist>
28 <listitem>
29 <para>
30 <link xlink:href="https://github.com/maxmind/geoipupdate">geoipupdate</link>,
31 a GeoIP database updater from MaxMind. Available as
32 <link xlink:href="options.html#opt-services.geoipupdate.enable">services.geoipupdate</link>.
33+ </para>
34+ </listitem>
35+ <listitem>
36+ <para>
37+ <link xlink:href="https://sr.ht">sourcehut</link>, a
38+ collection of tools useful for software development. Available
39+ as
40+ <link xlink:href="options.html#opt-services.sourcehut.enable">services.sourcehut</link>.
41 </para>
42 </listitem>
43 </itemizedlist>
+4
nixos/doc/manual/release-notes/rl-2111.section.md
···14 database updater from MaxMind. Available as
15 [services.geoipupdate](options.html#opt-services.geoipupdate.enable).
16000017## Backward Incompatibilities
1819* The `staticjinja` package has been upgraded from 1.0.4 to 2.0.0
···14 database updater from MaxMind. Available as
15 [services.geoipupdate](options.html#opt-services.geoipupdate.enable).
1617+* [sourcehut](https://sr.ht), a collection of tools useful for software
18+ development. Available as
19+ [services.sourcehut](options.html#opt-services.sourcehut.enable).
20+21## Backward Incompatibilities
2223* The `staticjinja` package has been upgraded from 1.0.4 to 2.0.0
+7
nixos/modules/virtualisation/libvirtd.nix
···155156 config = mkIf cfg.enable {
1570000000158 environment = {
159 # this file is expected in /etc/qemu and not sysconfdir (/var/lib)
160 etc."qemu/bridge.conf".text = lib.concatMapStringsSep "\n" (e:
···155156 config = mkIf cfg.enable {
157158+ assertions = [
159+ {
160+ assertion = config.security.polkit.enable;
161+ message = "The libvirtd module currently requires Polkit to be enabled ('security.polkit.enable = true').";
162+ }
163+ ];
164+165 environment = {
166 # this file is expected in /etc/qemu and not sysconfdir (/var/lib)
167 etc."qemu/bridge.conf".text = lib.concatMapStringsSep "\n" (e:
+2
pkgs/applications/editors/neovim/utils.nix
···148 , vimAlias ? false
149 , viAlias ? false
150 , configure ? {}
0151 }:
152 let
153 /* for compatibility with passing extraPythonPackages as a list; added 2018-07-11 */
···160 extraPython3Packages = compatFun extraPython3Packages;
161 inherit withNodeJs withRuby viAlias vimAlias;
162 inherit configure;
0163 };
164 in
165 assert withPython -> throw "Python2 support has been removed from neovim, please remove withPython and extraPythonPackages.";
···148 , vimAlias ? false
149 , viAlias ? false
150 , configure ? {}
151+ , extraName ? ""
152 }:
153 let
154 /* for compatibility with passing extraPythonPackages as a list; added 2018-07-11 */
···161 extraPython3Packages = compatFun extraPython3Packages;
162 inherit withNodeJs withRuby viAlias vimAlias;
163 inherit configure;
164+ inherit extraName;
165 };
166 in
167 assert withPython -> throw "Python2 support has been removed from neovim, please remove withPython and extraPythonPackages.";
+16-12
pkgs/applications/editors/neovim/wrapper.nix
···27 # set to false if you want to control where to save the generated config
28 # (e.g., in ~/.config/init.vim or project/.nvimrc)
29 , wrapRc ? true
030 , ...
31 }@args:
32 let
3334 wrapperArgsStr = if isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs;
3536- # If configure != {}, we can't generate the rplugin.vim file with e.g
37- # NVIM_SYSTEM_RPLUGIN_MANIFEST *and* NVIM_RPLUGIN_MANIFEST env vars set in
38- # the wrapper. That's why only when configure != {} (tested both here and
39- # when postBuild is evaluated), we call makeWrapper once to generate a
40- # wrapper with most arguments we need, excluding those that cause problems to
41- # generate rplugin.vim, but still required for the final wrapper.
42- finalMakeWrapperArgs =
43- [ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim" ]
44- ++ [ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ]
45- ++ optionals wrapRc [ "--add-flags" "-u ${writeText "init.vim" args.neovimRcContent}" ]
46- ;
47 in
48 assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env.";
49···116 preferLocalBuild = true;
117118 nativeBuildInputs = [ makeWrapper ];
119- passthru = { unwrapped = neovim; };
000120121 meta = neovim.meta // {
122 # To prevent builds on hydra
···27 # set to false if you want to control where to save the generated config
28 # (e.g., in ~/.config/init.vim or project/.nvimrc)
29 , wrapRc ? true
30+ , neovimRcContent ? ""
31 , ...
32 }@args:
33 let
3435 wrapperArgsStr = if isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs;
3637+ # If configure != {}, we can't generate the rplugin.vim file with e.g
38+ # NVIM_SYSTEM_RPLUGIN_MANIFEST *and* NVIM_RPLUGIN_MANIFEST env vars set in
39+ # the wrapper. That's why only when configure != {} (tested both here and
40+ # when postBuild is evaluated), we call makeWrapper once to generate a
41+ # wrapper with most arguments we need, excluding those that cause problems to
42+ # generate rplugin.vim, but still required for the final wrapper.
43+ finalMakeWrapperArgs =
44+ [ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim" ]
45+ ++ [ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ]
46+ ++ optionals wrapRc [ "--add-flags" "-u ${writeText "init.vim" neovimRcContent}" ]
47+ ;
48 in
49 assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env.";
50···117 preferLocalBuild = true;
118119 nativeBuildInputs = [ makeWrapper ];
120+ passthru = {
121+ unwrapped = neovim;
122+ initRc = neovimRcContent;
123+ };
124125 meta = neovim.meta // {
126 # To prevent builds on hydra
···14 if libc == null then
15 null
16 else if stdenvNoCC.targetPlatform.isNetBSD then
17- if libc != targetPackages.netbsdCross.headers then
0018 targetPackages.netbsdCross.ld_elf_so
19 else
20 null
···14 if libc == null then
15 null
16 else if stdenvNoCC.targetPlatform.isNetBSD then
17+ if !(targetPackages ? netbsdCross) then
18+ netbsd.ld_elf_so
19+ else if libc != targetPackages.netbsdCross.headers then
20 targetPackages.netbsdCross.ld_elf_so
21 else
22 null