From d8b5ed331d62890285d3ce5a81d336269cdcb394 Mon Sep 17 00:00:00 2001 From: fricklerhandwerk Date: Fri, 23 Apr 2021 10:42:08 +0200 Subject: [PATCH 1/2] doc/using: convert to markdown --- doc/manual.xml | 6 +- doc/using/configuration.chapter.md | 356 +++++++++++++++++++++++ doc/using/configuration.xml | 451 ----------------------------- doc/using/overlays.chapter.md | 149 ++++++++++ doc/using/overlays.xml | 279 ------------------ doc/using/overrides.chapter.md | 104 +++++++ doc/using/overrides.xml | 145 ---------- 7 files changed, 612 insertions(+), 878 deletions(-) create mode 100644 doc/using/configuration.chapter.md delete mode 100644 doc/using/configuration.xml create mode 100644 doc/using/overlays.chapter.md delete mode 100644 doc/using/overlays.xml create mode 100644 doc/using/overrides.chapter.md delete mode 100644 doc/using/overrides.xml diff --git a/doc/manual.xml b/doc/manual.xml index 6ea4addc361a..b43021d85ca5 100644 --- a/doc/manual.xml +++ b/doc/manual.xml @@ -8,9 +8,9 @@ Using Nixpkgs - - - + + + diff --git a/doc/using/configuration.chapter.md b/doc/using/configuration.chapter.md new file mode 100644 index 000000000000..e4d401368796 --- /dev/null +++ b/doc/using/configuration.chapter.md @@ -0,0 +1,356 @@ +# Global configuration {#chap-packageconfig} + +Nix comes with certain defaults about what packages can and cannot be installed, based on a package's metadata. By default, Nix will prevent installation if any of the following criteria are true: + +- The package is thought to be broken, and has had its `meta.broken` set to `true`. + +- The package isn't intended to run on the given system, as none of its `meta.platforms` match the given system. + +- The package's `meta.license` is set to a license which is considered to be unfree. + +- The package has known security vulnerabilities but has not or can not be updated for some reason, and a list of issues has been entered in to the package's `meta.knownVulnerabilities`. + +Note that all this is checked during evaluation already, and the check includes any package that is evaluated. In particular, all build-time dependencies are checked. `nix-env -qa` will (attempt to) hide any packages that would be refused. + +Each of these criteria can be altered in the nixpkgs configuration. + +The nixpkgs configuration for a NixOS system is set in the `configuration.nix`, as in the following example: + +```nix +{ + nixpkgs.config = { + allowUnfree = true; + }; +} +``` + +However, this does not allow unfree software for individual users. Their configurations are managed separately. + +A user's nixpkgs configuration is stored in a user-specific configuration file located at `~/.config/nixpkgs/config.nix`. For example: + +```nix +{ + allowUnfree = true; +} +``` + +Note that we are not able to test or build unfree software on Hydra due to policy. Most unfree licenses prohibit us from either executing or distributing the software. + +## Installing broken packages {#sec-allow-broken} + +There are two ways to try compiling a package which has been marked as broken. + +- For allowing the build of a broken package once, you can use an environment variable for a single invocation of the nix tools: + + ```shellSession + $ export NIXPKGS_ALLOW_BROKEN=1 + ``` + +- For permanently allowing broken packages to be built, you may add `allowBroken = true;` to your user's configuration file, like this: + + ```nix + { + allowBroken = true; + } + ``` + + +## Installing packages on unsupported systems {#sec-allow-unsupported-system} + +There are also two ways to try compiling a package which has been marked as unsupported for the given system. + +- For allowing the build of an unsupported package once, you can use an environment variable for a single invocation of the nix tools: + + ```shellSession + $ export NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 + ``` + +- For permanently allowing unsupported packages to be built, you may add `allowUnsupportedSystem = true;` to your user's configuration file, like this: + + ```nix + { + allowUnsupportedSystem = true; + } + ``` + +The difference between a package being unsupported on some system and being broken is admittedly a bit fuzzy. If a program *ought* to work on a certain platform, but doesn't, the platform should be included in `meta.platforms`, but marked as broken with e.g. `meta.broken = !hostPlatform.isWindows`. Of course, this begs the question of what \"ought\" means exactly. That is left to the package maintainer. + +## Installing unfree packages {#sec-allow-unfree} + +There are several ways to tweak how Nix handles a package which has been marked as unfree. + +- To temporarily allow all unfree packages, you can use an environment variable for a single invocation of the nix tools: + + ```shellSession + $ export NIXPKGS_ALLOW_UNFREE=1 + ``` + +- It is possible to permanently allow individual unfree packages, while still blocking unfree packages by default using the `allowUnfreePredicate` configuration option in the user configuration file. + + This option is a function which accepts a package as a parameter, and returns a boolean. The following example configuration accepts a package and always returns false: + + ```nix + { + allowUnfreePredicate = (pkg: false); + } + ``` + + For a more useful example, try the following. This configuration only allows unfree packages named roon-server and visual studio code: + + ```nix + { + allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ + "roon-server" + "vscode" + ]; + } + ``` + +- It is also possible to allow and block licenses that are specifically acceptable or not acceptable, using `allowlistedLicenses` and `blocklistedLicenses`, respectively. + + The following example configuration allowlists the licenses `amd` and `wtfpl`: + + ```nix + { + allowlistedLicenses = with lib.licenses; [ amd wtfpl ]; + } + ``` + + The following example configuration blocklists the `gpl3Only` and `agpl3Only` licenses: + + ```nix + { + blocklistedLicenses = with lib.licenses; [ agpl3Only gpl3Only ]; + } + ``` + + Note that `allowlistedLicenses` only applies to unfree licenses unless `allowUnfree` is enabled. It is not a generic allowlist for all types of licenses. `blocklistedLicenses` applies to all licenses. + +A complete list of licenses can be found in the file `lib/licenses.nix` of the nixpkgs tree. + +## Installing insecure packages {#sec-allow-insecure} + +There are several ways to tweak how Nix handles a package which has been marked as insecure. + +- To temporarily allow all insecure packages, you can use an environment variable for a single invocation of the nix tools: + + ```shellSession + $ export NIXPKGS_ALLOW_INSECURE=1 + ``` + +- It is possible to permanently allow individual insecure packages, while still blocking other insecure packages by default using the `permittedInsecurePackages` configuration option in the user configuration file. + + The following example configuration permits the installation of the hypothetically insecure package `hello`, version `1.2.3`: + + ```nix + { + permittedInsecurePackages = [ + "hello-1.2.3" + ]; + } + ``` + +- It is also possible to create a custom policy around which insecure packages to allow and deny, by overriding the `allowInsecurePredicate` configuration option. + + The `allowInsecurePredicate` option is a function which accepts a package and returns a boolean, much like `allowUnfreePredicate`. + + The following configuration example only allows insecure packages with very short names: + + ```nix + { + allowInsecurePredicate = pkg: builtins.stringLength (lib.getName pkg) <= 5; + } + ``` + + Note that `permittedInsecurePackages` is only checked if `allowInsecurePredicate` is not specified. + +## Modify packages via `packageOverrides` {#sec-modify-via-packageOverrides} + +You can define a function called `packageOverrides` in your local `~/.config/nixpkgs/config.nix` to override Nix packages. It must be a function that takes pkgs as an argument and returns a modified set of packages. + +```nix +{ + packageOverrides = pkgs: rec { + foo = pkgs.foo.override { ... }; + }; +} +``` + +## Declarative Package Management {#sec-declarative-package-management} + +### Build an environment {#sec-building-environment} + +Using `packageOverrides`, it is possible to manage packages declaratively. This means that we can list all of our desired packages within a declarative Nix expression. For example, to have `aspell`, `bc`, `ffmpeg`, `coreutils`, `gdb`, `nixUnstable`, `emscripten`, `jq`, `nox`, and `silver-searcher`, we could use the following in `~/.config/nixpkgs/config.nix`: + +```nix +{ + packageOverrides = pkgs: with pkgs; { + myPackages = pkgs.buildEnv { + name = "my-packages"; + paths = [ + aspell + bc + coreutils + gdb + ffmpeg + nixUnstable + emscripten + jq + nox + silver-searcher + ]; + }; + }; +} +``` + +To install it into our environment, you can just run `nix-env -iA nixpkgs.myPackages`. If you want to load the packages to be built from a working copy of `nixpkgs` you just run `nix-env -f. -iA myPackages`. To explore what's been installed, just look through `~/.nix-profile/`. You can see that a lot of stuff has been installed. Some of this stuff is useful some of it isn't. Let's tell Nixpkgs to only link the stuff that we want: + +```nix +{ + packageOverrides = pkgs: with pkgs; { + myPackages = pkgs.buildEnv { + name = "my-packages"; + paths = [ + aspell + bc + coreutils + gdb + ffmpeg + nixUnstable + emscripten + jq + nox + silver-searcher + ]; + pathsToLink = [ "/share" "/bin" ]; + }; + }; +} +``` + +`pathsToLink` tells Nixpkgs to only link the paths listed which gets rid of the extra stuff in the profile. `/bin` and `/share` are good defaults for a user environment, getting rid of the clutter. If you are running on Nix on MacOS, you may want to add another path as well, `/Applications`, that makes GUI apps available. + +### Getting documentation {#sec-getting-documentation} + +After building that new environment, look through `~/.nix-profile` to make sure everything is there that we wanted. Discerning readers will note that some files are missing. Look inside `~/.nix-profile/share/man/man1/` to verify this. There are no man pages for any of the Nix tools! This is because some packages like Nix have multiple outputs for things like documentation (see section 4). Let's make Nix install those as well. + +```nix +{ + packageOverrides = pkgs: with pkgs; { + myPackages = pkgs.buildEnv { + name = "my-packages"; + paths = [ + aspell + bc + coreutils + ffmpeg + nixUnstable + emscripten + jq + nox + silver-searcher + ]; + pathsToLink = [ "/share/man" "/share/doc" "/bin" ]; + extraOutputsToInstall = [ "man" "doc" ]; + }; + }; +} +``` + +This provides us with some useful documentation for using our packages. However, if we actually want those manpages to be detected by man, we need to set up our environment. This can also be managed within Nix expressions. + +```nix +{ + packageOverrides = pkgs: with pkgs; rec { + myProfile = writeText "my-profile" '' + export PATH=$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/sbin:/bin:/usr/sbin:/usr/bin + export MANPATH=$HOME/.nix-profile/share/man:/nix/var/nix/profiles/default/share/man:/usr/share/man + ''; + myPackages = pkgs.buildEnv { + name = "my-packages"; + paths = [ + (runCommand "profile" {} '' + mkdir -p $out/etc/profile.d + cp ${myProfile} $out/etc/profile.d/my-profile.sh + '') + aspell + bc + coreutils + ffmpeg + man + nixUnstable + emscripten + jq + nox + silver-searcher + ]; + pathsToLink = [ "/share/man" "/share/doc" "/bin" "/etc" ]; + extraOutputsToInstall = [ "man" "doc" ]; + }; + }; +} +``` + +For this to work fully, you must also have this script sourced when you are logged in. Try adding something like this to your `~/.profile` file: + +```shellSession +#!/bin/sh +if [ -d $HOME/.nix-profile/etc/profile.d ]; then + for i in $HOME/.nix-profile/etc/profile.d/*.sh; do + if [ -r $i ]; then + . $i + fi + done +fi +``` + +Now just run `source $HOME/.profile` and you can starting loading man pages from your environment. + +### GNU info setup {#sec-gnu-info-setup} + +Configuring GNU info is a little bit trickier than man pages. To work correctly, info needs a database to be generated. This can be done with some small modifications to our environment scripts. + +```nix +{ + packageOverrides = pkgs: with pkgs; rec { + myProfile = writeText "my-profile" '' + export PATH=$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/sbin:/bin:/usr/sbin:/usr/bin + export MANPATH=$HOME/.nix-profile/share/man:/nix/var/nix/profiles/default/share/man:/usr/share/man + export INFOPATH=$HOME/.nix-profile/share/info:/nix/var/nix/profiles/default/share/info:/usr/share/info + ''; + myPackages = pkgs.buildEnv { + name = "my-packages"; + paths = [ + (runCommand "profile" {} '' + mkdir -p $out/etc/profile.d + cp ${myProfile} $out/etc/profile.d/my-profile.sh + '') + aspell + bc + coreutils + ffmpeg + man + nixUnstable + emscripten + jq + nox + silver-searcher + texinfoInteractive + ]; + pathsToLink = [ "/share/man" "/share/doc" "/share/info" "/bin" "/etc" ]; + extraOutputsToInstall = [ "man" "doc" "info" ]; + postBuild = '' + if [ -x $out/bin/install-info -a -w $out/share/info ]; then + shopt -s nullglob + for i in $out/share/info/*.info $out/share/info/*.info.gz; do + $out/bin/install-info $i $out/share/info/dir + done + fi + ''; + }; + }; +} +``` + +`postBuild` tells Nixpkgs to run a command after building the environment. In this case, `install-info` adds the installed info pages to `dir` which is GNU info's default root node. Note that `texinfoInteractive` is added to the environment to give the `install-info` command. diff --git a/doc/using/configuration.xml b/doc/using/configuration.xml deleted file mode 100644 index 3ef39733458c..000000000000 --- a/doc/using/configuration.xml +++ /dev/null @@ -1,451 +0,0 @@ - - Global configuration - - Nix comes with certain defaults about what packages can and cannot be installed, based on a package's metadata. By default, Nix will prevent installation if any of the following criteria are true: - - - - - The package is thought to be broken, and has had its meta.broken set to true. - - - - - The package isn't intended to run on the given system, as none of its meta.platforms match the given system. - - - - - The package's meta.license is set to a license which is considered to be unfree. - - - - - The package has known security vulnerabilities but has not or can not be updated for some reason, and a list of issues has been entered in to the package's meta.knownVulnerabilities. - - - - - Note that all this is checked during evaluation already, and the check includes any package that is evaluated. In particular, all build-time dependencies are checked. nix-env -qa will (attempt to) hide any packages that would be refused. - - - Each of these criteria can be altered in the nixpkgs configuration. - - - The nixpkgs configuration for a NixOS system is set in the configuration.nix, as in the following example: - -{ - nixpkgs.config = { - allowUnfree = true; - }; -} - - However, this does not allow unfree software for individual users. Their configurations are managed separately. - - - A user's nixpkgs configuration is stored in a user-specific configuration file located at ~/.config/nixpkgs/config.nix. For example: - -{ - allowUnfree = true; -} - - - - Note that we are not able to test or build unfree software on Hydra due to policy. Most unfree licenses prohibit us from either executing or distributing the software. - -
- Installing broken packages - - - There are two ways to try compiling a package which has been marked as broken. - - - - - - For allowing the build of a broken package once, you can use an environment variable for a single invocation of the nix tools: -$ export NIXPKGS_ALLOW_BROKEN=1 - - - - - For permanently allowing broken packages to be built, you may add allowBroken = true; to your user's configuration file, like this: - -{ - allowBroken = true; -} - - - - -
-
- Installing packages on unsupported systems - - - There are also two ways to try compiling a package which has been marked as unsupported for the given system. - - - - - - For allowing the build of an unsupported package once, you can use an environment variable for a single invocation of the nix tools: -$ export NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 - - - - - For permanently allowing unsupported packages to be built, you may add allowUnsupportedSystem = true; to your user's configuration file, like this: - -{ - allowUnsupportedSystem = true; -} - - - - - - - The difference between a package being unsupported on some system and being broken is admittedly a bit fuzzy. If a program ought to work on a certain platform, but doesn't, the platform should be included in meta.platforms, but marked as broken with e.g. meta.broken = !hostPlatform.isWindows. Of course, this begs the question of what "ought" means exactly. That is left to the package maintainer. - -
-
- Installing unfree packages - - - There are several ways to tweak how Nix handles a package which has been marked as unfree. - - - - - - To temporarily allow all unfree packages, you can use an environment variable for a single invocation of the nix tools: -$ export NIXPKGS_ALLOW_UNFREE=1 - - - - - It is possible to permanently allow individual unfree packages, while still blocking unfree packages by default using the allowUnfreePredicate configuration option in the user configuration file. - - - This option is a function which accepts a package as a parameter, and returns a boolean. The following example configuration accepts a package and always returns false: - -{ - allowUnfreePredicate = (pkg: false); -} - - - - For a more useful example, try the following. This configuration only allows unfree packages named roon-server and visual studio code: - -{ - allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ - "roon-server" - "vscode" - ]; -} - - - - - - It is also possible to allow and block licenses that are specifically acceptable or not acceptable, using allowlistedLicenses and blocklistedLicenses, respectively. - - - The following example configuration allowlists the licenses amd and wtfpl: - -{ - allowlistedLicenses = with lib.licenses; [ amd wtfpl ]; -} - - - - The following example configuration blocklists the gpl3Only and agpl3Only licenses: - -{ - blocklistedLicenses = with lib.licenses; [ agpl3Only gpl3Only ]; -} - - - - Note that allowlistedLicenses only applies to unfree licenses unless allowUnfree is enabled. It is not a generic allowlist for all types of licenses. blocklistedLicenses applies to all licenses. - - - - - - A complete list of licenses can be found in the file lib/licenses.nix of the nixpkgs tree. - -
-
- Installing insecure packages - - - There are several ways to tweak how Nix handles a package which has been marked as insecure. - - - - - - To temporarily allow all insecure packages, you can use an environment variable for a single invocation of the nix tools: -$ export NIXPKGS_ALLOW_INSECURE=1 - - - - - It is possible to permanently allow individual insecure packages, while still blocking other insecure packages by default using the permittedInsecurePackages configuration option in the user configuration file. - - - The following example configuration permits the installation of the hypothetically insecure package hello, version 1.2.3: - -{ - permittedInsecurePackages = [ - "hello-1.2.3" - ]; -} - - - - - - It is also possible to create a custom policy around which insecure packages to allow and deny, by overriding the allowInsecurePredicate configuration option. - - - The allowInsecurePredicate option is a function which accepts a package and returns a boolean, much like allowUnfreePredicate. - - - The following configuration example only allows insecure packages with very short names: - -{ - allowInsecurePredicate = pkg: builtins.stringLength (lib.getName pkg) <= 5; -} - - - - Note that permittedInsecurePackages is only checked if allowInsecurePredicate is not specified. - - - -
- -
- Modify packages via <literal>packageOverrides</literal> - - - You can define a function called packageOverrides in your local ~/.config/nixpkgs/config.nix to override Nix packages. It must be a function that takes pkgs as an argument and returns a modified set of packages. - -{ - packageOverrides = pkgs: rec { - foo = pkgs.foo.override { ... }; - }; -} - - -
-
- Declarative Package Management - -
- Build an environment - - - Using packageOverrides, it is possible to manage packages declaratively. This means that we can list all of our desired packages within a declarative Nix expression. For example, to have aspell, bc, ffmpeg, coreutils, gdb, nixUnstable, emscripten, jq, nox, and silver-searcher, we could use the following in ~/.config/nixpkgs/config.nix: - - - -{ - packageOverrides = pkgs: with pkgs; { - myPackages = pkgs.buildEnv { - name = "my-packages"; - paths = [ - aspell - bc - coreutils - gdb - ffmpeg - nixUnstable - emscripten - jq - nox - silver-searcher - ]; - }; - }; -} - - - - To install it into our environment, you can just run nix-env -iA nixpkgs.myPackages. If you want to load the packages to be built from a working copy of nixpkgs you just run nix-env -f. -iA myPackages. To explore what's been installed, just look through ~/.nix-profile/. You can see that a lot of stuff has been installed. Some of this stuff is useful some of it isn't. Let's tell Nixpkgs to only link the stuff that we want: - - - -{ - packageOverrides = pkgs: with pkgs; { - myPackages = pkgs.buildEnv { - name = "my-packages"; - paths = [ - aspell - bc - coreutils - gdb - ffmpeg - nixUnstable - emscripten - jq - nox - silver-searcher - ]; - pathsToLink = [ "/share" "/bin" ]; - }; - }; -} - - - - pathsToLink tells Nixpkgs to only link the paths listed which gets rid of the extra stuff in the profile. /bin and /share are good defaults for a user environment, getting rid of the clutter. If you are running on Nix on MacOS, you may want to add another path as well, /Applications, that makes GUI apps available. - -
- -
- Getting documentation - - - After building that new environment, look through ~/.nix-profile to make sure everything is there that we wanted. Discerning readers will note that some files are missing. Look inside ~/.nix-profile/share/man/man1/ to verify this. There are no man pages for any of the Nix tools! This is because some packages like Nix have multiple outputs for things like documentation (see section 4). Let's make Nix install those as well. - - - -{ - packageOverrides = pkgs: with pkgs; { - myPackages = pkgs.buildEnv { - name = "my-packages"; - paths = [ - aspell - bc - coreutils - ffmpeg - nixUnstable - emscripten - jq - nox - silver-searcher - ]; - pathsToLink = [ "/share/man" "/share/doc" "/bin" ]; - extraOutputsToInstall = [ "man" "doc" ]; - }; - }; -} - - - - This provides us with some useful documentation for using our packages. However, if we actually want those manpages to be detected by man, we need to set up our environment. This can also be managed within Nix expressions. - - - -{ - packageOverrides = pkgs: with pkgs; rec { - myProfile = writeText "my-profile" '' - export PATH=$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/sbin:/bin:/usr/sbin:/usr/bin - export MANPATH=$HOME/.nix-profile/share/man:/nix/var/nix/profiles/default/share/man:/usr/share/man - ''; - myPackages = pkgs.buildEnv { - name = "my-packages"; - paths = [ - (runCommand "profile" {} '' - mkdir -p $out/etc/profile.d - cp ${myProfile} $out/etc/profile.d/my-profile.sh - '') - aspell - bc - coreutils - ffmpeg - man - nixUnstable - emscripten - jq - nox - silver-searcher - ]; - pathsToLink = [ "/share/man" "/share/doc" "/bin" "/etc" ]; - extraOutputsToInstall = [ "man" "doc" ]; - }; - }; -} - - - - For this to work fully, you must also have this script sourced when you are logged in. Try adding something like this to your ~/.profile file: - - - -#!/bin/sh -if [ -d $HOME/.nix-profile/etc/profile.d ]; then - for i in $HOME/.nix-profile/etc/profile.d/*.sh; do - if [ -r $i ]; then - . $i - fi - done -fi - - - - Now just run source $HOME/.profile and you can starting loading man pages from your environment. - -
- -
- GNU info setup - - - Configuring GNU info is a little bit trickier than man pages. To work correctly, info needs a database to be generated. This can be done with some small modifications to our environment scripts. - - - -{ - packageOverrides = pkgs: with pkgs; rec { - myProfile = writeText "my-profile" '' - export PATH=$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/sbin:/bin:/usr/sbin:/usr/bin - export MANPATH=$HOME/.nix-profile/share/man:/nix/var/nix/profiles/default/share/man:/usr/share/man - export INFOPATH=$HOME/.nix-profile/share/info:/nix/var/nix/profiles/default/share/info:/usr/share/info - ''; - myPackages = pkgs.buildEnv { - name = "my-packages"; - paths = [ - (runCommand "profile" {} '' - mkdir -p $out/etc/profile.d - cp ${myProfile} $out/etc/profile.d/my-profile.sh - '') - aspell - bc - coreutils - ffmpeg - man - nixUnstable - emscripten - jq - nox - silver-searcher - texinfoInteractive - ]; - pathsToLink = [ "/share/man" "/share/doc" "/share/info" "/bin" "/etc" ]; - extraOutputsToInstall = [ "man" "doc" "info" ]; - postBuild = '' - if [ -x $out/bin/install-info -a -w $out/share/info ]; then - shopt -s nullglob - for i in $out/share/info/*.info $out/share/info/*.info.gz; do - $out/bin/install-info $i $out/share/info/dir - done - fi - ''; - }; - }; -} - - - - postBuild tells Nixpkgs to run a command after building the environment. In this case, install-info adds the installed info pages to dir which is GNU info's default root node. Note that texinfoInteractive is added to the environment to give the install-info command. - -
-
-
diff --git a/doc/using/overlays.chapter.md b/doc/using/overlays.chapter.md new file mode 100644 index 000000000000..935583a91e24 --- /dev/null +++ b/doc/using/overlays.chapter.md @@ -0,0 +1,149 @@ +# Overlays {#chap-overlays} + +This chapter describes how to extend and change Nixpkgs using overlays. Overlays are used to add layers in the fixed-point used by Nixpkgs to compose the set of all packages. + +Nixpkgs can be configured with a list of overlays, which are applied in order. This means that the order of the overlays can be significant if multiple layers override the same package. + +## Installing overlays {#sec-overlays-install} + +The list of overlays can be set either explicitly in a Nix expression, or through `` or user configuration files. + +### Set overlays in NixOS or Nix expressions {#sec-overlays-argument} + +On a NixOS system the value of the `nixpkgs.overlays` option, if present, is passed to the system Nixpkgs directly as an argument. Note that this does not affect the overlays for non-NixOS operations (e.g. `nix-env`), which are [looked up](#sec-overlays-lookup) independently. + +The list of overlays can be passed explicitly when importing nixpkgs, for example `import { overlays = [ overlay1 overlay2 ]; }`. + +NOTE: DO NOT USE THIS in nixpkgs. Further overlays can be added by calling the `pkgs.extend` or `pkgs.appendOverlays`, although it is often preferable to avoid these functions, because they recompute the Nixpkgs fixpoint, which is somewhat expensive to do. + +### Install overlays via configuration lookup {#sec-overlays-lookup} + +The list of overlays is determined as follows. + +1. First, if an [`overlays` argument](#sec-overlays-argument) to the Nixpkgs function itself is given, then that is used and no path lookup will be performed. + +2. Otherwise, if the Nix path entry `` exists, we look for overlays at that path, as described below. + + See the section on `NIX_PATH` in the Nix manual for more details on how to set a value for `.` + +3. If one of `~/.config/nixpkgs/overlays.nix` and `~/.config/nixpkgs/overlays/` exists, then we look for overlays at that path, as described below. It is an error if both exist. + +If we are looking for overlays at a path, then there are two cases: + +- If the path is a file, then the file is imported as a Nix expression and used as the list of overlays. + +- If the path is a directory, then we take the content of the directory, order it lexicographically, and attempt to interpret each as an overlay by: + + - Importing the file, if it is a `.nix` file. + + - Importing a top-level `default.nix` file, if it is a directory. + +Because overlays that are set in NixOS configuration do not affect non-NixOS operations such as `nix-env`, the `overlays.nix` option provides a convenient way to use the same overlays for a NixOS system configuration and user configuration: the same file can be used as `overlays.nix` and imported as the value of `nixpkgs.overlays`. + +## Defining overlays {#sec-overlays-definition} + +Overlays are Nix functions which accept two arguments, conventionally called `self` and `super`, and return a set of packages. For example, the following is a valid overlay. + +```nix +self: super: + +{ + boost = super.boost.override { + python = self.python3; + }; + rr = super.callPackage ./pkgs/rr { + stdenv = self.stdenv_32bit; + }; +} +``` + +The first argument (`self`) corresponds to the final package set. You should use this set for the dependencies of all packages specified in your overlay. For example, all the dependencies of `rr` in the example above come from `self`, as well as the overridden dependencies used in the `boost` override. + +The second argument (`super`) corresponds to the result of the evaluation of the previous stages of Nixpkgs. It does not contain any of the packages added by the current overlay, nor any of the following overlays. This set should be used either to refer to packages you wish to override, or to access functions defined in Nixpkgs. For example, the original recipe of `boost` in the above example, comes from `super`, as well as the `callPackage` function. + +The value returned by this function should be a set similar to `pkgs/top-level/all-packages.nix`, containing overridden and/or new packages. + +Overlays are similar to other methods for customizing Nixpkgs, in particular the `packageOverrides` attribute described in . 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. + +## Using overlays to configure alternatives {#sec-overlays-alternatives} + +Certain software packages have different implementations of the same interface. Other distributions have functionality to switch between these. For example, Debian provides [DebianAlternatives](https://wiki.debian.org/DebianAlternatives). Nixpkgs has what we call `alternatives`, which are configured through overlays. + +### BLAS/LAPACK {#sec-overlays-alternatives-blas-lapack} + +In Nixpkgs, we have multiple implementations of the BLAS/LAPACK numerical linear algebra interfaces. They are: + +- [OpenBLAS](https://www.openblas.net/) + + The Nixpkgs attribute is `openblas` for ILP64 (integer width = 64 bits) and `openblasCompat` for LP64 (integer width = 32 bits). `openblasCompat` is the default. + +- [LAPACK reference](http://www.netlib.org/lapack/) (also provides BLAS) + + The Nixpkgs attribute is `lapack-reference`. + +- [Intel MKL](https://software.intel.com/en-us/mkl) (only works on the x86_64 architecture, unfree) + + The Nixpkgs attribute is `mkl`. + +- [BLIS](https://github.com/flame/blis) + + BLIS, available through the attribute `blis`, is a framework for linear algebra kernels. In addition, it implements the BLAS interface. + +- [AMD BLIS/LIBFLAME](https://developer.amd.com/amd-aocl/blas-library/) (optimized for modern AMD x86_64 CPUs) + + The AMD fork of the BLIS library, with attribute `amd-blis`, extends BLIS with optimizations for modern AMD CPUs. The changes are usually submitted to the upstream BLIS project after some time. However, AMD BLIS typically provides some performance improvements on AMD Zen CPUs. The complementary AMD LIBFLAME library, with attribute `amd-libflame`, provides a LAPACK implementation. + +Introduced in [PR #83888](https://github.com/NixOS/nixpkgs/pull/83888), we are able to override the `blas` and `lapack` packages to use different implementations, through the `blasProvider` and `lapackProvider` argument. This can be used to select a different provider. BLAS providers will have symlinks in `$out/lib/libblas.so.3` and `$out/lib/libcblas.so.3` to their respective BLAS libraries. Likewise, LAPACK providers will have symlinks in `$out/lib/liblapack.so.3` and `$out/lib/liblapacke.so.3` to their respective LAPACK libraries. For example, Intel MKL is both a BLAS and LAPACK provider. An overlay can be created to use Intel MKL that looks like: + +```nix +self: super: + +{ + blas = super.blas.override { + blasProvider = self.mkl; + }; + + lapack = super.lapack.override { + lapackProvider = self.mkl; + }; +} +``` + +This overlay uses Intel's MKL library for both BLAS and LAPACK interfaces. Note that the same can be accomplished at runtime using `LD_LIBRARY_PATH` of `libblas.so.3` and `liblapack.so.3`. For instance: + +```shellSession +$ LD_LIBRARY_PATH=$(nix-build -A mkl)/lib:$LD_LIBRARY_PATH nix-shell -p octave --run octave +``` + +Intel MKL requires an `openmp` implementation when running with multiple processors. By default, `mkl` will use Intel's `iomp` implementation if no other is specified, but this is a runtime-only dependency and binary compatible with the LLVM implementation. To use that one instead, Intel recommends users set it with `LD_PRELOAD`. Note that `mkl` is only available on `x86_64-linux` and `x86_64-darwin`. Moreover, Hydra is not building and distributing pre-compiled binaries using it. + +For BLAS/LAPACK switching to work correctly, all packages must depend on `blas` or `lapack`. This ensures that only one BLAS/LAPACK library is used at one time. There are two versions of BLAS/LAPACK currently in the wild, `LP64` (integer size = 32 bits) and `ILP64` (integer size = 64 bits). Some software needs special flags or patches to work with `ILP64`. You can check if `ILP64` is used in Nixpkgs with `blas.isILP64` and `lapack.isILP64`. Some software does NOT work with `ILP64`, and derivations need to specify an assertion to prevent this. You can prevent `ILP64` from being used with the following: + +```nix +{ stdenv, blas, lapack, ... }: + +assert (!blas.isILP64) && (!lapack.isILP64); + +stdenv.mkDerivation { + ... +} +``` + +### Switching the MPI implementation {#sec-overlays-alternatives-mpi} + +All programs that are built with [MPI](https://en.wikipedia.org/wiki/Message_Passing_Interface) support use the generic attribute `mpi` as an input. At the moment Nixpkgs natively provides two different MPI implementations: + +- [Open MPI](https://www.open-mpi.org/) (default), attribute name + `openmpi` + +- [MPICH](https://www.mpich.org/), attribute name `mpich` + +To provide MPI enabled applications that use `MPICH`, instead of the default `Open MPI`, simply use the following overlay: + +```nix +self: super: + +{ + mpi = self.mpich; +} +``` diff --git a/doc/using/overlays.xml b/doc/using/overlays.xml deleted file mode 100644 index 8f12aad2adad..000000000000 --- a/doc/using/overlays.xml +++ /dev/null @@ -1,279 +0,0 @@ - - Overlays - - This chapter describes how to extend and change Nixpkgs using overlays. Overlays are used to add layers in the fixed-point used by Nixpkgs to compose the set of all packages. - - - Nixpkgs can be configured with a list of overlays, which are applied in order. This means that the order of the overlays can be significant if multiple layers override the same package. - - -
- Installing overlays - - - The list of overlays can be set either explicitly in a Nix expression, or through <nixpkgs-overlays> or user configuration files. - - -
- Set overlays in NixOS or Nix expressions - - - On a NixOS system the value of the nixpkgs.overlays option, if present, is passed to the system Nixpkgs directly as an argument. Note that this does not affect the overlays for non-NixOS operations (e.g. nix-env), which are looked up independently. - - - - The list of overlays can be passed explicitly when importing nixpkgs, for example import <nixpkgs> { overlays = [ overlay1 overlay2 ]; }. - - - - NOTE: DO NOT USE THIS in nixpkgs. Further overlays can be added by calling the pkgs.extend or pkgs.appendOverlays, although it is often preferable to avoid these functions, because they recompute the Nixpkgs fixpoint, which is somewhat expensive to do. - -
- -
- Install overlays via configuration lookup - - - The list of overlays is determined as follows. - - - - - - - First, if an overlays argument to the Nixpkgs function itself is given, then that is used and no path lookup will be performed. - - - - - Otherwise, if the Nix path entry <nixpkgs-overlays> exists, we look for overlays at that path, as described below. - - - See the section on NIX_PATH in the Nix manual for more details on how to set a value for <nixpkgs-overlays>. - - - - - If one of ~/.config/nixpkgs/overlays.nix and ~/.config/nixpkgs/overlays/ exists, then we look for overlays at that path, as described below. It is an error if both exist. - - - - - - - If we are looking for overlays at a path, then there are two cases: - - - - If the path is a file, then the file is imported as a Nix expression and used as the list of overlays. - - - - - If the path is a directory, then we take the content of the directory, order it lexicographically, and attempt to interpret each as an overlay by: - - - - Importing the file, if it is a .nix file. - - - - - Importing a top-level default.nix file, if it is a directory. - - - - - - - - - - Because overlays that are set in NixOS configuration do not affect non-NixOS operations such as nix-env, the overlays.nix option provides a convenient way to use the same overlays for a NixOS system configuration and user configuration: the same file can be used as overlays.nix and imported as the value of nixpkgs.overlays. - - - -
-
- -
- Defining overlays - - - Overlays are Nix functions which accept two arguments, conventionally called self and super, and return a set of packages. For example, the following is a valid overlay. - - - -self: super: - -{ - boost = super.boost.override { - python = self.python3; - }; - rr = super.callPackage ./pkgs/rr { - stdenv = self.stdenv_32bit; - }; -} - - - - The first argument (self) corresponds to the final package set. You should use this set for the dependencies of all packages specified in your overlay. For example, all the dependencies of rr in the example above come from self, as well as the overridden dependencies used in the boost override. - - - - The second argument (super) corresponds to the result of the evaluation of the previous stages of Nixpkgs. It does not contain any of the packages added by the current overlay, nor any of the following overlays. This set should be used either to refer to packages you wish to override, or to access functions defined in Nixpkgs. For example, the original recipe of boost in the above example, comes from super, as well as the callPackage function. - - - - The value returned by this function should be a set similar to pkgs/top-level/all-packages.nix, containing overridden and/or new packages. - - - - Overlays are similar to other methods for customizing Nixpkgs, in particular the packageOverrides attribute described in . 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. - -
-
- Using overlays to configure alternatives - - - Certain software packages have different implementations of the same interface. Other distributions have functionality to switch between these. For example, Debian provides DebianAlternatives. Nixpkgs has what we call alternatives, which are configured through overlays. - - -
- BLAS/LAPACK - - - In Nixpkgs, we have multiple implementations of the BLAS/LAPACK numerical linear algebra interfaces. They are: - - - - - - OpenBLAS - - - The Nixpkgs attribute is openblas for ILP64 (integer width = 64 bits) and openblasCompat for LP64 (integer width = 32 bits). openblasCompat is the default. - - - - - LAPACK reference (also provides BLAS) - - - The Nixpkgs attribute is lapack-reference. - - - - - Intel MKL (only works on the x86_64 architecture, unfree) - - - The Nixpkgs attribute is mkl. - - - - - BLIS - - - BLIS, available through the attribute blis, is a framework for linear algebra kernels. In addition, it implements the BLAS interface. - - - - - AMD BLIS/LIBFLAME (optimized for modern AMD x86_64 CPUs) - - - The AMD fork of the BLIS library, with attribute amd-blis, extends BLIS with optimizations for modern AMD CPUs. The changes are usually submitted to the upstream BLIS project after some time. However, AMD BLIS typically provides some performance improvements on AMD Zen CPUs. The complementary AMD LIBFLAME library, with attribute amd-libflame, provides a LAPACK implementation. - - - - - - Introduced in PR #83888, we are able to override the blas and lapack packages to use different implementations, through the blasProvider and lapackProvider argument. This can be used to select a different provider. BLAS providers will have symlinks in $out/lib/libblas.so.3 and $out/lib/libcblas.so.3 to their respective BLAS libraries. Likewise, LAPACK providers will have symlinks in $out/lib/liblapack.so.3 and $out/lib/liblapacke.so.3 to their respective LAPACK libraries. For example, Intel MKL is both a BLAS and LAPACK provider. An overlay can be created to use Intel MKL that looks like: - - - -self: super: - -{ - blas = super.blas.override { - blasProvider = self.mkl; - }; - - lapack = super.lapack.override { - lapackProvider = self.mkl; - }; -} - - - - This overlay uses Intel’s MKL library for both BLAS and LAPACK interfaces. Note that the same can be accomplished at runtime using LD_LIBRARY_PATH of libblas.so.3 and liblapack.so.3. For instance: - - - -$ LD_LIBRARY_PATH=$(nix-build -A mkl)/lib:$LD_LIBRARY_PATH nix-shell -p octave --run octave - - - - Intel MKL requires an openmp implementation when running with multiple processors. By default, mkl will use Intel’s iomp implementation if no other is specified, but this is a runtime-only dependency and binary compatible with the LLVM implementation. To use that one instead, Intel recommends users set it with LD_PRELOAD. Note that mkl is only available on x86_64-linux and x86_64-darwin. Moreover, Hydra is not building and distributing pre-compiled binaries using it. - - - - For BLAS/LAPACK switching to work correctly, all packages must depend on blas or lapack. This ensures that only one BLAS/LAPACK library is used at one time. There are two versions of BLAS/LAPACK currently in the wild, LP64 (integer size = 32 bits) and ILP64 (integer size = 64 bits). Some software needs special flags or patches to work with ILP64. You can check if ILP64 is used in Nixpkgs with blas.isILP64 and lapack.isILP64. Some software does NOT work with ILP64, and derivations need to specify an assertion to prevent this. You can prevent ILP64 from being used with the following: - - - -{ stdenv, blas, lapack, ... }: - -assert (!blas.isILP64) && (!lapack.isILP64); - -stdenv.mkDerivation { - ... -} - -
- -
- Switching the MPI implementation - - - All programs that are built with MPI support use the generic attribute mpi as an input. At the moment Nixpkgs natively provides two different MPI implementations: - - - - Open MPI (default), attribute name openmpi - - - - - MPICH, attribute name mpich - - - - - - - To provide MPI enabled applications that use MPICH, instead of the default Open MPI, simply use the following overlay: - - - -self: super: - -{ - mpi = self.mpich; -} - -
-
-
diff --git a/doc/using/overrides.chapter.md b/doc/using/overrides.chapter.md new file mode 100644 index 000000000000..c1ab710e061b --- /dev/null +++ b/doc/using/overrides.chapter.md @@ -0,0 +1,104 @@ +# Overriding {#chap-overrides} + +Sometimes one wants to override parts of `nixpkgs`, e.g. derivation attributes, the results of derivations. + +These functions are used to make changes to packages, returning only single packages. [Overlays](#chap-overlays), on the other hand, can be used to combine the overridden packages across the entire package set of Nixpkgs. + +## <pkg>.override {#sec-pkg-override} + +The function `override` is usually available for all the derivations in the nixpkgs expression (`pkgs`). + +It is used to override the arguments passed to a function. + +Example usages: + +```nix +pkgs.foo.override { arg1 = val1; arg2 = val2; ... } +``` + + + +```nix +import pkgs.path { overlays = [ (self: super: { + foo = super.foo.override { barSupport = true ; }; + })]}; +``` + +```nix +mypkg = pkgs.callPackage ./mypkg.nix { + mydep = pkgs.mydep.override { ... }; + } +``` + +In the first example, `pkgs.foo` is the result of a function call with some default arguments, usually a derivation. Using `pkgs.foo.override` will call the same function with the given new arguments. + +## <pkg>.overrideAttrs {#sec-pkg-overrideAttrs} + +The function `overrideAttrs` allows overriding the attribute set passed to a `stdenv.mkDerivation` call, producing a new derivation based on the original one. This function is available on all derivations produced by the `stdenv.mkDerivation` function, which is most packages in the nixpkgs expression `pkgs`. + +Example usage: + +```nix +helloWithDebug = pkgs.hello.overrideAttrs (oldAttrs: rec { + separateDebugInfo = true; +}); +``` + +In the above example, the `separateDebugInfo` attribute is overridden to be true, thus building debug info for `helloWithDebug`, while all other attributes will be retained from the original `hello` package. + +The argument `oldAttrs` is conventionally used to refer to the attr set originally passed to `stdenv.mkDerivation`. + +::: note +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). +::: + +## <pkg>.overrideDerivation {#sec-pkg-overrideDerivation} + +::: warning +You 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`. +::: + +::: warning +Do 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`. +::: + +The function `overrideDerivation` creates a new derivation based on an existing one by overriding the original's attributes with the attribute set produced by the specified function. This function is available on all derivations defined using the `makeOverridable` function. Most standard derivation-producing functions, such as `stdenv.mkDerivation`, are defined using this function, which means most packages in the nixpkgs expression, `pkgs`, have this function. + +Example usage: + +```nix +mySed = pkgs.gnused.overrideDerivation (oldAttrs: { + name = "sed-4.2.2-pre"; + src = fetchurl { + url = ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2; + sha256 = "11nq06d131y4wmf3drm0yk502d2xc6n5qy82cg88rb9nqd2lj41k"; + }; + patches = []; +}); +``` + +In the above example, the `name`, `src`, and `patches` of the derivation will be overridden, while all other attributes will be retained from the original derivation. + +The argument `oldAttrs` is used to refer to the attribute set of the original derivation. + +::: note +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. +::: + +## lib.makeOverridable {#sec-lib-makeOverridable} + +The function `lib.makeOverridable` is used to make the result of a function easily customizable. This utility only makes sense for functions that accept an argument set and return an attribute set. + +Example usage: + +```nix +f = { a, b }: { result = a+b; }; +c = lib.makeOverridable f { a = 1; b = 2; }; +``` + +The variable `c` is the value of the `f` function applied with some default arguments. Hence the value of `c.result` is `3`, in this example. + +The variable `c` however also has some additional functions, like +[c.override](#sec-pkg-override) which can be used to override the +default arguments. In this example the value of +`(c.override { a = 4; }).result` is 6. diff --git a/doc/using/overrides.xml b/doc/using/overrides.xml deleted file mode 100644 index c9d36ddb2d7b..000000000000 --- a/doc/using/overrides.xml +++ /dev/null @@ -1,145 +0,0 @@ - - Overriding - - Sometimes one wants to override parts of nixpkgs, e.g. derivation attributes, the results of derivations. - - - These functions are used to make changes to packages, returning only single packages. Overlays, on the other hand, can be used to combine the overridden packages across the entire package set of Nixpkgs. - -
- <pkg>.override - - - The function override is usually available for all the derivations in the nixpkgs expression (pkgs). - - - - It is used to override the arguments passed to a function. - - - - Example usages: -pkgs.foo.override { arg1 = val1; arg2 = val2; ... } - - -import pkgs.path { overlays = [ (self: super: { - foo = super.foo.override { barSupport = true ; }; - })]}; - - -mypkg = pkgs.callPackage ./mypkg.nix { - mydep = pkgs.mydep.override { ... }; - } - - - - - In the first example, pkgs.foo is the result of a function call with some default arguments, usually a derivation. Using pkgs.foo.override will call the same function with the given new arguments. - -
-
- <pkg>.overrideAttrs - - - The function overrideAttrs allows overriding the attribute set passed to a stdenv.mkDerivation call, producing a new derivation based on the original one. This function is available on all derivations produced by the stdenv.mkDerivation function, which is most packages in the nixpkgs expression pkgs. - - - - Example usage: - -helloWithDebug = pkgs.hello.overrideAttrs (oldAttrs: rec { - separateDebugInfo = true; -}); - - - - - In the above example, the separateDebugInfo attribute is overridden to be true, thus building debug info for helloWithDebug, while all other attributes will be retained from the original hello package. - - - - The argument oldAttrs is conventionally used to refer to the attr set originally passed to stdenv.mkDerivation. - - - - - 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). - - -
-
- <pkg>.overrideDerivation - - - - You 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. - - - - - - Do 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. - - - - - The function overrideDerivation creates a new derivation based on an existing one by overriding the original's attributes with the attribute set produced by the specified function. This function is available on all derivations defined using the makeOverridable function. Most standard derivation-producing functions, such as stdenv.mkDerivation, are defined using this function, which means most packages in the nixpkgs expression, pkgs, have this function. - - - - Example usage: - -mySed = pkgs.gnused.overrideDerivation (oldAttrs: { - name = "sed-4.2.2-pre"; - src = fetchurl { - url = ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2; - sha256 = "11nq06d131y4wmf3drm0yk502d2xc6n5qy82cg88rb9nqd2lj41k"; - }; - patches = []; -}); - - - - - In the above example, the name, src, and patches of the derivation will be overridden, while all other attributes will be retained from the original derivation. - - - - The argument oldAttrs is used to refer to the attribute set of the original derivation. - - - - - 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. - - -
-
- lib.makeOverridable - - - The function lib.makeOverridable is used to make the result of a function easily customizable. This utility only makes sense for functions that accept an argument set and return an attribute set. - - - - Example usage: - -f = { a, b }: { result = a+b; }; -c = lib.makeOverridable f { a = 1; b = 2; }; - - - - - The variable c is the value of the f function applied with some default arguments. Hence the value of c.result is 3, in this example. - - - - The variable c however also has some additional functions, like c.override which can be used to override the default arguments. In this example the value of (c.override { a = 4; }).result is 6. - -
-
From c30fe2412047927ea761bdca20d42f7fc398745c Mon Sep 17 00:00:00 2001 From: fricklerhandwerk Date: Sat, 24 Apr 2021 11:12:46 +0200 Subject: [PATCH 2/2] docs/using: shellSession -> ShellSession Co-authored-by: Jan Tojnar --- doc/using/configuration.chapter.md | 10 +++++----- doc/using/overlays.chapter.md | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/using/configuration.chapter.md b/doc/using/configuration.chapter.md index e4d401368796..932b24237c02 100644 --- a/doc/using/configuration.chapter.md +++ b/doc/using/configuration.chapter.md @@ -42,7 +42,7 @@ There are two ways to try compiling a package which has been marked as broken. - For allowing the build of a broken package once, you can use an environment variable for a single invocation of the nix tools: - ```shellSession + ```ShellSession $ export NIXPKGS_ALLOW_BROKEN=1 ``` @@ -61,7 +61,7 @@ There are also two ways to try compiling a package which has been marked as unsu - For allowing the build of an unsupported package once, you can use an environment variable for a single invocation of the nix tools: - ```shellSession + ```ShellSession $ export NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 ``` @@ -81,7 +81,7 @@ There are several ways to tweak how Nix handles a package which has been marked - To temporarily allow all unfree packages, you can use an environment variable for a single invocation of the nix tools: - ```shellSession + ```ShellSession $ export NIXPKGS_ALLOW_UNFREE=1 ``` @@ -134,7 +134,7 @@ There are several ways to tweak how Nix handles a package which has been marked - To temporarily allow all insecure packages, you can use an environment variable for a single invocation of the nix tools: - ```shellSession + ```ShellSession $ export NIXPKGS_ALLOW_INSECURE=1 ``` @@ -294,7 +294,7 @@ This provides us with some useful documentation for using our packages. However For this to work fully, you must also have this script sourced when you are logged in. Try adding something like this to your `~/.profile` file: -```shellSession +```ShellSession #!/bin/sh if [ -d $HOME/.nix-profile/etc/profile.d ]; then for i in $HOME/.nix-profile/etc/profile.d/*.sh; do diff --git a/doc/using/overlays.chapter.md b/doc/using/overlays.chapter.md index 935583a91e24..21efe467b847 100644 --- a/doc/using/overlays.chapter.md +++ b/doc/using/overlays.chapter.md @@ -111,7 +111,7 @@ self: super: This overlay uses Intel's MKL library for both BLAS and LAPACK interfaces. Note that the same can be accomplished at runtime using `LD_LIBRARY_PATH` of `libblas.so.3` and `liblapack.so.3`. For instance: -```shellSession +```ShellSession $ LD_LIBRARY_PATH=$(nix-build -A mkl)/lib:$LD_LIBRARY_PATH nix-shell -p octave --run octave ```