Skip to content

Commit 7f5f907

Browse files
committed
all-packages.nix: Add pkgs.overridePackages
1 parent df92d1c commit 7f5f907

3 files changed

Lines changed: 77 additions & 2 deletions

File tree

‎doc/functions.xml‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<xi:include href="quick-start.xml" />
1414
<xi:include href="stdenv.xml" />
1515
<xi:include href="packageconfig.xml" />
16+
<xi:include href="functions.xml" />
1617
<xi:include href="meta.xml" />
1718
<xi:include href="language-support.xml" />
1819
<xi:include href="package-notes.xml" />

‎pkgs/top-level/all-packages.nix‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ let
100100
# ... pkgs.foo ...").
101101
pkgs = applyGlobalOverrides (config.packageOverrides or (pkgs: {}));
102102

103+
mkOverrides = pkgsOrig: overrides: overrides //
104+
(lib.optionalAttrs (pkgsOrig.stdenv ? overrides && crossSystem == null) (pkgsOrig.stdenv.overrides pkgsOrig));
103105

104106
# Return the complete set of packages, after applying the overrides
105107
# returned by the `overrider' function (see above). Warning: this
@@ -110,8 +112,7 @@ let
110112
# in the case of cross-building, or otherwise the basic
111113
# overrided packages will not be built with the crossStdenv
112114
# adapter.
113-
overrides = overrider pkgsOrig //
114-
(lib.optionalAttrs (pkgsOrig.stdenv ? overrides && crossSystem == null) (pkgsOrig.stdenv.overrides pkgsOrig));
115+
overrides = mkOverrides pkgsOrig (overrider pkgsOrig);
115116

116117
# The un-overriden packages, passed to `overrider'.
117118
pkgsOrig = pkgsFun pkgs {};
@@ -142,6 +143,22 @@ let
142143

143144
newScope = extra: lib.callPackageWith (defaultScope // extra);
144145

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;
145162

146163
# Override system. This is useful to build i686 packages on x86_64-linux.
147164
forceSystem = system: kernel: (import ./all-packages.nix) {

0 commit comments

Comments
 (0)