git.iko.soy/typeable/nixpkgs
on master help sign in
all-packages.nix: Add pkgs.overridePackages
7f5f907Luca Bruno
doc/functions.xmlnew file+57
@@ -0,0 +1,57 @@
1+<chapter xmlns="http://docbook.org/ns/docbook"
2+ xmlns:xlink="http://www.w3.org/1999/xlink"
3+ xml:id="chap-functions">
4+
5+<title>Functions reference</title>
6+
7+<para>
8+ The nixpkgs repository has several utility functions to manipulate Nix expressions.
9+</para>
10+
11+<section xml:id="sec-pkgs-overridePackages">
12+ <title>pkgs.overridePackages</title>
13+
14+ <para>
15+ This function inside the nixpkgs expression (<varname>pkgs</varname>)
16+ can be used to override the set of packages itself.
17+ </para>
18+ <para>
19+ Warning: this function is expensive and must not be used from within
20+ the nixpkgs repository.
21+ </para>
22+ <para>
23+ Example usage:
24+
25+ <programlisting>let
26+ pkgs = import &lt;nixpkgs&gt; {};
27+ newpkgs = pkgs.overridePackages (self: super: {
28+ foo = super.foo.override { ... };
29+ };
30+in ...</programlisting>
31+ </para>
32+
33+ <para>
34+ The resulting <varname>newpkgs</varname> will have the new <varname>foo</varname>
35+ expression, and all other expressions depending on <varname>foo</varname> will also
36+ use the new <varname>foo</varname> expression.
37+ </para>
38+
39+ <para>
40+ The behavior of this function is similar to <link
41+ linkend="sec-modify-via-packageOverrides">config.packageOverrides</link>.
42+ </para>
43+
44+ <para>
45+ The <varname>self</varname> parameter refers to the final package set with the
46+ applied overrides. Using this parameter may lead to infinite recursion if not
47+ used consciously.
48+ </para>
49+
50+ <para>
51+ The <varname>super</varname> parameter refers to the old package set.
52+ It's equivalent to <varname>pkgs</varname> in the above example.
53+ </para>
54+
55+</section>
56+
57+</chapter>
doc/manual.xml+1
@@ -13,6 +13,7 @@
13 <xi:include href="quick-start.xml" />
13 <xi:include href="quick-start.xml" />
14 <xi:include href="stdenv.xml" />
14 <xi:include href="stdenv.xml" />
15 <xi:include href="packageconfig.xml" />
15 <xi:include href="packageconfig.xml" />
16+ <xi:include href="functions.xml" />
16 <xi:include href="meta.xml" />
17 <xi:include href="meta.xml" />
17 <xi:include href="language-support.xml" />
18 <xi:include href="language-support.xml" />
18 <xi:include href="package-notes.xml" />
19 <xi:include href="package-notes.xml" />
pkgs/top-level/all-packages.nix+19−2
@@ -100,6 +100,8 @@ let
100 # ... pkgs.foo ...").
100 # ... pkgs.foo ...").
101 pkgs = applyGlobalOverrides (config.packageOverrides or (pkgs: {}));
101 pkgs = applyGlobalOverrides (config.packageOverrides or (pkgs: {}));
102
102
103+ mkOverrides = pkgsOrig: overrides: overrides //
104+ (lib.optionalAttrs (pkgsOrig.stdenv ? overrides && crossSystem == null) (pkgsOrig.stdenv.overrides pkgsOrig));
103
105
104 # Return the complete set of packages, after applying the overrides
106 # Return the complete set of packages, after applying the overrides
105 # returned by the `overrider' function (see above). Warning: this
107 # returned by the `overrider' function (see above). Warning: this
@@ -110,8 +112,7 @@ let
110 # in the case of cross-building, or otherwise the basic
112 # in the case of cross-building, or otherwise the basic
111 # overrided packages will not be built with the crossStdenv
113 # overrided packages will not be built with the crossStdenv
112 # adapter.
114 # adapter.
113− overrides = overrider pkgsOrig //
115+ overrides = mkOverrides pkgsOrig (overrider pkgsOrig);
114− (lib.optionalAttrs (pkgsOrig.stdenv ? overrides && crossSystem == null) (pkgsOrig.stdenv.overrides pkgsOrig));
115
116
116 # The un-overriden packages, passed to `overrider'.
117 # The un-overriden packages, passed to `overrider'.
117 pkgsOrig = pkgsFun pkgs {};
118 pkgsOrig = pkgsFun pkgs {};
@@ -142,6 +143,22 @@ let
142
143
143 newScope = extra: lib.callPackageWith (defaultScope // extra);
144 newScope = extra: lib.callPackageWith (defaultScope // extra);
144
145
146+ # Easily override this package set.
147+ # Warning: this function is very expensive and must not be used
148+ # from within the nixpkgs repository.
149+ #
150+ # Example:
151+ # pkgs.overridePackages (self: super: {
152+ # foo = super.foo.override { ... };
153+ # }
154+ #
155+ # The result is `pkgs' where all the derivations depending on `foo'
156+ # will use the new version.
157+ overridePackages = f:
158+ let
159+ newpkgs = pkgsFun newpkgs overrides;
160+ overrides = mkOverrides pkgs (f newpkgs pkgs);
161+ in newpkgs;
145
162
146 # Override system. This is useful to build i686 packages on x86_64-linux.
163 # Override system. This is useful to build i686 packages on x86_64-linux.
147 forceSystem = system: kernel: (import ./all-packages.nix) {
164 forceSystem = system: kernel: (import ./all-packages.nix) {