From f5dfe78a1eb5ff8dfcc7ab37cfc132c5f31d3cef Mon Sep 17 00:00:00 2001 From: "Nicolas B. Pierron" Date: Sat, 17 Dec 2016 18:05:21 +0000 Subject: Add overlays mechanism to Nixpkgs. This patch add a new argument to Nixpkgs default expression named "overlays". By default, the value of the argument is either taken from the environment variable `NIXPKGS_OVERLAYS`, or from the directory `~/.nixpkgs/overlays/`. If the environment variable does not name a valid directory then this mechanism would fallback on the home directory. If the home directory does not exists it will fallback on an empty list of overlays. The overlays directory should contain the list of extra Nixpkgs stages which would be used to extend the content of Nixpkgs, with additional set of packages. The overlays, i-e directory, files, symbolic links are used in alphabetical order. The simplest overlay which extends Nixpkgs with nothing looks like: ```nix self: super: { } ``` More refined overlays can use `super` as the basis for building new packages, and `self` as a way to query the final result of the fix-point. An example of overlay which extends Nixpkgs with a small set of packages can be found at: https://github.com/nbp/nixpkgs-mozilla/blob/nixpkgs-overlay/moz-overlay.nix To use this file, checkout the repository and add a symbolic link to the `moz-overlay.nix` file in `~/.nixpkgs/overlays` directory. --- doc/functions.xml | 64 +----------------------- doc/languages-frameworks/python.md | 6 +-- doc/manual.xml | 1 + doc/overlays.xml | 99 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 65 deletions(-) create mode 100644 doc/overlays.xml (limited to 'doc') diff --git a/doc/functions.xml b/doc/functions.xml index f6a0a4352f63c..6374c15ddf2b5 100644 --- a/doc/functions.xml +++ b/doc/functions.xml @@ -17,66 +17,6 @@ derivations or even the whole package set. -
- pkgs.overridePackages - - - This function inside the nixpkgs expression (pkgs) - can be used to override the set of packages itself. - - - Warning: this function is expensive and must not be used from within - the nixpkgs repository. - - - Example usage: - - let - pkgs = import <nixpkgs> {}; - newpkgs = pkgs.overridePackages (self: super: { - foo = super.foo.override { ... }; - }); - in ... - - - - The resulting newpkgs will have the new foo - expression, and all other expressions depending on foo will also - use the new foo expression. - - - - The behavior of this function is similar to config.packageOverrides. - - - - The self parameter refers to the final package set with the - applied overrides. Using this parameter may lead to infinite recursion if not - used consciously. - - - - The super parameter refers to the old package set. - It's equivalent to pkgs in the above example. - - - - Note that in previous versions of nixpkgs, this method replaced any changes from config.packageOverrides, - along with that from previous calls if this function was called repeatedly. - Now those previous changes will be preserved so this function can be "chained" meaningfully. - To recover the old behavior, make sure config.packageOverrides is unset, - and call this only once off a "freshly" imported nixpkgs: - - let - pkgs = import <nixpkgs> { config: {}; }; - newpkgs = pkgs.overridePackages ...; - in ... - - -
-
<pkg>.override @@ -91,9 +31,9 @@ Example usages: pkgs.foo.override { arg1 = val1; arg2 = val2; ... } - pkgs.overridePackages (self: super: { + import pkgs.path { overlays = [ (self: super: { foo = super.foo.override { barSupport = true ; }; - }) + })]}; mypkg = pkgs.callPackage ./mypkg.nix { mydep = pkgs.mydep.override { ... }; } diff --git a/doc/languages-frameworks/python.md b/doc/languages-frameworks/python.md index 82aeb112c93ed..48d9e0a0952f9 100644 --- a/doc/languages-frameworks/python.md +++ b/doc/languages-frameworks/python.md @@ -737,18 +737,18 @@ in (pkgs.python35.override {inherit packageOverrides;}).withPackages (ps: [ps.bl ``` The requested package `blaze` depends on `pandas` which itself depends on `scipy`. -If you want the whole of Nixpkgs to use your modifications, then you can use `pkgs.overridePackages` +If you want the whole of Nixpkgs to use your modifications, then you can use `overlays` as explained in this manual. In the following example we build a `inkscape` using a different version of `numpy`. ``` let pkgs = import {}; - newpkgs = pkgs.overridePackages ( pkgsself: pkgssuper: { + newpkgs = import pkgs.path { overlays = [ (pkgsself: pkgssuper: { python27 = let packageOverrides = self: super: { numpy = super.numpy_1_10; }; in pkgssuper.python27.override {inherit packageOverrides;}; - } ); + } ) ]; }; in newpkgs.inkscape ``` diff --git a/doc/manual.xml b/doc/manual.xml index 6ad66d486525d..1c0dac6e4df77 100644 --- a/doc/manual.xml +++ b/doc/manual.xml @@ -18,6 +18,7 @@ + diff --git a/doc/overlays.xml b/doc/overlays.xml new file mode 100644 index 0000000000000..d194c6bfc8920 --- /dev/null +++ b/doc/overlays.xml @@ -0,0 +1,99 @@ + + +Overlays + +This chapter describes how to extend and change Nixpkgs content using +overlays. Overlays are used to add phases in the fix-point used by Nixpkgs +to bind the dependencies of all packages. + + + +
+Installing Overlays + +Overlays are looked for in the following order, the first valid one is +considered, and all the rest are ignored: + + + + + + As argument of the imported attribute set. When importing Nixpkgs, + the overlays attribute argument can be set to a list of + functions, which would be describe in . + + + + + + As a directory pointed by the environment variable named +NIXPKGS_OVERLAYS. This directory can contain symbolic +links to Nix expressions. + + + + + + As the directory located at +~/.nixpkgs/overlays/. This directory can contain +symbolic links to Nix expressions. + + + + + + +For the second and third option, the directory contains either +directories providing a default.nix expression, or files, or symbolic links +to the entry Nix expression of the overlay. These Nix expressions are +following the syntax described in . + +To install an overlay, using the last option. Clone the repository of +the overlay, and add a symbolic link to it in the +~/.nixpkgs/overlays/ directory. + +
+ + + +
+Overlays Layout + +An overlay is a Nix expression, which is a function which accepts 2 +arguments. + + +self: super: + +{ + foo = super.foo.override { ... }; + bar = import ./pkgs/bar { + inherit (self) stdenv fetchurl; + inherit (self) ninja crawl dwarf-fortress; + }; +} + + +The first argument, usualy named self, corresponds +to the final package set. You should use this set to inherit all the +dependencies needed by your package expression. + +The second argument, usualy named 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 is used in to override +existing packages, either by changing their dependencies or their +recipes. + +The value returned by this function should be a set similar to +pkgs/top-level/all-packages.nix, which contains either +extra packages defined by the overlay, or which overwrite Nixpkgs packages +with other custom defaults. This is similar to . + +
+ +
-- cgit 1.4.1