···99100</section>
1010000000000000000000000000000000000000000000000000000102<section xml:id="sec-pkg-overrideDerivation">
103 <title><pkg>.overrideDerivation</title>
000000000104105 <warning>
106 <para>Do not use this function in Nixpkgs as it evaluates a Derivation
···99100</section>
101102+<section xml:id="sec-pkg-overrideAttrs">
103+ <title><pkg>.overrideAttrs</title>
104+105+ <para>
106+ The function <varname>overrideAttrs</varname> allows overriding the
107+ attribute set passed to a <varname>stdenv.mkDerivation</varname> call,
108+ producing a new derivation based on the original one.
109+ This function is available on all derivations produced by the
110+ <varname>stdenv.mkDerivation</varname> function, which is most packages
111+ in the nixpkgs expression <varname>pkgs</varname>.
112+ </para>
113+114+ <para>
115+ Example usage:
116+117+ <programlisting>helloWithDebug = pkgs.hello.overrideAttrs (oldAttrs: rec {
118+ separateDebugInfo = true;
119+});</programlisting>
120+ </para>
121+122+ <para>
123+ In the above example, the <varname>separateDebugInfo</varname> attribute is
124+ overriden to be true, thus building debug info for
125+ <varname>helloWithDebug</varname>, while all other attributes will be
126+ retained from the original <varname>hello</varname> package.
127+ </para>
128+129+ <para>
130+ The argument <varname>oldAttrs</varname> is conventionally used to refer to
131+ the attr set originally passed to <varname>stdenv.mkDerivation</varname>.
132+ </para>
133+134+ <note>
135+ <para>
136+ Note that <varname>separateDebugInfo</varname> is processed only by the
137+ <varname>stdenv.mkDerivation</varname> function, not the generated, raw
138+ Nix derivation. Thus, using <varname>overrideDerivation</varname> will
139+ not work in this case, as it overrides only the attributes of the final
140+ derivation. It is for this reason that <varname>overrideAttrs</varname>
141+ should be preferred in (almost) all cases to
142+ <varname>overrideDerivation</varname>, i.e. to allow using
143+ <varname>sdenv.mkDerivation</varname> to process input arguments, as well
144+ as the fact that it is easier to use (you can use the same attribute
145+ names you see in your Nix code, instead of the ones generated (e.g.
146+ <varname>buildInputs</varname> vs <varname>nativeBuildInputs</varname>,
147+ and involves less typing.
148+ </para>
149+ </note>
150+151+</section>
152+153+154<section xml:id="sec-pkg-overrideDerivation">
155 <title><pkg>.overrideDerivation</title>
156+157+ <warning>
158+ <para>You should prefer <varname>overrideAttrs</varname> in almost all
159+ cases, see its documentation for the reasons why.
160+ <varname>overrideDerivation</varname> is not deprecated and will continue
161+ to work, but is less nice to use and does not have as many abilities as
162+ <varname>overrideAttrs</varname>.
163+ </para>
164+ </warning>
165166 <warning>
167 <para>Do not use this function in Nixpkgs as it evaluates a Derivation
+12-10
lib/customisation.nix
···56 ff = f origArgs;
57 overrideWith = newArgs: origArgs // (if builtins.isFunction newArgs then newArgs origArgs else newArgs);
58 in
59- if builtins.isAttrs ff then (ff //
60- { override = newArgs: makeOverridable f (overrideWith newArgs);
61- overrideDerivation = fdrv:
62- makeOverridable (args: overrideDerivation (f args) fdrv) origArgs;
63- })
64- else if builtins.isFunction ff then
65- { override = newArgs: makeOverridable f (overrideWith newArgs);
66- __functor = self: ff;
67- overrideDerivation = throw "overrideDerivation not yet supported for functors";
68- }
0069 else ff;
7071
···56 ff = f origArgs;
57 overrideWith = newArgs: origArgs // (if builtins.isFunction newArgs then newArgs origArgs else newArgs);
58 in
59+ if builtins.isAttrs ff then (ff // {
60+ override = newArgs: makeOverridable f (overrideWith newArgs);
61+ overrideDerivation = fdrv:
62+ makeOverridable (args: overrideDerivation (f args) fdrv) origArgs;
63+ ${if ff ? overrideAttrs then "overrideAttrs" else null} = fdrv:
64+ makeOverridable (args: (f args).overrideAttrs fdrv) origArgs;
65+ })
66+ else if builtins.isFunction ff then {
67+ override = newArgs: makeOverridable f (overrideWith newArgs);
68+ __functor = self: ff;
69+ overrideDerivation = throw "overrideDerivation not yet supported for functors";
70+ }
71 else ff;
7273
+1
pkgs/stdenv/generic/default.nix
···234 outputs = outputs';
235 } else { })))) (
236 {
0237 # The meta attribute is passed in the resulting attribute set,
238 # but it's not part of the actual derivation, i.e., it's not
239 # passed to the builder and is not a dependency. But since we
···234 outputs = outputs';
235 } else { })))) (
236 {
237+ overrideAttrs = f: mkDerivation (attrs // (f attrs));
238 # The meta attribute is passed in the resulting attribute set,
239 # but it's not part of the actual derivation, i.e., it's not
240 # passed to the builder and is not a dependency. But since we