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