@@ -7,208 +7,8 @@
77 The nixpkgs repository has several utility functions to manipulate Nix
88 expressions.
99 </para>
10− <section xml:id="sec-overrides">
11− <title>Overriding</title>
1210
13− <para>
14− Sometimes one wants to override parts of <literal>nixpkgs</literal>, e.g.
15− derivation attributes, the results of derivations or even the whole package
16− set.
17− </para>
18−
19− <section xml:id="sec-pkg-override">
20− <title><pkg>.override</title>
21−
22− <para>
23− The function <varname>override</varname> is usually available for all the
24− derivations in the nixpkgs expression (<varname>pkgs</varname>).
25− </para>
26−
27− <para>
28− It is used to override the arguments passed to a function.
29− </para>
30−
31− <para>
32− Example usages:
33−<programlisting>pkgs.foo.override { arg1 = val1; arg2 = val2; ... }</programlisting>
34−<programlisting>
35−import pkgs.path { overlays = [ (self: super: {
36− foo = super.foo.override { barSupport = true ; };
37− })]};
38−</programlisting>
39−<programlisting>
40−mypkg = pkgs.callPackage ./mypkg.nix {
41− mydep = pkgs.mydep.override { ... };
42− }
43−</programlisting>
44− </para>
45−
46− <para>
47− In the first example, <varname>pkgs.foo</varname> is the result of a
48− function call with some default arguments, usually a derivation. Using
49− <varname>pkgs.foo.override</varname> will call the same function with the
50− given new arguments.
51− </para>
52− </section>
53−
54− <section xml:id="sec-pkg-overrideAttrs">
55− <title><pkg>.overrideAttrs</title>
56−
57− <para>
58− The function <varname>overrideAttrs</varname> allows overriding the
59− attribute set passed to a <varname>stdenv.mkDerivation</varname> call,
60− producing a new derivation based on the original one. This function is
61− available on all derivations produced by the
62− <varname>stdenv.mkDerivation</varname> function, which is most packages in
63− the nixpkgs expression <varname>pkgs</varname>.
64− </para>
65−
66− <para>
67− Example usage:
68−<programlisting>
69−helloWithDebug = pkgs.hello.overrideAttrs (oldAttrs: rec {
70− separateDebugInfo = true;
71−});
72−</programlisting>
73− </para>
74−
75− <para>
76− In the above example, the <varname>separateDebugInfo</varname> attribute is
77− overridden to be true, thus building debug info for
78− <varname>helloWithDebug</varname>, while all other attributes will be
79− retained from the original <varname>hello</varname> package.
80− </para>
81−
82− <para>
83− The argument <varname>oldAttrs</varname> is conventionally used to refer to
84− the attr set originally passed to <varname>stdenv.mkDerivation</varname>.
85− </para>
86−
87− <note>
88− <para>
89− Note that <varname>separateDebugInfo</varname> is processed only by the
90− <varname>stdenv.mkDerivation</varname> function, not the generated, raw
91− Nix derivation. Thus, using <varname>overrideDerivation</varname> will not
92− work in this case, as it overrides only the attributes of the final
93− derivation. It is for this reason that <varname>overrideAttrs</varname>
94− should be preferred in (almost) all cases to
95− <varname>overrideDerivation</varname>, i.e. to allow using
96− <varname>sdenv.mkDerivation</varname> to process input arguments, as well
97− as the fact that it is easier to use (you can use the same attribute names
98− you see in your Nix code, instead of the ones generated (e.g.
99− <varname>buildInputs</varname> vs <varname>nativeBuildInputs</varname>,
100− and involves less typing.
101− </para>
102− </note>
103− </section>
104−
105− <section xml:id="sec-pkg-overrideDerivation">
106− <title><pkg>.overrideDerivation</title>
107−
108− <warning>
109− <para>
110− You should prefer <varname>overrideAttrs</varname> in almost all cases,
111− see its documentation for the reasons why.
112− <varname>overrideDerivation</varname> is not deprecated and will continue
113− to work, but is less nice to use and does not have as many abilities as
114− <varname>overrideAttrs</varname>.
115− </para>
116− </warning>
117−
118− <warning>
119− <para>
120− Do not use this function in Nixpkgs as it evaluates a Derivation before
121− modifying it, which breaks package abstraction and removes error-checking
122− of function arguments. In addition, this evaluation-per-function
123− application incurs a performance penalty, which can become a problem if
124− many overrides are used. It is only intended for ad-hoc customisation,
125− such as in <filename>~/.config/nixpkgs/config.nix</filename>.
126− </para>
127− </warning>
128−
129− <para>
130− The function <varname>overrideDerivation</varname> creates a new derivation
131− based on an existing one by overriding the original's attributes with the
132− attribute set produced by the specified function. This function is
133− available on all derivations defined using the
134− <varname>makeOverridable</varname> function. Most standard
135− derivation-producing functions, such as
136− <varname>stdenv.mkDerivation</varname>, are defined using this function,
137− which means most packages in the nixpkgs expression,
138− <varname>pkgs</varname>, have this function.
139− </para>
140−
141− <para>
142− Example usage:
143−<programlisting>
144−mySed = pkgs.gnused.overrideDerivation (oldAttrs: {
145− name = "sed-4.2.2-pre";
146− src = fetchurl {
147− url = ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2;
148− sha256 = "11nq06d131y4wmf3drm0yk502d2xc6n5qy82cg88rb9nqd2lj41k";
149− };
150− patches = [];
151−});
152−</programlisting>
153− </para>
154−
155− <para>
156− In the above example, the <varname>name</varname>, <varname>src</varname>,
157− and <varname>patches</varname> of the derivation will be overridden, while
158− all other attributes will be retained from the original derivation.
159− </para>
160−
161− <para>
162− The argument <varname>oldAttrs</varname> is used to refer to the attribute
163− set of the original derivation.
164− </para>
165−
166− <note>
167− <para>
168− A package's attributes are evaluated *before* being modified by the
169− <varname>overrideDerivation</varname> function. For example, the
170− <varname>name</varname> attribute reference in <varname>url =
171− "mirror://gnu/hello/${name}.tar.gz";</varname> is filled-in *before* the
172− <varname>overrideDerivation</varname> function modifies the attribute set.
173− This means that overriding the <varname>name</varname> attribute, in this
174− example, *will not* change the value of the <varname>url</varname>
175− attribute. Instead, we need to override both the <varname>name</varname>
176− *and* <varname>url</varname> attributes.
177− </para>
178− </note>
179− </section>
180−
181− <section xml:id="sec-lib-makeOverridable">
182− <title>lib.makeOverridable</title>
183−
184− <para>
185− The function <varname>lib.makeOverridable</varname> is used to make the
186− result of a function easily customizable. This utility only makes sense for
187− functions that accept an argument set and return an attribute set.
188− </para>
189−
190− <para>
191− Example usage:
192−<programlisting>
193−f = { a, b }: { result = a+b; };
194−c = lib.makeOverridable f { a = 1; b = 2; };
195−</programlisting>
196− </para>
197−
198− <para>
199− The variable <varname>c</varname> is the value of the <varname>f</varname>
200− function applied with some default arguments. Hence the value of
201− <varname>c.result</varname> is <literal>3</literal>, in this example.
202− </para>
203−
204− <para>
205− The variable <varname>c</varname> however also has some additional
206− functions, like <link linkend="sec-pkg-override">c.override</link> which
207− can be used to override the default arguments. In this example the value of
208− <varname>(c.override { a = 4; }).result</varname> is 6.
209− </para>
210− </section>
211− </section>
11+ <xi:include href="functions/overrides.xml" />
21212 <section xml:id="sec-generators">
21313 <title>Generators</title>
21414