···9999100100</section>
101101102102+<section xml:id="sec-pkg-overrideAttrs">
103103+ <title><pkg>.overrideAttrs</title>
104104+105105+ <para>
106106+ The function <varname>overrideAttrs</varname> allows overriding the
107107+ attribute set passed to a <varname>stdenv.mkDerivation</varname> call,
108108+ producing a new derivation based on the original one.
109109+ This function is available on all derivations produced by the
110110+ <varname>stdenv.mkDerivation</varname> function, which is most packages
111111+ in the nixpkgs expression <varname>pkgs</varname>.
112112+ </para>
113113+114114+ <para>
115115+ Example usage:
116116+117117+ <programlisting>helloWithDebug = pkgs.hello.overrideAttrs (oldAttrs: rec {
118118+ separateDebugInfo = true;
119119+});</programlisting>
120120+ </para>
121121+122122+ <para>
123123+ In the above example, the <varname>separateDebugInfo</varname> attribute is
124124+ overriden to be true, thus building debug info for
125125+ <varname>helloWithDebug</varname>, while all other attributes will be
126126+ retained from the original <varname>hello</varname> package.
127127+ </para>
128128+129129+ <para>
130130+ The argument <varname>oldAttrs</varname> is conventionally used to refer to
131131+ the attr set originally passed to <varname>stdenv.mkDerivation</varname>.
132132+ </para>
133133+134134+ <note>
135135+ <para>
136136+ Note that <varname>separateDebugInfo</varname> is processed only by the
137137+ <varname>stdenv.mkDerivation</varname> function, not the generated, raw
138138+ Nix derivation. Thus, using <varname>overrideDerivation</varname> will
139139+ not work in this case, as it overrides only the attributes of the final
140140+ derivation. It is for this reason that <varname>overrideAttrs</varname>
141141+ should be preferred in (almost) all cases to
142142+ <varname>overrideDerivation</varname>, i.e. to allow using
143143+ <varname>sdenv.mkDerivation</varname> to process input arguments, as well
144144+ as the fact that it is easier to use (you can use the same attribute
145145+ names you see in your Nix code, instead of the ones generated (e.g.
146146+ <varname>buildInputs</varname> vs <varname>nativeBuildInputs</varname>,
147147+ and involves less typing.
148148+ </para>
149149+ </note>
150150+151151+</section>
152152+153153+102154<section xml:id="sec-pkg-overrideDerivation">
103155 <title><pkg>.overrideDerivation</title>
156156+157157+ <warning>
158158+ <para>You should prefer <varname>overrideAttrs</varname> in almost all
159159+ cases, see its documentation for the reasons why.
160160+ <varname>overrideDerivation</varname> is not deprecated and will continue
161161+ to work, but is less nice to use and does not have as many abilities as
162162+ <varname>overrideAttrs</varname>.
163163+ </para>
164164+ </warning>
104165105166 <warning>
106167 <para>Do not use this function in Nixpkgs as it evaluates a Derivation
+12-10
lib/customisation.nix
···5656 ff = f origArgs;
5757 overrideWith = newArgs: origArgs // (if builtins.isFunction newArgs then newArgs origArgs else newArgs);
5858 in
5959- if builtins.isAttrs ff then (ff //
6060- { override = newArgs: makeOverridable f (overrideWith newArgs);
6161- overrideDerivation = fdrv:
6262- makeOverridable (args: overrideDerivation (f args) fdrv) origArgs;
6363- })
6464- else if builtins.isFunction ff then
6565- { override = newArgs: makeOverridable f (overrideWith newArgs);
6666- __functor = self: ff;
6767- overrideDerivation = throw "overrideDerivation not yet supported for functors";
6868- }
5959+ if builtins.isAttrs ff then (ff // {
6060+ override = newArgs: makeOverridable f (overrideWith newArgs);
6161+ overrideDerivation = fdrv:
6262+ makeOverridable (args: overrideDerivation (f args) fdrv) origArgs;
6363+ ${if ff ? overrideAttrs then "overrideAttrs" else null} = fdrv:
6464+ makeOverridable (args: (f args).overrideAttrs fdrv) origArgs;
6565+ })
6666+ else if builtins.isFunction ff then {
6767+ override = newArgs: makeOverridable f (overrideWith newArgs);
6868+ __functor = self: ff;
6969+ overrideDerivation = throw "overrideDerivation not yet supported for functors";
7070+ }
6971 else ff;
70727173
+1
pkgs/stdenv/generic/default.nix
···234234 outputs = outputs';
235235 } else { })))) (
236236 {
237237+ overrideAttrs = f: mkDerivation (attrs // (f attrs));
237238 # The meta attribute is passed in the resulting attribute set,
238239 # but it's not part of the actual derivation, i.e., it's not
239240 # passed to the builder and is not a dependency. But since we