···20202121`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.
22222323-2423Other 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`.
25242626-## `fetchsvn`
2525+## `fetchsvn` {#fetchsvn}
27262827Used with Subversion. Expects `url` to a Subversion directory, `rev`, and `sha256`.
29283030-## `fetchgit`
2929+## `fetchgit` {#fetchgit}
31303231Used 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`.
33323433Additionally 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.
35343636-## `fetchfossil`
3535+## `fetchfossil` {#fetchfossil}
37363837Used with Fossil. Expects `url` to a Fossil archive, `rev`, and `sha256`.
39384040-## `fetchcvs`
3939+## `fetchcvs` {#fetchcvs}
41404241Used with CVS. Expects `cvsRoot`, `tag`, and `sha256`.
43424444-## `fetchhg`
4343+## `fetchhg` {#fetchhg}
45444645Used with Mercurial. Expects `url`, `rev`, and `sha256`.
47464847A 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.
49485050-## `fetchFromGitHub`
4949+## `fetchFromGitHub` {#fetchfromgithub}
51505251`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.
53525453`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.
55545656-## `fetchFromGitLab`
5555+## `fetchFromGitLab` {#fetchfromgitlab}
57565857This is used with GitLab repositories. The arguments expected are very similar to fetchFromGitHub above.
59586060-## `fetchFromGitiles`
5959+## `fetchFromGitiles` {#fetchfromgitiles}
61606261This is used with Gitiles repositories. The arguments expected are similar to fetchgit.
63626464-## `fetchFromBitbucket`
6363+## `fetchFromBitbucket` {#fetchfrombitbucket}
65646665This is used with BitBucket repositories. The arguments expected are very similar to fetchFromGitHub above.
67666868-## `fetchFromSavannah`
6767+## `fetchFromSavannah` {#fetchfromsavannah}
69687069This is used with Savannah repositories. The arguments expected are very similar to fetchFromGitHub above.
71707272-## `fetchFromRepoOrCz`
7171+## `fetchFromRepoOrCz` {#fetchfromrepoorcz}
73727473This is used with repo.or.cz repositories. The arguments expected are very similar to fetchFromGitHub above.
75747676-## `fetchFromSourcehut`
7575+## `fetchFromSourcehut` {#fetchfromsourcehut}
77767877This 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
···2233`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.
4455-::: warning
55+::: {.warning}
66The `appimageTools` API is unstable and may be subject to backwards-incompatible changes in the future.
77:::
88
+2-2
doc/builders/images/dockertools.section.md
···11# pkgs.dockerTools {#sec-pkgs-dockerTools}
2233-`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.
33+`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.
4455## buildImage {#ssec-pkgs-dockerTools-buildImage}
66···52525353> **_NOTE:_** Using this parameter requires the `kvm` device to be available.
54545555-- `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).
5555+- `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).
56565757After 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.
5858
+2-2
doc/builders/images/snaptools.section.md
···14141515The following expression packages GNU Hello as a Snapcraft snap.
16161717-```{#ex-snapTools-buildSnap-hello .nix}
1717+``` {#ex-snapTools-buildSnap-hello .nix}
1818let
1919 inherit (import <nixpkgs> { }) snapTools hello;
2020in snapTools.makeSnap {
···35353636Graphical 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.
37373838-```{#ex-snapTools-buildSnap-firefox .nix}
3838+``` {#ex-snapTools-buildSnap-firefox .nix}
3939let
4040 inherit (import <nixpkgs> { }) snapTools firefox;
4141in snapTools.makeSnap {
+3-3
doc/builders/packages/cataclysm-dda.section.md
···11# Cataclysm: Dark Days Ahead {#cataclysm-dark-days-ahead}
2233-## How to install Cataclysm DDA
33+## How to install Cataclysm DDA {#how-to-install-cataclysm-dda}
4455To install the latest stable release of Cataclysm DDA to your profile, execute
66`nix-env -f "<nixpkgs>" -iA cataclysm-dda`. For the curses build (build
···3434}
3535```
36363737-## Important note for overriding packages
3737+## Important note for overriding packages {#important-note-for-overriding-packages}
38383939After applying `overrideAttrs`, you need to fix `passthru.pkgs` and
4040`passthru.withMods` attributes either manually or by using `attachPkgs`:
···6969goodExample2.withMods (_: []) # parallel building enabled
7070```
71717272-## Customizing with mods
7272+## Customizing with mods {#customizing-with-mods}
73737474To install Cataclysm DDA with mods of your choice, you can use `withMods`
7575attribute:
+1-1
doc/builders/packages/elm.section.md
···66nix-shell -p elmPackages.elm elmPackages.elm-format
77```
8899-To update the Elm compiler, see <filename>nixpkgs/pkgs/development/compilers/elm/README.md</filename>.
99+To update the Elm compiler, see `nixpkgs/pkgs/development/compilers/elm/README.md`.
10101111To package Elm applications, [read about elm2nix](https://github.com/hercules-ci/elm2nix#elm2nix).
+1-1
doc/builders/packages/firefox.section.md
···11# Firefox {#sec-firefox}
2233-## Build wrapped Firefox with extensions and policies
33+## Build wrapped Firefox with extensions and policies {#build-wrapped-firefox-with-extensions-and-policies}
4455The `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:
66
+2-2
doc/builders/packages/opengl.section.md
···4455Broadly, we support both GL vendors: Mesa and NVIDIA.
6677-## NixOS Desktop
77+## NixOS Desktop {#nixos-desktop}
8899The 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.
10101111-## Nix on GNU/Linux
1111+## Nix on GNU/Linux {#nix-on-gnulinux}
12121313If 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.
1414
+13-10
doc/builders/packages/steam.section.md
···2020## Troubleshooting {#sec-steam-troub}
21212222- **Steam fails to start. What do I do?**
2323+2324 Try to run
24252526 ```ShellSession
···32333334 - The `newStdcpp` parameter was removed since NixOS 17.09 and should not be needed anymore.
3435 - 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
3636+3537 ```
3638 steam.sh: line 713: 7842 Segmentation fault (core dumped)
3739 ```
4040+3841 have a look at [this pull request](https://github.com/NixOS/nixpkgs/pull/20269).
39424043- **Java**
41444245 1. There is no java in steam chrootenv by default. If you get a message like
43464444- ```
4545- /home/foo/.local/share/Steam/SteamApps/common/towns/towns.sh: line 1: java: command not found
4646- ```
4747+ ```
4848+ /home/foo/.local/share/Steam/SteamApps/common/towns/towns.sh: line 1: java: command not found
4949+ ```
47504848- You need to add
5151+ you need to add
49525050- ```nix
5151- steam.override { withJava = true; };
5252- ```
5353+ ```nix
5454+ steam.override { withJava = true; };
5555+ ```
53565457## steam-run {#sec-steam-run}
5558···57605861```nix
5962pkgs.steam.override ({
6060- nativeOnly = true;
6161- newStdcpp = true;
6262- }).run
6363+ nativeOnly = true;
6464+ newStdcpp = true;
6565+}).run
6366```
64676568to your configuration, rebuild, and run the game with
+4-4
doc/builders/packages/xorg.section.md
···2233The 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.
4455-## Katamari Tarballs
55+## Katamari Tarballs {#katamari-tarballs}
6677X.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:
88···1414 | sort > "tarballs-$release.list"
1515```
16161717-## Individual Tarballs
1717+## Individual Tarballs {#individual-tarballs}
18181919The 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`.
20202121-## Generating Nix Expressions
2121+## Generating Nix Expressions {#generating-nix-expressions}
22222323The generator is invoked as follows:
2424···29293030For 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.)
31313232-## Overriding the Generator
3232+## Overriding the Generator {#overriding-the-generator}
33333434If 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
···37373838Variant 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.
39394040-::: note
4040+::: {.note}
4141This 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`.
4242:::
4343
+4-4
doc/contributing/coding-conventions.chapter.md
···6677- 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.
8899-- 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"/>.
99+- 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).
10101111- Function calls with attribute set arguments are written as
1212···209209210210- 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.
211211212212-- 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" />
212212+- 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)
213213214214## File naming and organisation {#sec-organisation}
215215···462462463463 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.
464464465465- 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.
465465+ 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.
466466467467-::: warning
467467+::: {.warning}
468468This method has security problems. Check below for details.
469469:::
470470
···11# Contributing to this documentation {#chap-contributing}
2233-The DocBook sources of the Nixpkgs manual are in the [doc](https://github.com/NixOS/nixpkgs/tree/master/doc) subdirectory of the Nixpkgs repository.
33+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).
4455You can quickly check your edits with `make`:
66···2222```
23232424If the build succeeds, the manual will be in `./result/share/doc/nixpkgs/manual.html`.
2525+2626+## Syntax {#sec-contributing-markup}
2727+2828+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.
2929+3030+Additionally, the following syntax extensions are currently used:
3131+3232+- []{#ssec-contributing-markup-anchors}
3333+ 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).
3434+3535+ It uses the widely compatible [header attributes](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/attributes.md) syntax:
3636+3737+ ```markdown
3838+ ## Syntax {#sec-contributing-markup}
3939+ ```
4040+4141+- []{#ssec-contributing-markup-anchors-inline}
4242+ **Inline anchors**, which allow linking arbitrary place in the text (e.g. individual list items, sentences…).
4343+4444+ 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):
4545+4646+ ```markdown
4747+ - []{#ssec-gnome-hooks-glib} `glib` setup hook will populate `GSETTINGS_SCHEMAS_PATH` and then `wrapGAppsHook` will prepend it to `XDG_DATA_DIRS`.
4848+ ```
4949+5050+- []{#ssec-contributing-markup-automatic-links}
5151+ 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).
5252+5353+ This syntax is taken from [MyST](https://myst-parser.readthedocs.io/en/latest/using/syntax.html#targets-and-cross-referencing).
5454+5555+- []{#ssec-contributing-markup-admonitions}
5656+ **Admonitions**, set off from the text to bring attention to something.
5757+5858+ It uses pandoc’s [fenced `div`s syntax](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/fenced_divs.md):
5959+6060+ ```markdown
6161+ ::: {.warning}
6262+ This is a warning
6363+ :::
6464+ ```
6565+6666+ which renders as
6767+6868+ > ::: {.warning}
6969+ > This is a warning.
7070+ > :::
7171+7272+ The following are supported:
7373+7474+ - [`caution`](https://tdg.docbook.org/tdg/5.0/caution.html)
7575+ - [`important`](https://tdg.docbook.org/tdg/5.0/important.html)
7676+ - [`note`](https://tdg.docbook.org/tdg/5.0/note.html)
7777+ - [`tip`](https://tdg.docbook.org/tdg/5.0/tip.html)
7878+ - [`warning`](https://tdg.docbook.org/tdg/5.0/warning.html)
7979+8080+- []{#ssec-contributing-markup-definition-lists}
8181+ [**Definition lists**](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/definition_lists.md), for defining a group of terms:
8282+8383+ ```markdown
8484+ pear
8585+ : green or yellow bulbous fruit
8686+8787+ watermelon
8888+ : green fruit with red flesh
8989+ ```
9090+9191+ which renders as
9292+9393+ > pear
9494+ > : green or yellow bulbous fruit
9595+ >
9696+ > watermelon
9797+ > : green fruit with red flesh
9898+9999+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
···99 $ cd nixpkgs
1010 ```
11111212-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.
1212+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.
13131414 ```ShellSession
1515 $ mkdir pkgs/development/libraries/libfoo
···11# Reviewing contributions {#chap-reviewing-contributions}
2233-::: warning
33+::: {.warning}
44The 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).
55:::
66···3535- Building the package locally.
3636 - 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.
3737 - 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.
3838+3839 ```ShellSession
3940 $ git fetch origin nixos-unstable
4041 $ git fetch origin pull/PRNUMBER/head
4142 $ git rebase --onto nixos-unstable BASEBRANCH FETCH_HEAD
4243 ```
4444+4345 - The first command fetches the nixos-unstable branch.
4446 - 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.
4547 - The third command rebases the pull request changes to the nixos-unstable branch.
4648 - 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.
4949+4750 ```ShellSession
4851 $ nix-shell -p nixpkgs-review --run "nixpkgs-review pr PRNUMBER"
4952 ```
+3-1
doc/contributing/submitting-changes.chapter.md
···7171- If a new version fixing the vulnerability has been released, update the package;
7272- 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.
7373 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.:
7474+7475 ```nix
7576 (fetchpatch {
7677 name = "CVE-2019-11068.patch";
···89909091Before removing a package, one should try to find a new maintainer or fix smaller issues first.
91929292-### Steps to remove a package from Nixpkgs
9393+### Steps to remove a package from Nixpkgs {#steps-to-remove-a-package-from-nixpkgs}
93949495We use jbidwatcher as an example for a discontinued project here.
9596···1001011. 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.)
101102102103 For example in this case:
104104+103105 ```
104106 jbidwatcher = throw "jbidwatcher was discontinued in march 2021"; # added 2021-03-15
105107 ```
+2-2
doc/functions/library/attrsets.xml
···166166 <xi:include href="./locations.xml" xpointer="lib.attrsets.getAttrFromPath" />
167167168168 <para>
169169- Like <xref linkend="function-library-lib.attrsets.attrByPath" /> except without a default, and it will throw if the value doesn't exist.
169169+ Like [](#function-library-lib.attrsets.attrByPath) except without a default, and it will throw if the value doesn't exist.
170170 </para>
171171172172 <variablelist>
···14801480 <xi:include href="./locations.xml" xpointer="lib.attrsets.zipAttrs" />
1481148114821482 <para>
14831483- 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.
14831483+ 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.
14841484 </para>
1485148514861486 <variablelist>
+24
doc/labelless-link-is-xref.lua
···11+local function starts_with(start, str)
22+ return str:sub(1, #start) == start
33+end
44+55+local function escape_xml_arg(arg)
66+ amps = arg:gsub('&', '&')
77+ amps_quotes = amps:gsub('"', '"')
88+ amps_quotes_lt = amps_quotes:gsub('<', '<')
99+1010+ return amps_quotes_lt
1111+end
1212+1313+function Link(elem)
1414+ has_no_content = #elem.content == 0
1515+ targets_anchor = starts_with('#', elem.target)
1616+ has_no_attributes = elem.title == '' and elem.identifier == '' and #elem.classes == 0 and #elem.attributes == 0
1717+1818+ if has_no_content and targets_anchor and has_no_attributes then
1919+ -- xref expects idref without the pound-sign
2020+ target_without_hash = elem.target:sub(2, #elem.target)
2121+2222+ return pandoc.RawInline('docbook', '<xref linkend="' .. escape_xml_arg(target_without_hash) .. '" />')
2323+ end
2424+end
+21-14
doc/languages-frameworks/agda.section.md
···11# Agda {#agda}
2233-## How to use Agda
33+## How to use Agda {#how-to-use-agda}
4455Agda is available as the [agda](https://search.nixos.org/packages?channel=unstable&show=agda&from=0&size=30&sort=relevance&query=agda)
66package.
···4343```
44444545You can also reference a GitHub repository
4646+4647```nix
4748agda.withPackages (p: [
4849 (p.standard-library.overrideAttrs (oldAttrs: {
···59606061If you want to use a library not added to Nixpkgs, you can add a
6162dependency to a local library by calling `agdaPackages.mkDerivation`.
6363+6264```nix
6365agda.withPackages (p: [
6466 (p.mkDerivation {
···9294Agda will not by default use these libraries. To tell Agda to use a library we have some options:
93959496* Call `agda` with the library flag:
9595-```ShellSession
9696-$ agda -l standard-library -i . MyFile.agda
9797-```
9797+ ```ShellSession
9898+ $ agda -l standard-library -i . MyFile.agda
9999+ ```
98100* Write a `my-library.agda-lib` file for the project you are working on which may look like:
9999-```
100100-name: my-library
101101-include: .
102102-depend: standard-library
103103-```
101101+ ```
102102+ name: my-library
103103+ include: .
104104+ depend: standard-library
105105+ ```
104106* Create the file `~/.agda/defaults` and add any libraries you want to use by default.
105107106108More information can be found in the [official Agda documentation on library management](https://agda.readthedocs.io/en/v2.6.1/tools/package-system.html).
107109108108-## Compiling Agda
110110+## Compiling Agda {#compiling-agda}
111111+109112Agda 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.
110113This can be overridden by a different version of `ghc` as follows:
111114···116119}
117120```
118121119119-## Writing Agda packages
122122+## Writing Agda packages {#writing-agda-packages}
123123+120124To write a nix derivation for an Agda library, first check that the library has a `*.agda-lib` file.
121125122126A derivation can then be written using `agdaPackages.mkDerivation`. This has similar arguments to `stdenv.mkDerivation` with the following additions:
···140144}
141145```
142146143143-### Building Agda packages
147147+### Building Agda packages {#building-agda-packages}
148148+144149The default build phase for `agdaPackages.mkDerivation` simply runs `agda` on the `Everything.agda` file.
145150If something else is needed to build the package (e.g. `make`) then the `buildPhase` should be overridden.
146151Additionally, a `preBuild` or `configurePhase` can be used if there are steps that need to be done prior to checking the `Everything.agda` file.
147152`agda` and the Agda libraries contained in `buildInputs` are made available during the build phase.
148153149149-### Installing Agda packages
154154+### Installing Agda packages {#installing-agda-packages}
155155+150156The default install phase copies Agda source files, Agda interface files (`*.agdai`) and `*.agda-lib` files to the output directory.
151157This can be overridden.
152158153159By 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.
154160155155-## Adding Agda packages to Nixpkgs
161161+## Adding Agda packages to Nixpkgs {#adding-agda-packages-to-nixpkgs}
156162157163To 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:
158164···182188 '';
183189}
184190```
191191+185192This 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`.
186193187194When 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
···33The Android build environment provides three major features and a number of
44supporting features.
5566-Deploying an Android SDK installation with plugins
77---------------------------------------------------
66+## Deploying an Android SDK installation with plugins {#deploying-an-android-sdk-installation-with-plugins}
77+88The first use case is deploying the SDK with a desired set of plugins or subsets
99of an SDK.
1010···136136androidComposition.platform-tools
137137```
138138139139-Using predefined Android package compositions
140140----------------------------------------------
139139+## Using predefined Android package compositions {#using-predefined-android-package-compositions}
140140+141141In addition to composing an Android package set manually, it is also possible
142142to use a predefined composition that contains all basic packages for a specific
143143Android version, such as version 9.0 (API-level 28).
···159159androidenv.androidPkgs_9_0.platform-tools
160160```
161161162162-Building an Android application
163163--------------------------------
162162+## Building an Android application {#building-an-android-application}
163163+164164In addition to the SDK, it is also possible to build an Ant-based Android
165165project and automatically deploy all the Android plugins that a project
166166requires.
167167+167168168169```nix
169170with import <nixpkgs> {};
···199200installed on any Android device with a web browser by navigating to the build
200201result page.
201202202202-Spawning emulator instances
203203----------------------------
203203+## Spawning emulator instances {#spawning-emulator-instances}
204204+204205For testing purposes, it can also be quite convenient to automatically generate
205206scripts that spawn emulator instances with all desired configuration settings.
206207···241242In addition to prebuilt APKs, you can also bind the APK parameter to a
242243`buildApp {}` function invocation shown in the previous example.
243244244244-Notes on environment variables in Android projects
245245---------------------------------------------------
245245+## Notes on environment variables in Android projects {#notes-on-environment-variables-in-android-projects}
246246+246247* `ANDROID_SDK_ROOT` should point to the Android SDK. In your Nix expressions, this should be
247248 `${androidComposition.androidsdk}/libexec/android-sdk`. Note that `ANDROID_HOME` is deprecated,
248249 but if you rely on tools that need it, you can export it too.
···300301sdk.dir and ndk.dir values. This will ensure that the SDK and NDK directories will
301302both be correct when you run Android Studio inside nix-shell.
302303303303-Notes on improving build.gradle compatibility
304304----------------------------------------------
304304+## Notes on improving build.gradle compatibility {#notes-on-improving-build.gradle-compatibility}
305305+305306Ensure that your buildToolsVersion and ndkVersion match what is declared in androidenv.
306307If you are using cmake, make sure its declared version is correct too.
307308···321322322323```
323324324324-Querying the available versions of each plugin
325325-----------------------------------------------
325325+## Querying the available versions of each plugin {#querying-the-available-versions-of-each-plugin}
326326+326327repo.json provides all the options in one file now.
327328328329A shell script in the `pkgs/development/mobile/androidenv/` subdirectory can be used to retrieve all
···334335335336The above command-line instruction queries all package versions in repo.json.
336337337337-Updating the generated expressions
338338-----------------------------------
338338+## Updating the generated expressions {#updating-the-generated-expressions}
339339+339340repo.json is generated from XML files that the Android Studio package manager uses.
340341To update the expressions run the `generate.sh` script that is stored in the
341342`pkgs/development/mobile/androidenv/` subdirectory:
+5-5
doc/languages-frameworks/beam.section.md
···4455In 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.
6677-## Available versions and deprecations schedule
77+## Available versions and deprecations schedule {#available-versions-and-deprecations-schedule}
8899-### Elixir
99+### Elixir {#elixir}
10101111nixpkgs follows the [official elixir deprecation schedule](https://hexdocs.pm/elixir/compatibility-and-deprecations.html) and keeps the last 5 released versions of Elixir available.
1212···68686969`mixRelease` is used to make a release in the mix sense. Dependencies will need to be fetched with `fetchMixDeps` and passed to it.
70707171-#### mixRelease - Elixir Phoenix example
7171+#### mixRelease - Elixir Phoenix example {#mixrelease---elixir-phoenix-example}
72727373Here is how your `default.nix` file would look.
7474···148148- you can now `nix-build .`
149149- 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.
150150151151-#### Example of creating a service for an Elixir - Phoenix project
151151+#### Example of creating a service for an Elixir - Phoenix project {#example-of-creating-a-service-for-an-elixir---phoenix-project}
152152153153In order to create a service with your release, you could add a `service.nix`
154154in your project with the following
···228228}
229229```
230230231231-#### Elixir - Phoenix project
231231+#### Elixir - Phoenix project {#elixir---phoenix-project}
232232233233Here is an example `shell.nix`.
234234
+1-1
doc/languages-frameworks/bower.section.md
···149149150150## Troubleshooting {#ssec-bower2nix-troubleshooting}
151151152152-### ENOCACHE errors from buildBowerComponents
152152+### ENOCACHE errors from buildBowerComponents {#enocache-errors-from-buildbowercomponents}
153153154154This means that Bower was looking for a package version which doesn't exist in the generated `bower-packages.nix`.
155155
+2-2
doc/languages-frameworks/coq.section.md
···11# Coq and coq packages {#sec-language-coq}
2233-## Coq derivation: `coq`
33+## Coq derivation: `coq` {#coq-derivation-coq}
4455The 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
66···88* `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).
99* `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"; }`.
10101111-## Coq packages attribute sets: `coqPackages`
1111+## Coq packages attribute sets: `coqPackages` {#coq-packages-attribute-sets-coqpackages}
12121313The 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:
1414
+3-1
doc/languages-frameworks/crystal.section.md
···11# Crystal {#crystal}
2233-## Building a Crystal package
33+## Building a Crystal package {#building-a-crystal-package}
4455This section uses [Mint](https://github.com/mint-lang/mint) as an example for how to build a Crystal package.
6677If 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
88+89```bash
910$ git clone https://github.com/mint-lang/mint
1011$ cd mint
···1516This should have generated a `shards.nix` file.
16171718Next create a Nix file for your derivation and use `pkgs.crystal.buildCrystalPackage` as follows:
1919+1820```nix
1921with import <nixpkgs> {};
2022crystal.buildCrystalPackage rec {
+7-7
doc/languages-frameworks/dotnet.section.md
···11-# Dotnet
11+# Dotnet {#dotnet}
2233-## Local Development Workflow
33+## Local Development Workflow {#local-development-workflow}
4455For local development, it's recommended to use nix-shell to create a dotnet environment:
66···1616}
1717```
18181919-### Using many sdks in a workflow
1919+### Using many sdks in a workflow {#using-many-sdks-in-a-workflow}
20202121It'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`:
2222···37373838This 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:
39394040-```ShellSesssion
4040+```ShellSession
4141$ dotnet --info
4242.NET Core SDK (reflecting any global.json):
4343 Version: 3.1.101
···6060 Microsoft.NETCore.App 3.1.1 [/nix/store/iiv98i2jdi226dgh4jzkkj2ww7f8jgpd-dotnet-core-combined/shared/Microsoft.NETCore.App]
6161```
62626363-## dotnet-sdk vs dotnetCorePackages.sdk
6363+## dotnet-sdk vs dotnetCorePackages.sdk {#dotnet-sdk-vs-dotnetcorepackages.sdk}
64646565The `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.
66666767-## dotnetCorePackages.sdk vs dotnetCorePackages.net vs dotnetCorePackages.netcore vs dotnetCorePackages.aspnetcore
6767+## dotnetCorePackages.sdk vs dotnetCorePackages.net vs dotnetCorePackages.netcore vs dotnetCorePackages.aspnetcore {#dotnetcorepackages.sdk-vs-dotnetcorepackages.net-vs-dotnetcorepackages.netcore-vs-dotnetcorepackages.aspnetcore}
68686969The `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.
70707171-## Packaging a Dotnet Application
7171+## Packaging a Dotnet Application {#packaging-a-dotnet-application}
72727373Ideally, we would like to build against the sdk, then only have the dotnet runtime available in the runtime closure.
7474
+6-8
doc/languages-frameworks/emscripten.section.md
···2727 * dev-shell for zlib implementation hacking:
2828 * `nix-shell -A emscriptenPackages.zlib`
29293030-3131-## Imperative usage
3030+## Imperative usage {#imperative-usage}
32313332A few things to note:
34333534* `export EMCC_DEBUG=2` is nice for debugging
3635* `~/.emscripten`, the build artifact cache sometimes creates issues and needs to be removed from time to time
37363838-3939-## Declarative usage
3737+## Declarative usage {#declarative-usage}
40384139Let's see two different examples from `pkgs/top-level/emscripten-packages.nix`:
4240···5048* Use `export EMCC_DEBUG=2` from within a emscriptenPackage's `phase` to get more detailed debug output what is going wrong.
5149* ~/.emscripten cache is requiring us to set `HOME=$TMPDIR` in individual phases. This makes compilation slower but also makes it more deterministic.
52505353-### Usage 1: pkgs.zlib.override
5151+### Usage 1: pkgs.zlib.override {#usage-1-pkgs.zlib.override}
54525553This 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...
5654···110108 '';
111109 });
112110113113-### Usage 2: pkgs.buildEmscriptenPackage
111111+### Usage 2: pkgs.buildEmscriptenPackage {#usage-2-pkgs.buildemscriptenpackage}
114112115113This `xmlmirror` example features a emscriptenPackage which is defined completely from this context and no `pkgs.zlib.override` is used.
116114···165163 '';
166164 };
167165168168-### Declarative debugging
166166+### Declarative debugging {#declarative-debugging}
169167170168Use `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.
171169···1771756. `buildPhase`
1781767. ... happy hacking...
179177180180-## Summary
178178+## Summary {#summary}
181179182180Using 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.
183181
+1-1
doc/languages-frameworks/gnome.section.md
···84848585- []{#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`.
86868787- ::: warning
8787+ ::: {.warning}
8888 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;`.
8989 :::
9090
+2-2
doc/languages-frameworks/go.section.md
···44444545The function `buildGoPackage` builds legacy Go programs, not supporting Go modules.
46464747-### Example for `buildGoPackage`
4747+### Example for `buildGoPackage` {#example-for-buildgopackage}
48484949In the following is an example expression using buildGoPackage, the following arguments are of special significance to the function:
5050···140140141141### `subPackages` {#var-go-subPackages}
142142143143-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.
143143+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
···11# Idris {#idris}
2233-## Installing Idris
33+## Installing Idris {#installing-idris}
4455The easiest way to get a working idris version is to install the `idris` attribute:
6677-```ShellSesssion
77+```ShellSession
88$ # On NixOS
99$ nix-env -i nixos.idris
1010$ # On non-NixOS
···21212222And then:
23232424-```ShellSesssion
2424+```ShellSession
2525$ # On NixOS
2626$ nix-env -iA nixos.myIdris
2727$ # On non-NixOS
···2929```
30303131To see all available Idris packages:
3232-```ShellSesssion
3232+3333+```ShellSession
3334$ # On NixOS
3435$ nix-env -qaPA nixos.idrisPackages
3536$ # On non-NixOS
···3738```
38393940Similarly, entering a `nix-shell`:
4040-```ShellSesssion
4141+4242+```ShellSession
4143$ nix-shell -p 'idrisPackages.with-packages (with idrisPackages; [ contrib pruviloj ])'
4244```
43454444-## Starting Idris with library support
4646+## Starting Idris with library support {#starting-idris-with-library-support}
45474648To have access to these libraries in idris, call it with an argument `-p <library name>` for each library:
47494848-```ShellSesssion
5050+```ShellSession
4951$ nix-shell -p 'idrisPackages.with-packages (with idrisPackages; [ contrib pruviloj ])'
5052[nix-shell:~]$ idris -p contrib -p pruviloj
5153```
52545355A listing of all available packages the Idris binary has access to is available via `--listlibs`:
54565555-```ShellSesssion
5757+```ShellSession
5658$ idris --listlibs
575900prelude-idx.ibc
5860pruviloj
···646600contrib-idx.ibc
6567```
66686767-## Building an Idris project with Nix
6969+## Building an Idris project with Nix {#building-an-idris-project-with-nix}
68706971As an example of how a Nix expression for an Idris package can be created, here is the one for `idrisPackages.yaml`:
7072···105107106108Assuming this file is saved as `yaml.nix`, it's buildable using
107109108108-```ShellSesssion
110110+```ShellSession
109111$ nix-build -E '(import <nixpkgs> {}).idrisPackages.callPackage ./yaml.nix {}'
110112```
111113···121123122124in another file (say `default.nix`) to be able to build it with
123125124124-```ShellSesssion
126126+```ShellSession
125127$ nix-build -A yaml
126128```
127129128128-## Passing options to `idris` commands
130130+## Passing options to `idris` commands {#passing-options-to-idris-commands}
129131130132The `build-idris-package` function provides also optional input values to set additional options for the used `idris` commands.
131133
+9-8
doc/languages-frameworks/ios.section.md
···20202121The Xcode build environment implements a number of features.
22222323-Deploying a proxy component wrapper exposing Xcode
2424---------------------------------------------------
2323+## Deploying a proxy component wrapper exposing Xcode {#deploying-a-proxy-component-wrapper-exposing-xcode}
2424+2525The first use case is deploying a Nix package that provides symlinks to the Xcode
2626installation on the host system. This package can be used as a build input to
2727any build function implemented in the Nix expression language that requires
···5555lrwxr-xr-x 1 sander staff 14 1 jan 1970 xcrun -> /usr/bin/xcrun
5656```
57575858-Building an iOS application
5959----------------------------
5858+## Building an iOS application {#building-an-ios-application}
5959+6060We can build an iOS app executable for the simulator, or an IPA/xcarchive file
6161for release purposes, e.g. ad-hoc, enterprise or store installations, by
6262executing the `xcodeenv.buildApp {}` function:
···9999```
100100101101The above function takes a variety of parameters:
102102+102103* The `name` and `src` parameters are mandatory and specify the name of the app
103104 and the location where the source code resides
104105* `sdkVersion` specifies which version of the iOS SDK to use.
···151152`xcodeBaseDir` parameter can be overridden to refer to a different Xcode
152153version.
153154154154-Spawning simulator instances
155155-----------------------------
155155+## Spawning simulator instances {#spawning-simulator-instances}
156156+156157In addition to building iOS apps, we can also automatically spawn simulator
157158instances:
158159···213214By providing the result of an `xcode.buildApp {}` function and configuring the
214215app bundle id, the app gets deployed automatically and started.
215216216216-Troubleshooting
217217----------------
217217+## Troubleshooting {#troubleshooting}
218218+218219In some rare cases, it may happen that after a failure, changes are not picked
219220up. Most likely, this is caused by a derived data cache that Xcode maintains.
220221To wipe it you can run:
+33-23
doc/languages-frameworks/lua.section.md
···11-# User's Guide to Lua Infrastructure {#users-guide-to-lua-infrastructure}
11+# User’s Guide to Lua Infrastructure {#users-guide-to-lua-infrastructure}
2233-## Using Lua
33+## Using Lua {#using-lua}
4455-### Overview of Lua
55+### Overview of Lua {#overview-of-lua}
6677Several versions of the Lua interpreter are available: luajit, lua 5.1, 5.2, 5.3.
88The 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.
···1717`luaPackages` refers to `lua5_1.pkgs` and `lua52Packages` to
1818`lua5_2.pkgs`.
19192020-### Installing Lua and packages
2020+### Installing Lua and packages {#installing-lua-and-packages}
21212222-#### Lua environment defined in separate `.nix` file
2222+#### Lua environment defined in separate `.nix` file {#lua-environment-defined-in-separate-.nix-file}
23232424Create a file, e.g. `build.nix`, with the following expression
2525+2526```nix
2627with import <nixpkgs> {};
27282829lua5_2.withPackages (ps: with ps; [ busted luafilesystem ])
2930```
3131+3032and install it in your profile with
3333+3134```shell
3235nix-env -if build.nix
3336```
3437Now you can use the Lua interpreter, as well as the extra packages (`busted`,
3538`luafilesystem`) that you added to the environment.
36393737-#### Lua environment defined in `~/.config/nixpkgs/config.nix`
4040+#### Lua environment defined in `~/.config/nixpkgs/config.nix` {#lua-environment-defined-in-.confignixpkgsconfig.nix}
38413942If you prefer to, you could also add the environment as a package override to the Nixpkgs set, e.g.
4043using `config.nix`,
4444+4145```nix
4246{ # ...
4347···4650 };
4751}
4852```
5353+4954and install it in your profile with
5555+5056```shell
5157nix-env -iA nixpkgs.myLuaEnv
5258```
5359The environment is installed by referring to the attribute, and considering
5460the `nixpkgs` channel was used.
55615656-#### Lua environment defined in `/etc/nixos/configuration.nix`
6262+#### Lua environment defined in `/etc/nixos/configuration.nix` {#lua-environment-defined-in-etcnixosconfiguration.nix}
57635864For the sake of completeness, here's another example how to install the environment system-wide.
5965···6672}
6773```
68746969-### How to override a Lua package using overlays?
7575+### How to override a Lua package using overlays? {#how-to-override-a-lua-package-using-overlays}
70767177Use the following overlay template:
7278···8793}
8894```
89959090-### Temporary Lua environment with `nix-shell`
9696+### Temporary Lua environment with `nix-shell` {#temporary-lua-environment-with-nix-shell}
919792989399There are two methods for loading a shell with Lua packages. The first and recommended method
94100is to create an environment with `lua.buildEnv` or `lua.withPackages` and load that. E.g.
101101+95102```sh
96103$ nix-shell -p 'lua.withPackages(ps: with ps; [ busted luafilesystem ])'
97104```
105105+98106opens a shell from which you can launch the interpreter
107107+99108```sh
100109[nix-shell:~] lua
101110```
111111+102112The other method, which is not recommended, does not create an environment and requires you to list the packages directly,
103113104114```sh
···108118The Lua interpreter has the attribute `pkgs` which contains all Lua libraries for that specific interpreter.
109119110120111111-## Developing with Lua
121121+## Developing with Lua {#developing-with-lua}
112122113123Now that you know how to get a working Lua environment with Nix, it is time
114124to go forward and start actually developing with Lua. There are two ways to
···116126of by the luarocks2nix converter or the packaging has to be done manually.
117127Let's present the luarocks way first and the manual one in a second time.
118128119119-### Packaging a library on luarocks
129129+### Packaging a library on luarocks {#packaging-a-library-on-luarocks}
120130121131[Luarocks.org](www.luarocks.org) is the main repository of lua packages.
122132The site proposes two types of packages, the rockspec and the src.rock
···135145Nix rely on luarocks to install lua packages, basically it runs:
136146`luarocks make --deps-mode=none --tree $out`
137147138138-#### Packaging a library manually
148148+#### Packaging a library manually {#packaging-a-library-manually}
139149140150You can develop your package as you usually would, just don't forget to wrap it
141151within a `toLuaModule` call, for instance
152152+142153```nix
143154mynewlib = toLuaModule ( stdenv.mkDerivation { ... });
144155```
···146157There is also the `buildLuaPackage` function that can be used when lua modules
147158are not packaged for luarocks. You can see a few examples at `pkgs/top-level/lua-packages.nix`.
148159149149-## Lua Reference
160160+## Lua Reference {#lua-reference}
150161151151-### Lua interpreters
162162+### Lua interpreters {#lua-interpreters}
152163153164Versions 5.1, 5.2 and 5.3 of the lua interpreter are available as
154165respectively `lua5_1`, `lua5_2` and `lua5_3`. Luajit is available too.
155166The Nix expressions for the interpreters can be found in `pkgs/development/interpreters/lua-5`.
156167157157-158158-#### Attributes on lua interpreters packages
168168+#### Attributes on lua interpreters packages {#attributes-on-lua-interpreters-packages}
159169160170Each interpreter has the following attributes:
161171···164174- `withPackages`. Simpler interface to `buildEnv`.
165175- `pkgs`. Set of Lua packages for that specific interpreter. The package set can be modified by overriding the interpreter and passing `packageOverrides`.
166176167167-168168-#### `buildLuarocksPackage` function
177177+#### `buildLuarocksPackage` function {#buildluarockspackage-function}
169178170179The `buildLuarocksPackage` function is implemented in `pkgs/development/interpreters/lua-5/build-lua-package.nix`
171180The following is an example:
···205214206215By default `meta.platforms` is set to the same value as the interpreter unless overridden otherwise.
207216208208-#### `buildLuaApplication` function
217217+#### `buildLuaApplication` function {#buildluaapplication-function}
209218210219The `buildLuaApplication` function is practically the same as `buildLuaPackage`.
211220The difference is that `buildLuaPackage` by default prefixes the names of the packages with the version of the interpreter.
212221Because with an application we're not interested in multiple version the prefix is dropped.
213222214214-#### lua.withPackages function
223223+#### lua.withPackages function {#lua.withpackages-function}
215224216225The `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.
217226Using the `withPackages` function, the previous example for the luafilesystem environment can be written like this:
227227+218228```nix
219229with import <nixpkgs> {};
220230···223233224234`withPackages` passes the correct package set for the specific interpreter version as an argument to the function. In the above example, `ps` equals `luaPackages`.
225235But you can also easily switch to using `lua5_2`:
236236+226237```nix
227238with import <nixpkgs> {};
228239···231242232243Now, `ps` is set to `lua52Packages`, matching the version of the interpreter.
233244234234-235235-### Possible Todos
245245+### Possible Todos {#possible-todos}
236246237247* export/use version specific variables such as `LUA_PATH_5_2`/`LUAROCKS_CONFIG_5_2`
238248* let luarocks check for dependencies via exporting the different rocktrees in temporary config
239249240240-### Lua Contributing guidelines
250250+### Lua Contributing guidelines {#lua-contributing-guidelines}
241251242252Following rules should be respected:
243253
+10-7
doc/languages-frameworks/maven.section.md
···43434444You find this demo project at https://github.com/fzakaria/nixos-maven-example
45454646-## Solving for dependencies
4646+## Solving for dependencies {#solving-for-dependencies}
47474848-### buildMaven with NixOS/mvn2nix-maven-plugin
4848+### buildMaven with NixOS/mvn2nix-maven-plugin {#buildmaven-with-nixosmvn2nix-maven-plugin}
49495050> ⚠️ Although `buildMaven` is the "blessed" way within nixpkgs, as of 2020, it hasn't seen much activity in quite a while.
5151···8282 A simple derivation that runs through `mvn compile` & `mvn package` to build the JAR. You may use this as inspiration for more complicated derivations.
83838484Here is an [example](https://github.com/fzakaria/nixos-maven-example/blob/main/build-maven-repository.nix) of building the Maven repository
8585+8586```nix
8687{ pkgs ? import <nixpkgs> { } }:
8788with pkgs;
···103104│ └── 4.1.3
104105│ ├── avalon-framework-4.1.3.jar -> /nix/store/iv5fp3955w3nq28ff9xfz86wvxbiw6n9-avalon-framework-4.1.3.jar
105106```
106106-### Double Invocation
107107+108108+### Double Invocation {#double-invocation}
107109108110> ⚠️ This pattern is the simplest but may cause unnecessary rebuilds due to the output hash changing.
109111···163165164166If 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`.
165167166166-## Building a JAR
168168+## Building a JAR {#building-a-jar}
167169168170Regardless of which strategy is chosen above, the step to build the derivation is the same.
169171···2012032 directories, 1 file
202204```
203205204204-## Runnable JAR
206206+## Runnable JAR {#runnable-jar}
205207206208The previous example builds a `jar` file but that's not a file one can run.
207209···213215214216The following two methods are more suited to Nix then building an [UberJar](https://imagej.net/Uber-JAR) which may be the more traditional approach.
215217216216-### CLASSPATH
218218+### CLASSPATH {#classpath}
217219218220> This is ideal if you are providing a derivation for _nixpkgs_ and don't want to patch the project's `pom.xml`.
219221···252254}
253255```
254256255255-### MANIFEST file via Maven Plugin
257257+### MANIFEST file via Maven Plugin {#manifest-file-via-maven-plugin}
256258257259> This is ideal if you are the project owner and want to change your `pom.xml` to set the CLASSPATH within it.
258260259261Augment the `pom.xml` to create a JAR with the following manifest:
262262+260263```xml
261264<build>
262265 <plugins>
+64-57
doc/languages-frameworks/python.section.md
···11# Python {#python}
2233-## User Guide
33+## User Guide {#user-guide}
4455-### Using Python
55+### Using Python {#using-python}
6677-#### Overview
77+#### Overview {#overview}
8899Several versions of the Python interpreter are available on Nix, as well as a
1010high amount of packages. The attribute `python3` refers to the default
···3131`pythonPackages` refers to `python.pkgs` and `python38Packages` to
3232`python38.pkgs`.
33333434-#### Installing Python and packages
3434+#### Installing Python and packages {#installing-python-and-packages}
35353636The Nix and NixOS manuals explain how packages are generally installed. In the
3737case of Python and Nix, it is important to make a distinction between whether the
···6262of development: individual projects create their own Python environments without
6363impacting the global environment or each other.
64646565-#### Ad-hoc temporary Python environment with `nix-shell`
6565+#### Ad-hoc temporary Python environment with `nix-shell` {#ad-hoc-temporary-python-environment-with-nix-shell}
66666767The simplest way to start playing with the way nix wraps and sets up Python
6868environments is with `nix-shell` at the cmdline. These environments create a
···131131interpreter and dependencies work in Nix and NixOS, but to do some actual
132132development, we'll want to make it a bit more persistent.
133133134134-##### Running Python scripts and using `nix-shell` as shebang
134134+##### Running Python scripts and using `nix-shell` as shebang {#running-python-scripts-and-using-nix-shell-as-shebang}
135135136136Sometimes, we have a script whose header looks like this:
137137···146146Executing this script requires a `python3` that has `numpy`. Using what we learned
147147in the previous section, we could startup a shell and just run it like so:
148148149149-```ShellSesssion
149149+```ShellSession
150150$ nix-shell -p 'python38.withPackages(ps: with ps; [ numpy ])' --run 'python3 foo.py'
151151The dot product of [1 2] and [3 4] is: 11
152152```
···203203This is also a great way to ensure the script executes identically on different
204204servers.
205205206206-##### Load environment from `.nix` expression
206206+##### Load environment from `.nix` expression {#load-environment-from-.nix-expression}
207207208208We've now seen how to create an ad-hoc temporary shell session, and how to
209209create a single script with Python dependencies, but in the course of normal
···262262like `libffi` the `openssl` in scope. This is generic and can span any number of
263263tools or languages across the Nixpkgs ecosystem.
264264265265-##### Installing environments globally on the system
265265+##### Installing environments globally on the system {#installing-environments-globally-on-the-system}
266266267267Up to now, we've been creating environments scoped to an ad-hoc shell session,
268268or a single script, or a single project. This is generally advisable, as it
···315315atomically *uninstall* all other imperatively installed packages and replace
316316your profile with just `myEnv` by using the `--replace` flag.
317317318318-##### Environment defined in `/etc/nixos/configuration.nix`
318318+##### Environment defined in `/etc/nixos/configuration.nix` {#environment-defined-in-etcnixosconfiguration.nix}
319319320320For the sake of completeness, here's how to install the environment system-wide
321321on NixOS.
···329329}
330330```
331331332332-### Developing with Python
332332+### Developing with Python {#developing-with-python}
333333334334Above, we were mostly just focused on use cases and what to do to get started
335335creating working Python environments in nix.
···338338back and take a deeper look at how Python packages are packaged on Nix. Then,
339339we will look at how you can use development mode with your code.
340340341341-#### Python library packages in Nixpkgs
341341+#### Python library packages in Nixpkgs {#python-library-packages-in-nixpkgs}
342342343343With Nix all packages are built by functions. The main function in Nix for
344344building Python libraries is `buildPythonPackage`. Let's see how we can build the
···425425`toolz` from the Nixpkgs package set this time, but instead took our own version
426426that we introduced with the `let` expression.
427427428428-#### Handling dependencies
428428+#### Handling dependencies {#handling-dependencies}
429429430430Our example, `toolz`, does not have any dependencies on other Python packages or
431431system libraries. According to the manual, `buildPythonPackage` uses the
···537537 };
538538}
539539```
540540+540541Note also the line `doCheck = false;`, we explicitly disabled running the test-suite.
541542542542-#### Testing Python Packages
543543+#### Testing Python Packages {#testing-python-packages}
543544544545It is highly encouraged to have testing as part of the package build. This
545546helps to avoid situations where the package was able to build and install,
···559560as many tests should be enabled as possible. Failing tests can still be
560561a good indication that the package is not in a valid state.
561562562562-#### Using pytest
563563+#### Using pytest {#using-pytest}
563564564565Pytest is the most common test runner for python repositories. A trivial
565566test run would be:
567567+566568```
567569 checkInputs = [ pytest ];
568570 checkPhase = "pytest";
···572574sandbox, and will generally need many tests to be disabled.
573575574576To filter tests using pytest, one can do the following:
577577+575578```
576579 checkInputs = [ pytest ];
577580 # avoid tests which need additional data or touch network
···587590588591`-k` is used to define a predicate for test names. In this example, we are
589592filtering out tests which contain `download` or `update` in their test case name.
590590-Only one `-k` argument is allows, and thus a long predicate should be concatenated
591591-with "\" and wrapped to the next line.
593593+Only one `-k` argument is allowed, and thus a long predicate should be concatenated
594594+with “\\” and wrapped to the next line.
592595593593-*NOTE:* In pytest==6.0.1, the use of "\" to continue a line (e.g. `-k 'not download \'`) has
596596+*NOTE:* In pytest==6.0.1, the use of “\\” to continue a line (e.g. `-k 'not download \'`) has
594597been removed, in this case, it's recommended to use `pytestCheckHook`.
595598596596-#### Using pytestCheckHook
599599+#### Using pytestCheckHook {#using-pytestcheckhook}
597600598601`pytestCheckHook` is a convenient hook which will substitute the setuptools
599602`test` command for a checkPhase which runs `pytest`. This is also beneficial
600603when a package may need many items disabled to run the test suite.
601604602605Using the example above, the analagous pytestCheckHook usage would be:
606606+603607```
604608 checkInputs = [ pytestCheckHook ];
605609···637641would be much harder to read. This also enables us to comment on why specific tests
638642are disabled.
639643640640-#### Using pythonImportsCheck
644644+#### Using pythonImportsCheck {#using-pythonimportscheck}
641645642646Although unit tests are highly prefered to validate correctness of a package, not
643647all packages have test suites that can be ran easily, and some have none at all.
···659663This can also be useful in verifying that the package doesn't assume commonly
660664present packages (e.g. `setuptools`)
661665662662-### Develop local package
666666+### Develop local package {#develop-local-package}
663667664668As a Python developer you're likely aware of [development mode](http://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode)
665669(`python setup.py develop`); instead of installing the package this command
···694698It is important to note that due to how development mode is implemented on Nix
695699it is not possible to have multiple packages simultaneously in development mode.
696700697697-### Organising your packages
701701+### Organising your packages {#organising-your-packages}
698702699703So far we discussed how you can use Python on Nix, and how you can develop with
700704it. We've looked at how you write expressions to package Python packages, and we
···706710duplication we now look at how you can maintain a repository with your
707711own packages. The important functions here are `import` and `callPackage`.
708712709709-### Including a derivation using `callPackage`
713713+### Including a derivation using `callPackage` {#including-a-derivation-using-callpackage}
710714711715Earlier we created a Python environment using `withPackages`, and included the
712716`toolz` package via a `let` expression.
···756760example we use `buildPythonPackage` that is part of the set `python38Packages`,
757761and in this case the `python38` interpreter is automatically used.
758762759759-## Reference
763763+## Reference {#reference}
760764761761-### Interpreters
765765+### Interpreters {#interpreters}
762766763767Versions 2.7, 3.6, 3.7, 3.8 and 3.9 of the CPython interpreter are available as
764768respectively `python27`, `python36`, `python37`, `python38` and `python39`. The
···773777`out/{python.sitePackages}` to `$PYTHONPATH` if such directory
774778exists.
775779776776-#### Missing `tkinter` module standard library
780780+#### Missing `tkinter` module standard library {#missing-tkinter-module-standard-library}
777781778782To reduce closure size the `Tkinter`/`tkinter` is available as a separate package, `pythonPackages.tkinter`.
779783780780-#### Attributes on interpreters packages
784784+#### Attributes on interpreters packages {#attributes-on-interpreters-packages}
781785782786Each interpreter has the following attributes:
783787···789793- `executable`. Name of the interpreter executable, e.g. `python3.8`.
790794- `pkgs`. Set of Python packages for that specific interpreter. The package set can be modified by overriding the interpreter and passing `packageOverrides`.
791795792792-### Optimizations
796796+### Optimizations {#optimizations}
793797794798The Python interpreters are by default not build with optimizations enabled, because
795799the builds are in that case not reproducible. To enable optimizations, override the
···806810in mypython
807811```
808812809809-### Building packages and applications
813813+### Building packages and applications {#building-packages-and-applications}
810814811815Python libraries and applications that use `setuptools` or
812816`distutils` are typically built with respectively the `buildPythonPackage` and
···838842* `pkgs.python3Packages` pointing to `pkgs.python38Packages`
839843* `pkgs.pythonPackages` pointing to `pkgs.python2Packages`
840844841841-#### `buildPythonPackage` function
845845+#### `buildPythonPackage` function {#buildpythonpackage-function}
842846843847The `buildPythonPackage` function is implemented in
844848`pkgs/development/interpreters/python/mk-python-derivation`
···890894By default `meta.platforms` is set to the same value
891895as the interpreter unless overridden otherwise.
892896893893-##### `buildPythonPackage` parameters
897897+##### `buildPythonPackage` parameters {#buildpythonpackage-parameters}
894898895899All parameters from `stdenv.mkDerivation` function are still supported. The
896900following are specific to `buildPythonPackage`:
···946950 `buildPythonPackage` also injects code into and wraps executables with the
947951 paths included in this list. Items listed in `install_requires` go here.
948952949949-##### Overriding Python packages
953953+##### Overriding Python packages {#overriding-python-packages}
950954951955The `buildPythonPackage` function has a `overridePythonAttrs` method that can be
952956used to override the package. In the following example we create an environment
···974978in python.withPackages(ps: [ps.blaze])).env
975979```
976980977977-#### `buildPythonApplication` function
981981+#### `buildPythonApplication` function {#buildpythonapplication-function}
978982979983The `buildPythonApplication` function is practically the same as
980984`buildPythonPackage`. The main purpose of this function is to build a Python
···10191023Since the package is an application, a consumer doesn't need to care about
10201024Python versions or modules, which is why they don't go in `pythonPackages`.
1021102510221022-#### `toPythonApplication` function
10261026+#### `toPythonApplication` function {#topythonapplication-function}
1023102710241028A distinction is made between applications and libraries, however, sometimes a
10251029package is used as both. In this case the package is added as a library to
···10311035`python-packages.nix`. A reference shall be created from `all-packages.nix` to
10321036the attribute in `python-packages.nix`, and the `toPythonApplication` shall be
10331037applied to the reference:
10381038+10341039```nix
10351040youtube-dl = with pythonPackages; toPythonApplication youtube-dl;
10361041```
1037104210381038-#### `toPythonModule` function
10431043+#### `toPythonModule` function {#topythonmodule-function}
1039104410401045In some cases, such as bindings, a package is created using
10411046`stdenv.mkDerivation` and added as attribute in `all-packages.nix`. The Python
···1052105710531058Do pay attention to passing in the right Python version!
1054105910551055-#### `python.buildEnv` function
10601060+#### `python.buildEnv` function {#python.buildenv-function}
1056106110571062Python environments can be created using the low-level `pkgs.buildEnv` function.
10581063This example shows how to create an environment that has the Pyramid Web Framework.
···10901095will drop you into a shell where Python will have the
10911096specified packages in its path.
1092109710981098+##### `python.buildEnv` arguments {#python.buildenv-arguments}
1093109910941094-##### `python.buildEnv` arguments
1095110010961101* `extraLibs`: List of packages installed inside the environment.
10971102* `postBuild`: Shell command executed after the build of environment.
···10991104* `permitUserSite`: Skip setting the `PYTHONNOUSERSITE` environment variable in
11001105 wrapped binaries in the environment.
1101110611021102-#### `python.withPackages` function
11071107+#### `python.withPackages` function {#python.withpackages-function}
1103110811041109The `python.withPackages` function provides a simpler interface to the `python.buildEnv` functionality.
11051110It takes a function as an argument that is passed the set of python packages and returns the list
···11411146Python 2 namespace packages may provide `__init__.py` that collide. In that case
11421147`python.buildEnv` should be used with `ignoreCollisions = true`.
1143114811441144-#### Setup hooks
11491149+#### Setup hooks {#setup-hooks}
1145115011461151The following are setup hooks specifically for Python packages. Most of these
11471152are used in `buildPythonPackage`.
···11661171- `wheelUnpackHook` to move a wheel to the correct folder so it can be installed
11671172 with the `pipInstallHook`.
1168117311691169-### Development mode
11741174+### Development mode {#development-mode}
1170117511711176Development or editable mode is supported. To develop Python packages
11721177`buildPythonPackage` has additional logic inside `shellPhase` to run `pip
···11751180Warning: `shellPhase` is executed only if `setup.py` exists.
1176118111771182Given a `default.nix`:
11831183+11781184```nix
11791185with import <nixpkgs> {};
11801186···1197120311981204Note: There is a boolean value `lib.inNixShell` set to `true` if nix-shell is invoked.
1199120512001200-### Tools
12061206+### Tools {#tools}
1201120712021208Packages inside nixpkgs are written by hand. However many tools exist in
12031209community to help save time. No tool is preferred at the moment.
···12091215- [nixpkgs-pytools](https://github.com/nix-community/nixpkgs-pytools)
12101216- [poetry2nix](https://github.com/nix-community/poetry2nix)
1211121712121212-### Deterministic builds
12181218+### Deterministic builds {#deterministic-builds}
1213121912141220The Python interpreters are now built deterministically. Minor modifications had
12151221to be made to the interpreters in order to generate deterministic bytecode. This
···12211227and [PYTHONHASHSEED=0](https://docs.python.org/3.8/using/cmdline.html#envvar-PYTHONHASHSEED).
12221228Both are also exported in `nix-shell`.
1223122912241224-### Automatic tests
12301230+### Automatic tests {#automatic-tests}
1225123112261232It is recommended to test packages as part of the build process.
12271233Source distributions (`sdist`) often include test files, but not always.
···12301236`checkPhase`, but often it is necessary to pass a custom `checkPhase`. An
12311237example of such a situation is when `py.test` is used.
1232123812331233-#### Common issues
12391239+#### Common issues {#common-issues}
1234124012351241* Non-working tests can often be deselected. By default `buildPythonPackage`
12361242 runs `python setup.py test`. Most Python modules follows the standard test
···12471253 '';
12481254 }
12491255 ```
12561256+12501257* Tests that attempt to access `$HOME` can be fixed by using the following
12511258 work-around before running tests (e.g. `preCheck`): `export HOME=$(mktemp -d)`
1252125912531253-## FAQ
12601260+## FAQ {#faq}
1254126112551255-### How to solve circular dependencies?
12621262+### How to solve circular dependencies? {#how-to-solve-circular-dependencies}
1256126312571264Consider the packages `A` and `B` that depend on each other. When packaging `B`,
12581265a solution is to override package `A` not to depend on `B` as an input. The same
12591266should also be done when packaging `A`.
1260126712611261-### How to override a Python package?
12681268+### How to override a Python package? {#how-to-override-a-python-package}
1262126912631270We can override the interpreter and pass `packageOverrides`. In the following
12641271example we rename the `pandas` package and build it.
···13161323in newpkgs.inkscape
13171324```
1318132513191319-### `python setup.py bdist_wheel` cannot create .whl
13261326+### `python setup.py bdist_wheel` cannot create .whl {#python-setup.py-bdist_wheel-cannot-create-.whl}
1320132713211328Executing `python setup.py bdist_wheel` in a `nix-shell `fails with
13221329```
···13491356nix-shell --run "unset SOURCE_DATE_EPOCH; python3 setup.py bdist_wheel"
13501357```
1351135813521352-### `install_data` / `data_files` problems
13591359+### `install_data` / `data_files` problems {#install_data-data_files-problems}
1353136013541361If you get the following error:
13551362···13691376sed -i '/ = data\_files/d' setup.py
13701377```
1371137813721372-### Rationale of non-existent global site-packages
13791379+### Rationale of non-existent global site-packages {#rationale-of-non-existent-global-site-packages}
1373138013741381On most operating systems a global `site-packages` is maintained. This however
13751382becomes problematic if you want to run multiple Python versions or have multiple
···13841391method is to use `nix-shell`, either with or without the `python.buildEnv`
13851392function.
1386139313871387-### How to consume Python modules using pip in a virtual environment like I am used to on other Operating Systems?
13941394+### 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}
1388139513891396While this approach is not very idiomatic from Nix perspective, it can still be
13901397useful when dealing with pre-existing projects or in situations where it's not
···14971504requirements.txt. However these will be cached locally within the `virtualenv`
14981505folder and not downloaded again.
1499150615001500-### How to override a Python package from `configuration.nix`?
15071507+### How to override a Python package from `configuration.nix`? {#how-to-override-a-python-package-from-configuration.nix}
1501150815021509If you need to change a package's attribute(s) from `configuration.nix` you could do:
15031510···15351542 }
15361543```
1537154415381538-### How to override a Python package using overlays?
15451545+### How to override a Python package using overlays? {#how-to-override-a-python-package-using-overlays}
1539154615401547Use the following overlay template:
15411548···15561563}
15571564```
1558156515591559-### How to use Intel's MKL with numpy and scipy?
15661566+### How to use Intel’s MKL with numpy and scipy? {#how-to-use-intels-mkl-with-numpy-and-scipy}
1560156715611568MKL can be configured using an overlay. See the section "[Using overlays to
15621569configure alternatives](#sec-overlays-alternatives-blas-lapack)".
1563157015641564-### What inputs do `setup_requires`, `install_requires` and `tests_require` map to?
15711571+### What inputs do `setup_requires`, `install_requires` and `tests_require` map to? {#what-inputs-do-setup_requires-install_requires-and-tests_require-map-to}
1565157215661573In a `setup.py` or `setup.cfg` it is common to declare dependencies:
15671574···15691576* `install_requires` corresponds to `propagatedBuildInputs`
15701577* `tests_require` corresponds to `checkInputs`
1571157815721572-## Contributing
15791579+## Contributing {#contributing}
1573158015741574-### Contributing guidelines
15811581+### Contributing guidelines {#contributing-guidelines}
1575158215761583The following rules are desired to be respected:
15771584
+8-3
doc/languages-frameworks/qt.section.md
···9090}
9191```
92929393-::: note
9393+::: {.note}
9494`wrapQtAppsHook` ignores files that are non-ELF executables.
9595This means that scripts won't be automatically wrapped so you'll need to manually wrap them as previously mentioned.
9696An example of when you'd always need to do this is with Python applications that use PyQt.
9797:::
98989999-## Adding a library to Nixpkgs
9999+## Adding a library to Nixpkgs {#adding-a-library-to-nixpkgs}
100100+100101Add Qt libraries to `qt5-packages.nix` to make them available for every
101102supported Qt version.
102103103104### Example adding a Qt library {#qt-library-all-packages-nix}
104105105106The following represents the contents of `qt5-packages.nix`.
107107+106108```nix
107109{
108110 # ...
···126128}
127129```
128130129129-## Adding an application to Nixpkgs
131131+## Adding an application to Nixpkgs {#adding-an-application-to-nixpkgs}
132132+130133Add Qt applications to `qt5-packages.nix`. Add an alias to `all-packages.nix`
131134to select the Qt 5 version used for the application.
132135133136### Example adding a Qt application {#qt-application-all-packages-nix}
134137135138The following represents the contents of `qt5-packages.nix`.
139139+136140```nix
137141{
138142 # ...
···144148```
145149146150The following represents the contents of `all-packages.nix`.
151151+147152```nix
148153{
149154 # ...
+5-5
doc/languages-frameworks/r.section.md
···11# R {#r}
2233-## Installation
33+## Installation {#installation}
4455Define an environment for R that contains all the libraries that you'd like to
66use by adding the following snippet to your $HOME/.config/nixpkgs/config.nix file:
···3131However, if you'd like to add a file to your project source to make the
3232environment available for other contributors, you can create a `default.nix`
3333file like so:
3434+3435```nix
3536with import <nixpkgs> {};
3637{
···5051and then run `nix-shell .` to be dropped into a shell with those packages
5152available.
52535353-## RStudio
5454+## RStudio {#rstudio}
54555556RStudio uses a standard set of packages and ignores any custom R
5657environments or installed packages you may have. To create a custom
···9394one above. If you need additional packages just add them to the list and
9495re-enter the shell.
95969696-## Updating the package set
9797+## Updating the package set {#updating-the-package-set}
97989899```bash
99100nix-shell generate-shell.nix
···113114114115`generate-r-packages.R <repo>` reads `<repo>-packages.nix`, therefor the renaming.
115116116116-117117-## Testing if the Nix-expression could be evaluated
117117+## Testing if the Nix-expression could be evaluated {#testing-if-the-nix-expression-could-be-evaluated}
118118119119```bash
120120nix-build test-evaluation.nix --dry-run
+11-11
doc/languages-frameworks/ruby.section.md
···11# Ruby {#sec-language-ruby}
2233-## Using Ruby
33+## Using Ruby {#using-ruby}
4455Several 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`.
66···12121313Since 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.
14141515-### Temporary Ruby environment with `nix-shell`
1515+### Temporary Ruby environment with `nix-shell` {#temporary-ruby-environment-with-nix-shell}
16161717Rather 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`.
1818···30303131Again, 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.
32323333-#### Load Ruby environment from `.nix` expression
3333+#### Load Ruby environment from `.nix` expression {#load-ruby-environment-from-.nix-expression}
34343535As 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:
3636···45452. Then we create a Ruby environment with the `withPackages` function.
46463. 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.
47474848-#### Execute command with `--run`
4848+#### Execute command with `--run` {#execute-command-with---run}
49495050A convenient flag for `nix-shell` is `--run`. It executes a command in the `nix-shell`. We can e.g. directly open a `pry` REPL:
5151···6565$ nix-shell -p "ruby.withPackages (ps: with ps; [ nokogiri pry ])" --run "ruby example.rb"
6666```
67676868-#### Using `nix-shell` as shebang
6868+#### Using `nix-shell` as shebang {#using-nix-shell-as-shebang}
69697070In 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.
7171···8080puts Nokogiri::HTML(body).at('h1').text
8181```
82828383-## Developing with Ruby
8383+## Developing with Ruby {#developing-with-ruby}
84848585-### Using an existing Gemfile
8585+### Using an existing Gemfile {#using-an-existing-gemfile}
86868787In 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.
8888···120120mkShell { buildInputs = [ gems (lowPrio gems.wrappedRuby) ]; }
121121```
122122123123-### Gem-specific configurations and workarounds
123123+### Gem-specific configurations and workarounds {#gem-specific-configurations-and-workarounds}
124124125125In some cases, especially if the gem has native extensions, you might need to modify the way the gem is built.
126126···201201202202Of 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.
203203204204-### Adding a gem to the default gemset
204204+### Adding a gem to the default gemset {#adding-a-gem-to-the-default-gemset}
205205206206Now 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.
207207···215215NIX_PATH=nixpkgs=$PWD nix-shell -p "ruby.withPackages (ps: with ps; [ name-of-your-gem ])"
216216```
217217218218-### Packaging applications
218218+### Packaging applications {#packaging-applications}
219219220220A 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.
221221···243243244244All 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.
245245246246-#### Packaging executables that require wrapping
246246+#### Packaging executables that require wrapping {#packaging-executables-that-require-wrapping}
247247248248Sometimes your app will depend on other executables at runtime, and tries to find it through the `PATH` environment variable.
249249
+59-43
doc/languages-frameworks/rust.section.md
···1515use either `rustup` from nixpkgs (which will manage the rust installation in your home directory),
1616or use Mozilla's [Rust nightlies overlay](#using-the-rust-nightlies-overlay).
17171818-## Compiling Rust applications with Cargo
1818+## Compiling Rust applications with Cargo {#compiling-rust-applications-with-cargo}
19192020Rust applications are packaged by using the `buildRustPackage` helper from `rustPlatform`:
2121···107107}
108108```
109109110110-### Importing a `Cargo.lock` file
110110+### Importing a `Cargo.lock` file {#importing-a-cargo.lock-file}
111111112112Using `cargoSha256` or `cargoHash` is tedious when using
113113`buildRustPackage` within a project, since it requires that the hash
···156156`lib.fakeHash` as a stub hash. Building the package (and thus the
157157vendored dependencies) will then inform you of the correct hash.
158158159159-### Cross compilation
159159+### Cross compilation {#cross-compilation}
160160161161By default, Rust packages are compiled for the host platform, just like any
162162other package is. The `--target` passed to rust tools is computed from this.
···168168 name will be used instead.
169169170170 For example:
171171+171172 ```nix
172173 import <nixpkgs> {
173174 crossSystem = (import <nixpkgs/lib>).systems.examples.armhf-embedded // {
···175176 };
176177 }
177178 ```
179179+178180 will result in:
181181+179182 ```shell
180183 --target thumbv7em-none-eabi
181184 ```
···188191 will be used instead.
189192190193 For example:
194194+191195 ```nix
192196 import <nixpkgs> {
193197 crossSystem = (import <nixpkgs/lib>).systems.examples.armhf-embedded // {
···196200 };
197201 }
198202 ```
203203+199204 will result in:
205205+200206 ```shell
201207 --target /nix/store/asdfasdfsadf-thumb-crazy.json # contains {"foo":"","bar":""}
202208 ```
···220226Note that currently custom targets aren't compiled with `std`, so `cargo test`
221227will fail. This can be ignored by adding `doCheck = false;` to your derivation.
222228223223-### Running package tests
229229+### Running package tests {#running-package-tests}
224230225231When using `buildRustPackage`, the `checkPhase` is enabled by default and runs
226232`cargo test` on the package to build. To make sure that we don't compile the
···248254binary itself, as stated
249255(here)[https://doc.rust-lang.org/cargo/commands/cargo-test.html].
250256251251-#### Tests relying on the structure of the `target/` directory
257257+#### Tests relying on the structure of the `target/` directory {#tests-relying-on-the-structure-of-the-target-directory}
252258253259Some tests may rely on the structure of the `target/` directory. Those tests
254260are likely to fail because we use `cargo --target` during the build. This means that
···258264259265This can only be worked around by patching the affected tests accordingly.
260266261261-#### Disabling package-tests
267267+#### Disabling package-tests {#disabling-package-tests}
262268263269In some instances, it may be necessary to disable testing altogether (with `doCheck = false;`):
264270···272278However, please check if it's possible to disable a problematic subset of the
273279test suite and leave a comment explaining your reasoning.
274280275275-#### Setting `test-threads`
281281+#### Setting `test-threads` {#setting-test-threads}
276282277283`buildRustPackage` will use parallel test threads by default,
278284sometimes it may be necessary to disable this so the tests run consecutively.
···284290}
285291```
286292287287-### Building a package in `debug` mode
293293+### Building a package in `debug` mode {#building-a-package-in-debug-mode}
288294289295By default, `buildRustPackage` will use `release` mode for builds. If a package
290296should be built in `debug` mode, it can be configured like so:
···298304299305In this scenario, the `checkPhase` will be ran in `debug` mode as well.
300306301301-### Custom `build`/`install`-procedures
307307+### Custom `build`/`install`-procedures {#custom-buildinstall-procedures}
302308303309Some packages may use custom scripts for building/installing, e.g. with a `Makefile`.
304310In these cases, it's recommended to override the `buildPhase`/`installPhase`/`checkPhase`.
305311306312Otherwise, some steps may fail because of the modified directory structure of `target/`.
307313308308-### Building a crate with an absent or out-of-date Cargo.lock file
314314+### 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}
309315310316`buildRustPackage` needs a `Cargo.lock` file to get all dependencies in the
311317source code in a reproducible way. If it is missing or out-of-date one can use
···321327}
322328```
323329324324-## Compiling non-Rust packages that include Rust code
330330+## Compiling non-Rust packages that include Rust code {#compiling-non-rust-packages-that-include-rust-code}
325331326332Several non-Rust packages incorporate Rust code for performance- or
327333security-sensitive parts. `rustPlatform` exposes several functions and
328334hooks that can be used to integrate Cargo in non-Rust packages.
329335330330-### Vendoring of dependencies
336336+### Vendoring of dependencies {#vendoring-of-dependencies}
331337332338Since network access is not allowed in sandboxed builds, Rust crate
333339dependencies need to be retrieved using a fetcher. `rustPlatform`
···387393`lib.fakeHash` as a stub hash. Building `cargoDeps` will then inform
388394you of the correct hash.
389395390390-### Hooks
396396+### Hooks {#hooks}
391397392398`rustPlatform` provides the following hooks to automate Cargo builds:
393399···416422* `cargoInstallHook`: install binaries and static/shared libraries
417423 that were built using `cargoBuildHook`.
418424419419-### Examples
425425+### Examples {#examples}
420426421421-#### Python package using `setuptools-rust`
427427+#### Python package using `setuptools-rust` {#python-package-using-setuptools-rust}
422428423429For Python packages using `setuptools-rust`, you can use
424430`fetchCargoTarball` and `cargoSetupHook` to retrieve and set up Cargo
···504510}
505511```
506512507507-#### Python package using `maturin`
513513+#### Python package using `maturin` {#python-package-using-maturin}
508514509515Python packages that use [Maturin](https://github.com/PyO3/maturin)
510516can be built with `fetchCargoTarball`, `cargoSetupHook`, and
···545551}
546552```
547553548548-## Compiling Rust crates using Nix instead of Cargo
554554+## Compiling Rust crates using Nix instead of Cargo {#compiling-rust-crates-using-nix-instead-of-cargo}
549555550550-### Simple operation
556556+### Simple operation {#simple-operation}
551557552558When run, `cargo build` produces a file called `Cargo.lock`,
553559containing pinned versions of all dependencies. Nixpkgs contains a
···558564and can be used to compile a crate and all its dependencies. Here is
559565an example for a minimal `hello` crate:
560566561561-562562- $ cargo new hello
563563- $ cd hello
564564- $ cargo build
567567+```ShellSession
568568+$ cargo new hello
569569+$ cd hello
570570+$ cargo build
565571 Compiling hello v0.1.0 (file:///tmp/hello)
566566- Finished dev [unoptimized + debuginfo] target(s) in 0.20 secs
567567- $ carnix -o hello.nix --src ./. Cargo.lock --standalone
568568- $ nix-build hello.nix -A hello_0_1_0
572572+ Finished dev [unoptimized + debuginfo] target(s) in 0.20 secs
573573+$ carnix -o hello.nix --src ./. Cargo.lock --standalone
574574+$ nix-build hello.nix -A hello_0_1_0
575575+```
569576570577Now, the file produced by the call to `carnix`, called `hello.nix`, looks like:
571578···644651will fetch it from [crates.io](https://crates.io). A `sha256`
645652attribute is still needed for Nix purity.
646653647647-### Handling external dependencies
654654+### Handling external dependencies {#handling-external-dependencies}
648655649656Some crates require external libraries. For crates from
650657[crates.io](https://crates.io), such libraries can be specified in
···703710}
704711```
705712706706-### Options and phases configuration
713713+### Options and phases configuration {#options-and-phases-configuration}
707714708715Actually, the overrides introduced in the previous section are more
709716general. A number of other parameters can be overridden:
···750757 };
751758 ```
752759753753-### Features
760760+### Features {#features}
754761755762One can also supply features switches. For example, if we want to
756763compile `diesel_cli` only with the `postgres` feature, and no default
···765772766773Where `diesel.nix` is the file generated by Carnix, as explained above.
767774775775+## Setting Up `nix-shell` {#setting-up-nix-shell}
768776769769-## Setting Up `nix-shell`
770777Oftentimes you want to develop code from within `nix-shell`. Unfortunately
771778`buildRustCrate` does not support common `nix-shell` operations directly
772779(see [this issue](https://github.com/NixOS/nixpkgs/issues/37945))
773780so we will use `stdenv.mkDerivation` instead.
774781775782Using the example `hello` project above, we want to do the following:
783783+776784- Have access to `cargo` and `rustc`
777785- Have the `openssl` library available to a crate through it's _normal_
778786 compilation mechanism (`pkg-config`).
···801809```
802810803811You should now be able to run the following:
804804-```ShellSesssion
812812+813813+```ShellSession
805814$ nix-shell --pure
806815$ cargo build
807816$ cargo test
808817```
809818810810-### Controlling Rust Version Inside `nix-shell`
819819+### Controlling Rust Version Inside `nix-shell` {#controlling-rust-version-inside-nix-shell}
820820+811821To control your rust version (i.e. use nightly) from within `shell.nix` (or
812822other nix expressions) you can use the following `shell.nix`
813823···839849```
840850841851Now run:
852852+842853```ShellSession
843854$ rustc --version
844855rustc 1.26.0-nightly (188e693b3 2018-03-26)
···846857847858To see that you are using nightly.
848859849849-850850-## Using the Rust nightlies overlay
860860+## Using the Rust nightlies overlay {#using-the-rust-nightlies-overlay}
851861852862Mozilla provides an overlay for nixpkgs to bring a nightly version of Rust into scope.
853863This overlay can _also_ be used to install recent unstable or stable versions
854864of Rust, if desired.
855865856856-### Rust overlay installation
866866+### Rust overlay installation {#rust-overlay-installation}
857867858868You can use this overlay by either changing your local nixpkgs configuration,
859869or by adding the overlay declaratively in a nix expression, e.g. in `configuration.nix`.
860860-For more information see [#sec-overlays-install](the manual on installing overlays).
870870+For more information see [the manual on installing overlays](#sec-overlays-install).
861871862862-#### Imperative rust overlay installation
872872+#### Imperative rust overlay installation {#imperative-rust-overlay-installation}
863873864874Clone [nixpkgs-mozilla](https://github.com/mozilla/nixpkgs-mozilla),
865875and create a symbolic link to the file
866876[rust-overlay.nix](https://github.com/mozilla/nixpkgs-mozilla/blob/master/rust-overlay.nix)
867877in the `~/.config/nixpkgs/overlays` directory.
868878869869- $ git clone https://github.com/mozilla/nixpkgs-mozilla.git
870870- $ mkdir -p ~/.config/nixpkgs/overlays
871871- $ ln -s $(pwd)/nixpkgs-mozilla/rust-overlay.nix ~/.config/nixpkgs/overlays/rust-overlay.nix
879879+```ShellSession
880880+$ git clone https://github.com/mozilla/nixpkgs-mozilla.git
881881+$ mkdir -p ~/.config/nixpkgs/overlays
882882+$ ln -s $(pwd)/nixpkgs-mozilla/rust-overlay.nix ~/.config/nixpkgs/overlays/rust-overlay.nix
883883+```
872884873873-### Declarative rust overlay installation
885885+### Declarative rust overlay installation {#declarative-rust-overlay-installation}
874886875887Add the following to your `configuration.nix`, `home-configuration.nix`, `shell.nix`, or similar:
876888···886898887899Note that this will fetch the latest overlay version when rebuilding your system.
888900889889-### Rust overlay usage
901901+### Rust overlay usage {#rust-overlay-usage}
890902891903The overlay contains attribute sets corresponding to different versions of the rust toolchain, such as:
892904···900912901913Imperatively, the latest stable version can be installed with the following command:
902914903903- $ nix-env -Ai nixpkgs.latest.rustChannels.stable.rust
915915+```ShellSession
916916+$ nix-env -Ai nixpkgs.latest.rustChannels.stable.rust
917917+```
904918905919Or using the attribute with nix-shell:
906920907907- $ nix-shell -p nixpkgs.latest.rustChannels.stable.rust
921921+```ShellSession
922922+$ nix-shell -p nixpkgs.latest.rustChannels.stable.rust
923923+```
908924909925Substitute the `nixpkgs` prefix with `nixos` on NixOS.
910926To install the beta or nightly channel, "stable" should be substituted by
+2
doc/languages-frameworks/texlive.section.md
···55## User's guide {#sec-language-texlive-user-guide}
6677- For basic usage just pull `texlive.combined.scheme-basic` for an environment with basic LaTeX support.
88+89- It typically won't work to use separately installed packages together. Instead, you can build a custom set of packages like this:
9101011 ```nix
···1415 ```
15161617- There are all the schemes, collections and a few thousand packages, as defined upstream (perhaps with tiny differences).
1818+1719- 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`.
18201921 ```nix
+4-4
doc/languages-frameworks/titanium.section.md
···99Not all Titanium features supported -- currently, it can only be used to build
1010Android and iOS apps.
11111212-Building a Titanium app
1313------------------------
1212+## Building a Titanium app {#building-a-titanium-app}
1313+1414We can build a Titanium app from source for Android or iOS and for debugging or
1515release purposes by invoking the `titaniumenv.buildApp {}` function:
1616···103103path of the PHP script (`installURL`) (that is included with the iOS build
104104environment) to enable wireless ad-hoc installations.
105105106106-Emulating or simulating the app
107107--------------------------------
106106+## Emulating or simulating the app {#emulating-or-simulating-the-app}
107107+108108It is also possible to simulate the correspond iOS simulator build by using
109109`xcodeenv.simulateApp {}` and emulate an Android APK by using
110110`androidenv.emulateApp {}`.
+10-10
doc/languages-frameworks/vim.section.md
···1212- Pathogen
1313- vim-plug
14141515-## Custom configuration
1515+## Custom configuration {#custom-configuration}
16161717Adding custom .vimrc lines can be done using the following code:
1818···5656}
5757```
58585959-## Managing plugins with Vim packages
5959+## Managing plugins with Vim packages {#managing-plugins-with-vim-packages}
60606161To store you plugins in Vim packages (the native Vim plugin manager, see `:help packages`) the following example can be used:
6262···116116117117After that you can install your special grafted `myVim` or `myNeovim` packages.
118118119119-### What if your favourite Vim plugin isn't already packaged?
119119+### What if your favourite Vim plugin isn’t already packaged? {#what-if-your-favourite-vim-plugin-isnt-already-packaged}
120120121121If one of your favourite plugins isn't packaged, you can package it yourself:
122122···154154}
155155```
156156157157-## Managing plugins with vim-plug
157157+## Managing plugins with vim-plug {#managing-plugins-with-vim-plug}
158158159159To use [vim-plug](https://github.com/junegunn/vim-plug) to manage your Vim
160160plugins the following example can be used:
···183183}
184184```
185185186186-## Managing plugins with VAM
186186+## Managing plugins with VAM {#managing-plugins-with-vam}
187187188188-### Handling dependencies of Vim plugins
188188+### Handling dependencies of Vim plugins {#handling-dependencies-of-vim-plugins}
189189190190VAM introduced .json files supporting dependencies without versioning
191191assuming that "using latest version" is ok most of the time.
192192193193-### Example
193193+### Example {#example}
194194195195First create a vim-scripts file having one plugin name per line. Example:
196196···280280]
281281```
282282283283-## Adding new plugins to nixpkgs
283283+## Adding new plugins to nixpkgs {#adding-new-plugins-to-nixpkgs}
284284285285Nix 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`.
286286···298298299299Finally, 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.
300300301301-## Updating plugins in nixpkgs
301301+## Updating plugins in nixpkgs {#updating-plugins-in-nixpkgs}
302302303303Run 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).
304304···312312./pkgs/misc/vim-plugins/update.py --proc 1
313313```
314314315315-## Important repositories
315315+## Important repositories {#important-repositories}
316316317317- [vim-pi](https://bitbucket.org/vimcommunity/vim-pi) is a plugin repository
318318 from VAM plugin manager meant to be used by others as well used by
+1-1
doc/preface.chapter.md
···1212expression language, then you are kindly referred to the [Nix manual](https://nixos.org/nix/manual/).
1313The NixOS distribution is documented in the [NixOS manual](https://nixos.org/nixos/manual/).
14141515-## Overview of Nixpkgs
1515+## Overview of Nixpkgs {#overview-of-nixpkgs}
16161717Nix expressions describe how to build packages from source and are collected in
1818the [nixpkgs repository](https://github.com/NixOS/nixpkgs). Also included in the
+19-16
doc/stdenv/cross-compilation.chapter.md
···6677This 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.
8899-109## Packaging in a cross-friendly manner {#sec-cross-packaging}
11101211### Platform parameters {#ssec-cross-platform-parameters}
···65646665### Theory of dependency categorization {#ssec-cross-dependency-categorization}
67666868-::: note
6969-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"/>.
6767+::: {.note}
6868+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).
7069:::
71707271In this section we explore the relationship between both runtime and build-time dependencies and the 3 Autoconf platforms.
···81808281Putting this all together, that means we have dependencies in the form "host → target", in at most the following six combinations:
83828383+#### Possible dependency types {#possible-dependency-types}
84848585-#### Possible dependency types
8686-| Dependency's host platform | Dependency's target platform |
8787-| -- | -- |
8585+| Dependency’s host platform | Dependency’s target platform |
8686+|----------------------------|------------------------------|
8887| build | build |
8988| build | host |
9089| build | target |
···113112$ nix-build '<nixpkgs>' -A pkgsCross.raspberryPi.hello
114113```
115114116116-#### 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}
115115+#### 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}
116116+117117Add the following to your `mkDerivation` invocation.
118118+118119```nix
119120depsBuildBuild = [ buildPackages.stdenv.cc ];
120121```
121122122122-#### My package's testsuite needs to run host platform code. {#cross-testsuite-runs-host-code}
123123+#### My package’s testsuite needs to run host platform code. {#cross-testsuite-runs-host-code}
123124124125Add the following to your `mkDerivation` invocation.
126126+125127```nix
126128doCheck = stdenv.hostPlatform == stdenv.buildPlatform;
127129```
···134136$ nix-build '<nixpkgs>' --arg crossSystem '(import <nixpkgs/lib>).systems.examples.fooBarBaz' -A whatever
135137```
136138137137-::: note
139139+::: {.note}
138140Eventually we would like to make these platform examples an unnecessary convenience so that
139141140142```ShellSession
···146148147149While 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.
148150149149-::: note
151151+::: {.note}
150152Many 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.
151153:::
152154···156158157159### Implementation of dependencies {#ssec-cross-dependency-implementation}
158160159159-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.
161161+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.
160162161163Now, 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.
162164···178180179181In 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`.
180182181181-::: note
183183+::: {.note}
182184The 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.
183185:::
184186···186188```
187189(native, native, native, foreign, foreign)
188190```
191191+189192If 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:
190193```
191194(native..., native, native, native, foreign, foreign, foreign...)
···193196One 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".
194197195198196196-::: note
197197-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.
199199+::: {.note}
200200+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.
198201199202First, 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`
200203···203206Thirdly, 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.
204207:::
205208206206-::: note
207207-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.
209209+::: {.note}
210210+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.
208211:::
+5-5
doc/stdenv/meta.chapter.md
···130130131131### `tests` {#var-meta-tests}
132132133133-::: warning
133133+::: {.warning}
134134This 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.
135135:::
136136···175175176176Although it’s typically better to indicate the specific license, a few generic options are available:
177177178178-### `lib.licenses.free`, `"free"`
178178+### `lib.licenses.free`, `"free"` {#lib.licenses.free-free}
179179180180Catch-all for free software licenses not listed above.
181181182182-### `lib.licenses.unfreeRedistributable`, `"unfree-redistributable"`
182182+### `lib.licenses.unfreeRedistributable`, `"unfree-redistributable"` {#lib.licenses.unfreeredistributable-unfree-redistributable}
183183184184Unfree 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.
185185186186Sometimes 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.
187187188188-### `lib.licenses.unfree`, `"unfree"`
188188+### `lib.licenses.unfree`, `"unfree"` {#lib.licenses.unfree-unfree}
189189190190Unfree 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.
191191192192-### `lib.licenses.unfreeRedistributableFirmware`, `"unfree-redistributable-firmware"`
192192+### `lib.licenses.unfreeRedistributableFirmware`, `"unfree-redistributable-firmware"` {#lib.licenses.unfreeredistributablefirmware-unfree-redistributable-firmware}
193193194194This 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
···6677The 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.
8899-::: note
99+::: {.note}
1010The 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.
1111:::
1212···28282929`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.
30303131-::: warning
3131+::: {.warning}
3232`nix-env` silenty disregards the outputs selected by the user, and instead installs the outputs from `meta.outputsToInstall`. For example,
33333434```ShellSession
···3838installs the `"out"` output (`coreutils.meta.outputsToInstall` is `[ "out" ]`) instead of the requested `"info"`.
3939:::
40404141-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:
4141+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:
42424343```nix
4444self: super:
···53535454In 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.
55555656-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" />.)
5656+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).)
57575858In 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.)
5959···69697070Often 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.
71717272-::: note
7373-There is a special handling of the `debug` output, described at <xref linkend="stdenv-separateDebugInfo" />.
7272+::: {.note}
7373+There is a special handling of the `debug` output, described at [](#stdenv-separateDebugInfo).
7474:::
75757676### “Binaries first” {#multiple-output-file-binaries-first-convention}
···85858686The 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.
87878888-#### ` $outputDev`
8888+#### `$outputDev` {#outputdev}
89899090is 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.
91919292-#### ` $outputBin`
9292+#### `$outputBin` {#outputbin}
93939494is meant for user-facing binaries, typically residing in `bin/`. They go to `bin` or `out` by default.
95959696-#### ` $outputLib`
9696+#### `$outputLib` {#outputlib}
97979898is meant for libraries, typically residing in `lib/` and `libexec/`. They go to `lib` or `out` by default.
9999100100-#### ` $outputDoc`
100100+#### `$outputDoc` {#outputdoc}
101101102102is for user documentation, typically residing in `share/doc/`. It goes to `doc` or `out` by default.
103103104104-#### ` $outputDevdoc`
104104+#### `$outputDevdoc` {#outputdevdoc}
105105106106is 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.
107107108108-#### ` $outputMan`
108108+#### `$outputMan` {#outputman}
109109110110is for man pages (except for section 3), typically residing in `share/man/man[0-9]/`. They go to `man` or `$outputBin` by default.
111111112112-#### ` $outputDevman`
112112+#### `$outputDevman` {#outputdevman}
113113114114is for section 3 man pages, typically residing in `share/man/man[0-9]/`. They go to `devman` or `$outputMan` by default.
115115116116-#### ` $outputInfo`
116116+#### `$outputInfo` {#outputinfo}
117117118118is for info pages, typically residing in `share/info/`. They go to `info` or `$outputBin` by default.
119119
+74-72
doc/stdenv/stdenv.chapter.md
···3939}
4040```
41414242-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.)
4242+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.)
43434444-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:
4444+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:
45454646```nix
4747stdenv.mkDerivation {
···59596060(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.)
61616262-There are many other attributes to customise the build. These are listed in <xref linkend="ssec-stdenv-attributes" />.
6262+There are many other attributes to customise the build. These are listed in [](#ssec-stdenv-attributes).
63636464While the standard environment provides a generic builder, you can still supply your own build script:
6565···116116117117## Specifying dependencies {#ssec-stdenv-dependencies}
118118119119-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.
119119+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.
120120121121-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.
121121+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.
122122123123The 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.
124124···175175176176Overall, 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.
177177178178-### Variables specifying dependencies
178178+### Variables specifying dependencies {#variables-specifying-dependencies}
179179+179180#### `depsBuildBuild` {#var-stdenv-depsBuildBuild}
180181181182A 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.
···236237237238## Attributes {#ssec-stdenv-attributes}
238239239239-### Variables affecting `stdenv` initialisation
240240+### Variables affecting `stdenv` initialisation {#variables-affecting-stdenv-initialisation}
240241241242#### `NIX_DEBUG` {#var-stdenv-NIX_DEBUG}
242243243244A 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.
244245245245-### Attributes affecting build properties
246246+### Attributes affecting build properties {#attributes-affecting-build-properties}
246247247248#### `enableParallelBuilding` {#var-stdenv-enableParallelBuilding}
248249···250251251252Unless set to `false`, some build systems with good support for parallel building including `cmake`, `meson`, and `qmake` will set it to `true`.
252253253253-### Special variables
254254+### Special variables {#special-variables}
254255255256#### `passthru` {#var-stdenv-passthru}
256257···298299299300The script will be run with `UPDATE_NIX_ATTR_PATH` environment variable set to the attribute path it is supposed to update.
300301301301-::: note
302302+::: {.note}
302303The 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.
303304:::
304305···314315315316There are a number of variables that control what phases are executed and in what order:
316317317317-#### Variables affecting phase control
318318+#### Variables affecting phase control {#variables-affecting-phase-control}
318319319320##### `phases` {#var-stdenv-phases}
320321···354355355356The 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:
356357357357-#### Tar files
358358+#### Tar files {#tar-files}
358359359360These 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`).
360361361361-#### Zip files
362362+#### Zip files {#zip-files}
362363363364Zip files are unpacked using `unzip`. However, `unzip` is not in the standard environment, so you should add it to `nativeBuildInputs` yourself.
364365365365-#### Directories in the Nix store
366366+#### Directories in the Nix store {#directories-in-the-nix-store}
366367367368These 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`.
368369369370Additional file types can be supported by setting the `unpackCmd` variable (see below).
370371371371-#### Variables controlling the unpack phase
372372+#### Variables controlling the unpack phase {#variables-controlling-the-unpack-phase}
373373+372374##### `srcs` / `src` {#var-stdenv-src}
373375374376The list of source files or directories to be unpacked or copied. One of these must be set.
···405407406408The patch phase applies the list of patches defined in the `patches` variable.
407409408408-#### Variables controlling the patch phase
410410+#### Variables controlling the patch phase {#variables-controlling-the-patch-phase}
409411410412##### `dontPatch` {#var-stdenv-dontPatch}
411413···431433432434The configure phase prepares the source tree for building. The default `configurePhase` runs `./configure` (typically an Autoconf-generated script) if it exists.
433435434434-#### Variables controlling the configure phase
436436+#### Variables controlling the configure phase {#variables-controlling-the-configure-phase}
435437436438##### `configureScript` {#var-stdenv-configureScript}
437439···491493492494The 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.
493495494494-#### Variables controlling the build phase
496496+#### Variables controlling the build phase {#variables-controlling-the-build-phase}
495497496498##### `dontBuild` {#var-stdenv-dontBuild}
497499···509511makeFlags = [ "PREFIX=$(out)" ];
510512```
511513512512-::: note
514514+::: {.note}
513515The flags are quoted in bash, but environment variables can be specified by using the make syntax.
514516:::
515517···545547546548The 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.
547549548548-#### Variables controlling the check phase
550550+#### Variables controlling the check phase {#variables-controlling-the-check-phase}
549551550552##### `doCheck` {#var-stdenv-doCheck}
551553···557559558560in 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.
559561560560-##### `makeFlags` / `makeFlagsArray` / `makefile`
562562+##### `makeFlags` / `makeFlagsArray` / `makefile` {#makeflags-makeflagsarray-makefile}
561563562564See the [build phase](#var-stdenv-makeFlags) for details.
563565···585587586588The 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`.
587589588588-#### Variables controlling the install phase
590590+#### Variables controlling the install phase {#variables-controlling-the-install-phase}
589591590592##### `dontInstall` {#var-stdenv-dontInstall}
591593592594Set to true to skip the install phase.
593595594594-##### `makeFlags` / `makeFlagsArray` / `makefile`
596596+##### `makeFlags` / `makeFlagsArray` / `makefile` {#makeflags-makeflagsarray-makefile-1}
595597596598See the [build phase](#var-stdenv-makeFlags) for details.
597599···624626- 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.
625627- 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`.
626628627627-#### Variables controlling the fixup phase
629629+#### Variables controlling the fixup phase {#variables-controlling-the-fixup-phase}
628630629631##### `dontFixup` {#var-stdenv-dontFixup}
630632···706708707709The installCheck phase checks whether the package was installed correctly by running its test suite against the installed directories. The default `installCheck` calls `make installcheck`.
708710709709-#### Variables controlling the installCheck phase
711711+#### Variables controlling the installCheck phase {#variables-controlling-the-installcheck-phase}
710712711713##### `doInstallCheck` {#var-stdenv-doInstallCheck}
712714···742744743745The 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.
744746745745-#### Variables controlling the distribution phase
747747+#### Variables controlling the distribution phase {#variables-controlling-the-distribution-phase}
746748747749##### `distTarget` {#var-stdenv-distTarget}
748750···879881880882Packages 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
881883882882-```{.bash}
884884+```bash
883885addEnvHooks "$hostOffset" myBashFunction
884886```
885887···887889888890First, 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.
889891890890-### `move-docs.sh`
892892+### `move-docs.sh` {#move-docs.sh}
891893892894This 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.
893895894894-### `compress-man-pages.sh`
896896+### `compress-man-pages.sh` {#compress-man-pages.sh}
895897896898This 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.
897899898898-### `strip.sh`
900900+### `strip.sh` {#strip.sh}
899901900902This 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.
901903902902-### `patch-shebangs.sh`
904904+### `patch-shebangs.sh` {#patch-shebangs.sh}
903905904906This 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.
905907906906-### `audit-tmpdir.sh`
908908+### `audit-tmpdir.sh` {#audit-tmpdir.sh}
907909908910This 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.
909911910910-### `multiple-outputs.sh`
912912+### `multiple-outputs.sh` {#multiple-outputs.sh}
911913912912-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.
914914+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.
913915914914-### `move-sbin.sh`
916916+### `move-sbin.sh` {#move-sbin.sh}
915917916918This setup hook moves any binaries installed in the `sbin/` subdirectory into `bin/`. In addition, a link is provided from `sbin/` to `bin/` for compatibility.
917919918918-### `move-lib64.sh`
920920+### `move-lib64.sh` {#move-lib64.sh}
919921920922This setup hook moves any libraries installed in the `lib64/` subdirectory into `lib/`. In addition, a link is provided from `lib64/` to `lib/` for compatibility.
921923922922-### `move-systemd-user-units.sh`
924924+### `move-systemd-user-units.sh` {#move-systemd-user-units.sh}
923925924926This 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.
925927926926-### `set-source-date-epoch-to-latest.sh`
928928+### `set-source-date-epoch-to-latest.sh` {#set-source-date-epoch-to-latest.sh}
927929928930This sets `SOURCE_DATE_EPOCH` to the modification time of the most recent file.
929931930930-### Bintools Wrapper
932932+### Bintools Wrapper {#bintools-wrapper}
931933932934The 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.
933935···937939938940A 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"`.
939941940940-### CC Wrapper
942942+### CC Wrapper {#cc-wrapper}
941943942944The 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.
943945···971973972974Adds 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.
973975974974-### teTeX / TeX Live
976976+### teTeX / TeX Live {#tetex-tex-live}
975977976978Adds the `share/texmf-nix` subdirectory of each build input to the `TEXINPUTS` environment variable.
977979978978-### Qt 4
980980+### Qt 4 {#qt-4}
979981980982Sets the `QTDIR` environment variable to Qt’s path.
981983···983985984986Exports `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).
985987986986-### GHC
988988+### GHC {#ghc}
987989988990Creates a temporary package database and registers every Haskell build input in it (TODO: how?).
989991990990-### GNOME platform
992992+### GNOME platform {#gnome-platform}
991993992992-Hooks related to GNOME platform and related libraries like GLib, GTK and GStreamer are described in <xref linkend="sec-language-gnome" />.
994994+Hooks related to GNOME platform and related libraries like GLib, GTK and GStreamer are described in [](#sec-language-gnome).
993995994996### autoPatchelfHook {#setup-hook-autopatchelfhook}
995997···1003100510041006The `autoPatchelf` command also recognizes a `--no-recurse` command line flag, which prevents it from recursing into subdirectories.
1005100710061006-### breakpointHook
10081008+### breakpointHook {#breakpointhook}
1007100910081010This 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`.
10091011···1013101510141016When a build failure happens there will be an instruction printed that shows how to attach with `cntr` to the build sandbox.
1015101710161016-::: note
10171017-::: title
10181018+::: {.note}
10191019+::: {.title}
10181020Caution with remote builds
10191021:::
1020102210211023This 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`.
10221024:::
1023102510241024-### installShellFiles
10261026+### installShellFiles {#installshellfiles}
1025102710261028This 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.
10271029···10471049'';
10481050```
1049105110501050-### libiconv, libintl
10521052+### libiconv, libintl {#libiconv-libintl}
1051105310521054A 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`.
1053105510541054-### validatePkgConfig
10561056+### validatePkgConfig {#validatepkgconfig}
1055105710561058The `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.
1057105910581058-### cmake
10601060+### cmake {#cmake}
1059106110601062Overrides 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.
1061106310621062-### xcbuildHook
10641064+### xcbuildHook {#xcbuildhook}
1063106510641066Overrides 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.
1065106710661066-### Meson
10681068+### Meson {#meson}
1067106910681070Overrides 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.
1069107110701070-#### Variables controlling Meson
10721072+#### Variables controlling Meson {#variables-controlling-meson}
1071107310721072-##### `mesonFlags`
10741074+##### `mesonFlags` {#mesonflags}
1073107510741076Controls the flags passed to meson.
1075107710761076-##### `mesonBuildType`
10781078+##### `mesonBuildType` {#mesonbuildtype}
1077107910781080Which [`--buildtype`](https://mesonbuild.com/Builtin-options.html#core-options) to pass to Meson. We default to `plain`.
1079108110801080-##### `mesonAutoFeatures`
10821082+##### `mesonAutoFeatures` {#mesonautofeatures}
1081108310821084What value to set [`-Dauto_features=`](https://mesonbuild.com/Builtin-options.html#core-options) to. We default to `enabled`.
1083108510841084-##### `mesonWrapMode`
10861086+##### `mesonWrapMode` {#mesonwrapmode}
1085108710861088What value to set [`-Dwrap_mode=`](https://mesonbuild.com/Builtin-options.html#core-options) to. We default to `nodownload` as we disallow network access.
1087108910881088-##### `dontUseMesonConfigure`
10901090+##### `dontUseMesonConfigure` {#dontusemesonconfigure}
1089109110901092Disables using Meson’s `configurePhase`.
1091109310921092-### ninja
10941094+### ninja {#ninja}
1093109510941096Overrides 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.
1095109710961096-### unzip
10981098+### unzip {#unzip}
1097109910981100This setup hook will allow you to unzip .zip files specified in `$src`. There are many similar packages like `unrar`, `undmg`, etc.
1099110111001100-### wafHook
11021102+### wafHook {#wafhook}
1101110311021104Overrides 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.
1103110511041104-### scons
11061106+### scons {#scons}
1105110711061108Overrides 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.
11071109···1119112111201122The following flags are enabled by default and might require disabling with `hardeningDisable` if the program to package is incompatible.
1121112311221122-### `format`
11241124+### `format` {#format}
1123112511241126Adds 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`.
11251127···11321134cc1plus: some warnings being treated as errors
11331135```
1134113611351135-### `stackprotector`
11371137+### `stackprotector` {#stackprotector}
1136113811371139Adds 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).
11381140···11431145/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'
11441146```
1145114711461146-### `fortify`
11481148+### `fortify` {#fortify}
1147114911481150Adds 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.
11491151···11641166fcntl2.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
11651167```
1166116811671167-### `pic`
11691169+### `pic` {#pic}
1168117011691171Adds the `-fPIC` compiler options. This options adds support for position independent code in shared libraries and thus making ASLR possible.
11701172···11771179ccbLfRgg.s:33: Error: missing or invalid displacement expression `private_key_len@GOTOFF'
11781180```
1179118111801180-### `strictoverflow`
11821182+### `strictoverflow` {#strictoverflow}
1181118311821184Signed 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.
1183118511841186This flag should not trigger any build or runtime errors.
1185118711861186-### `relro`
11881188+### `relro` {#relro}
1187118911881190Adds 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.
1189119111901192This 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.
1191119311921192-### `bindnow`
11941194+### `bindnow` {#bindnow}
1193119511941196Adds 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.
11951197···1201120312021204The following flags are disabled by default and should be enabled with `hardeningEnable` for packages that take untrusted input like network services.
1203120512041204-### `pie`
12061206+### `pie` {#pie}
1205120712061208Adds 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.
12071209
+1-1
doc/using/overlays.chapter.md
···63636464The value returned by this function should be a set similar to `pkgs/top-level/all-packages.nix`, containing overridden and/or new packages.
65656666-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.
6666+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.
67676868## Using overlays to configure alternatives {#sec-overlays-alternatives}
6969
+6-6
doc/using/overrides.chapter.md
···48484949The argument `oldAttrs` is conventionally used to refer to the attr set originally passed to `stdenv.mkDerivation`.
50505151-::: note
5252-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).
5151+::: {.note}
5252+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).
5353:::
54545555## <pkg>.overrideDerivation {#sec-pkg-overrideDerivation}
56565757-::: warning
5757+::: {.warning}
5858You 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`.
5959:::
60606161-::: warning
6161+::: {.warning}
6262Do 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`.
6363:::
6464···81818282The argument `oldAttrs` is used to refer to the attribute set of the original derivation.
83838484-::: note
8585-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.
8484+::: {.note}
8585+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.
8686:::
87878888## lib.makeOverridable {#sec-lib-makeOverridable}
···2424 </section>
2525 <section xml:id="new-services">
2626 <title>New Services</title>
2727- <itemizedlist spacing="compact">
2727+ <itemizedlist>
2828 <listitem>
2929 <para>
3030 <link xlink:href="https://github.com/maxmind/geoipupdate">geoipupdate</link>,
3131 a GeoIP database updater from MaxMind. Available as
3232 <link xlink:href="options.html#opt-services.geoipupdate.enable">services.geoipupdate</link>.
3333+ </para>
3434+ </listitem>
3535+ <listitem>
3636+ <para>
3737+ <link xlink:href="https://sr.ht">sourcehut</link>, a
3838+ collection of tools useful for software development. Available
3939+ as
4040+ <link xlink:href="options.html#opt-services.sourcehut.enable">services.sourcehut</link>.
3341 </para>
3442 </listitem>
3543 </itemizedlist>
+4
nixos/doc/manual/release-notes/rl-2111.section.md
···1414 database updater from MaxMind. Available as
1515 [services.geoipupdate](options.html#opt-services.geoipupdate.enable).
16161717+* [sourcehut](https://sr.ht), a collection of tools useful for software
1818+ development. Available as
1919+ [services.sourcehut](options.html#opt-services.sourcehut.enable).
2020+1721## Backward Incompatibilities
18221923* The `staticjinja` package has been upgraded from 1.0.4 to 2.0.0
+7
nixos/modules/virtualisation/libvirtd.nix
···155155156156 config = mkIf cfg.enable {
157157158158+ assertions = [
159159+ {
160160+ assertion = config.security.polkit.enable;
161161+ message = "The libvirtd module currently requires Polkit to be enabled ('security.polkit.enable = true').";
162162+ }
163163+ ];
164164+158165 environment = {
159166 # this file is expected in /etc/qemu and not sysconfdir (/var/lib)
160167 etc."qemu/bridge.conf".text = lib.concatMapStringsSep "\n" (e:
+2
pkgs/applications/editors/neovim/utils.nix
···148148 , vimAlias ? false
149149 , viAlias ? false
150150 , configure ? {}
151151+ , extraName ? ""
151152 }:
152153 let
153154 /* for compatibility with passing extraPythonPackages as a list; added 2018-07-11 */
···160161 extraPython3Packages = compatFun extraPython3Packages;
161162 inherit withNodeJs withRuby viAlias vimAlias;
162163 inherit configure;
164164+ inherit extraName;
163165 };
164166 in
165167 assert withPython -> throw "Python2 support has been removed from neovim, please remove withPython and extraPythonPackages.";
+16-12
pkgs/applications/editors/neovim/wrapper.nix
···2727 # set to false if you want to control where to save the generated config
2828 # (e.g., in ~/.config/init.vim or project/.nvimrc)
2929 , wrapRc ? true
3030+ , neovimRcContent ? ""
3031 , ...
3132 }@args:
3233 let
33343435 wrapperArgsStr = if isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs;
35363636- # If configure != {}, we can't generate the rplugin.vim file with e.g
3737- # NVIM_SYSTEM_RPLUGIN_MANIFEST *and* NVIM_RPLUGIN_MANIFEST env vars set in
3838- # the wrapper. That's why only when configure != {} (tested both here and
3939- # when postBuild is evaluated), we call makeWrapper once to generate a
4040- # wrapper with most arguments we need, excluding those that cause problems to
4141- # generate rplugin.vim, but still required for the final wrapper.
4242- finalMakeWrapperArgs =
4343- [ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim" ]
4444- ++ [ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ]
4545- ++ optionals wrapRc [ "--add-flags" "-u ${writeText "init.vim" args.neovimRcContent}" ]
4646- ;
3737+ # If configure != {}, we can't generate the rplugin.vim file with e.g
3838+ # NVIM_SYSTEM_RPLUGIN_MANIFEST *and* NVIM_RPLUGIN_MANIFEST env vars set in
3939+ # the wrapper. That's why only when configure != {} (tested both here and
4040+ # when postBuild is evaluated), we call makeWrapper once to generate a
4141+ # wrapper with most arguments we need, excluding those that cause problems to
4242+ # generate rplugin.vim, but still required for the final wrapper.
4343+ finalMakeWrapperArgs =
4444+ [ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim" ]
4545+ ++ [ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ]
4646+ ++ optionals wrapRc [ "--add-flags" "-u ${writeText "init.vim" neovimRcContent}" ]
4747+ ;
4748 in
4849 assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env.";
4950···116117 preferLocalBuild = true;
117118118119 nativeBuildInputs = [ makeWrapper ];
119119- passthru = { unwrapped = neovim; };
120120+ passthru = {
121121+ unwrapped = neovim;
122122+ initRc = neovimRcContent;
123123+ };
120124121125 meta = neovim.meta // {
122126 # To prevent builds on hydra
···1414 if libc == null then
1515 null
1616 else if stdenvNoCC.targetPlatform.isNetBSD then
1717- if libc != targetPackages.netbsdCross.headers then
1717+ if !(targetPackages ? netbsdCross) then
1818+ netbsd.ld_elf_so
1919+ else if libc != targetPackages.netbsdCross.headers then
1820 targetPackages.netbsdCross.ld_elf_so
1921 else
2022 null