···175175176176NixOS tests run in a VM, so they are slower than regular package tests. For more information see [NixOS module tests](https://nixos.org/manual/nixos/stable/#sec-nixos-tests).
177177178178+Alternatively, you can specify other derivations as tests. You can make use of
179179+the optional parameter to inject the correct package without
180180+relying on non-local definitions, even in the presence of `overrideAttrs`.
181181+Here that's `finalAttrs.finalPackage`, but you could choose a different name if
182182+`finalAttrs` already exists in your scope.
183183+184184+`(mypkg.overrideAttrs f).passthru.tests` will be as expected, as long as the
185185+definition of `tests` does not rely on the original `mypkg` or overrides it in
186186+all places.
187187+188188+```nix
189189+# my-package/default.nix
190190+{ stdenv, callPackage }:
191191+stdenv.mkDerivation (finalAttrs: {
192192+ # ...
193193+ passthru.tests.example = callPackage ./example.nix { my-package = finalAttrs.finalPackage; };
194194+})
195195+```
196196+197197+```nix
198198+# my-package/example.nix
199199+{ runCommand, lib, my-package, ... }:
200200+runCommand "my-package-test" {
201201+ nativeBuildInputs = [ my-package ];
202202+ src = lib.sources.sourcesByRegex ./. [ ".*.in" ".*.expected" ];
203203+} ''
204204+ my-package --help
205205+ my-package <example.in >example.actual
206206+ diff -U3 --color=auto example.expected example.actual
207207+ mkdir $out
208208+''
209209+```
210210+211211+178212### `timeout` {#var-meta-timeout}
179213180214A timeout (in seconds) for building the derivation. If the derivation takes longer than this time to build, it can fail due to breaking the timeout. However, all computers do not have the same computing power, hence some builders may decide to apply a multiplicative factor to this value. When filling this value in, try to keep it approximately consistent with other values already present in `nixpkgs`.
+54
doc/stdenv/stdenv.chapter.md
···317317318318For information about how to run the updates, execute `nix-shell maintainers/scripts/update.nix`.
319319320320+### Recursive attributes in `mkDerivation`
321321+322322+If you pass a function to `mkDerivation`, it will receive as its argument the final arguments, including the overrides when reinvoked via `overrideAttrs`. For example:
323323+324324+```nix
325325+mkDerivation (finalAttrs: {
326326+ pname = "hello";
327327+ withFeature = true;
328328+ configureFlags =
329329+ lib.optionals finalAttrs.withFeature ["--with-feature"];
330330+})
331331+```
332332+333333+Note that this does not use the `rec` keyword to reuse `withFeature` in `configureFlags`.
334334+The `rec` keyword works at the syntax level and is unaware of overriding.
335335+336336+Instead, the definition references `finalAttrs`, allowing users to change `withFeature`
337337+consistently with `overrideAttrs`.
338338+339339+`finalAttrs` also contains the attribute `finalPackage`, which includes the output paths, etc.
340340+341341+Let's look at a more elaborate example to understand the differences between
342342+various bindings:
343343+344344+```nix
345345+# `pkg` is the _original_ definition (for illustration purposes)
346346+let pkg =
347347+ mkDerivation (finalAttrs: {
348348+ # ...
349349+350350+ # An example attribute
351351+ packages = [];
352352+353353+ # `passthru.tests` is a commonly defined attribute.
354354+ passthru.tests.simple = f finalAttrs.finalPackage;
355355+356356+ # An example of an attribute containing a function
357357+ passthru.appendPackages = packages':
358358+ finalAttrs.finalPackage.overrideAttrs (newSelf: super: {
359359+ packages = super.packages ++ packages';
360360+ });
361361+362362+ # For illustration purposes; referenced as
363363+ # `(pkg.overrideAttrs(x)).finalAttrs` etc in the text below.
364364+ passthru.finalAttrs = finalAttrs;
365365+ passthru.original = pkg;
366366+ });
367367+in pkg
368368+```
369369+370370+Unlike the `pkg` binding in the above example, the `finalAttrs` parameter always references the final attributes. For instance `(pkg.overrideAttrs(x)).finalAttrs.finalPackage` is identical to `pkg.overrideAttrs(x)`, whereas `(pkg.overrideAttrs(x)).original` is the same as the original `pkg`.
371371+372372+See also the section about [`passthru.tests`](#var-meta-tests).
373373+320374## Phases {#sec-stdenv-phases}
321375322376`stdenv.mkDerivation` sets the Nix [derivation](https://nixos.org/manual/nix/stable/expressions/derivations.html#derivations)'s builder to a script that loads the stdenv `setup.sh` bash library and calls `genericBuild`. Most packaging functions rely on this default builder.
+6-2
doc/using/overrides.chapter.md
···3939Example usage:
40404141```nix
4242-helloWithDebug = pkgs.hello.overrideAttrs (oldAttrs: rec {
4242+helloWithDebug = pkgs.hello.overrideAttrs (finalAttrs: previousAttrs: {
4343 separateDebugInfo = true;
4444});
4545```
46464747In the above example, the `separateDebugInfo` attribute is overridden to be true, thus building debug info for `helloWithDebug`, while all other attributes will be retained from the original `hello` package.
48484949-The argument `oldAttrs` is conventionally used to refer to the attr set originally passed to `stdenv.mkDerivation`.
4949+The argument `previousAttrs` is conventionally used to refer to the attr set originally passed to `stdenv.mkDerivation`.
5050+5151+The argument `finalAttrs` refers to the final attributes passed to `mkDerivation`, plus the `finalPackage` attribute which is equal to the result of `mkDerivation` or subsequent `overrideAttrs` calls.
5252+5353+If only a one-argument function is written, the argument has the meaning of `previousAttrs`.
50545155::: {.note}
5256Note that `separateDebugInfo` is processed only by the `stdenv.mkDerivation` function, not the generated, raw Nix derivation. Thus, using `overrideDerivation` will not work in this case, as it overrides only the attributes of the final derivation. It is for this reason that `overrideAttrs` should be preferred in (almost) all cases to `overrideDerivation`, i.e. to allow using `stdenv.mkDerivation` to process input arguments, as well as the fact that it is easier to use (you can use the same attribute names you see in your Nix code, instead of the ones generated (e.g. `buildInputs` vs `nativeBuildInputs`), and it involves less typing).
···4545 </listitem>
4646 <listitem>
4747 <para>
4848+ <literal>stdenv.mkDerivation</literal> now supports a
4949+ self-referencing <literal>finalAttrs:</literal> parameter
5050+ containing the final <literal>mkDerivation</literal> arguments
5151+ including overrides. <literal>drv.overrideAttrs</literal> now
5252+ supports two parameters
5353+ <literal>finalAttrs: previousAttrs:</literal>. This allows
5454+ packaging configuration to be overridden in a consistent
5555+ manner by providing an alternative to
5656+ <literal>rec {}</literal> syntax.
5757+ </para>
5858+ <para>
5959+ Additionally, <literal>passthru</literal> can now reference
6060+ <literal>finalAttrs.finalPackage</literal> containing the
6161+ final package, including attributes such as the output paths
6262+ and <literal>overrideAttrs</literal>.
6363+ </para>
6464+ <para>
6565+ New language integrations can be simplified by overriding a
6666+ <quote>prototype</quote> package containing the
6767+ language-specific logic. This removes the need for a extra
6868+ layer of overriding for the <quote>generic builder</quote>
6969+ arguments, thus removing a usability problem and source of
7070+ error.
7171+ </para>
7272+ </listitem>
7373+ <listitem>
7474+ <para>
4875 PHP 8.1 is now available
4976 </para>
5077 </listitem>
···849876 <literal>22.05</literal>. Files will need to be manually moved
850877 to the new location if the <literal>stateVersion</literal> is
851878 updated.
879879+ </para>
880880+ <para>
881881+ As of Synapse 1.58.0, the old groups/communities feature has
882882+ been disabled by default. It will be completely removed with
883883+ Synapse 1.61.0.
852884 </para>
853885 </listitem>
854886 <listitem>
+17
nixos/doc/manual/release-notes/rl-2205.section.md
···17171818- GNOME has been upgraded to 42. Please take a look at their [Release Notes](https://release.gnome.org/42/) for details. Notably, it replaces gedit with GNOME Text Editor, GNOME Terminal with GNOME Console (formerly King’s Cross), and GNOME Screenshot with a tool built into the Shell.
19192020+- `stdenv.mkDerivation` now supports a self-referencing `finalAttrs:` parameter
2121+ containing the final `mkDerivation` arguments including overrides.
2222+ `drv.overrideAttrs` now supports two parameters `finalAttrs: previousAttrs:`.
2323+ This allows packaging configuration to be overridden in a consistent manner by
2424+ providing an alternative to `rec {}` syntax.
2525+2626+ Additionally, `passthru` can now reference `finalAttrs.finalPackage` containing
2727+ the final package, including attributes such as the output paths and
2828+ `overrideAttrs`.
2929+3030+ New language integrations can be simplified by overriding a "prototype"
3131+ package containing the language-specific logic. This removes the need for a
3232+ extra layer of overriding for the "generic builder" arguments, thus removing a
3333+ usability problem and source of error.
3434+2035- PHP 8.1 is now available
21362237- Mattermost has been updated to extended support release 6.3, as the previously packaged extended support release 5.37 is [reaching its end of life](https://docs.mattermost.com/upgrade/extended-support-release.html).
···346361 Additionally a few option defaults have been synced up with upstream default values, for example the `max_upload_size` grew from `10M` to `50M`. For the same reason, the default
347362 `media_store_path` was changed from `${dataDir}/media` to `${dataDir}/media_store` if `system.stateVersion` is at least `22.05`. Files will need to be manually moved to the new
348363 location if the `stateVersion` is updated.
364364+365365+ As of Synapse 1.58.0, the old groups/communities feature has been disabled by default. It will be completely removed with Synapse 1.61.0.
349366350367- The Keycloak package (`pkgs.keycloak`) has been switched from the
351368 Wildfly version, which will soon be deprecated, to the Quarkus based
+3
nixos/tests/matrix-appservice-irc.nix
···20202121 enable_registration = true;
22222323+ # don't use this in production, always use some form of verification
2424+ enable_registration_without_verification = true;
2525+2326 listeners = [ {
2427 # The default but tls=false
2528 bind_addresses = [
···194194 maintainers = with maintainers; [ goibhniu gilligan cko marsam ];
195195 platforms = platforms.linux ++ platforms.darwin;
196196 mainProgram = "node";
197197- knownVulnerabilities = optional (versionOlder version "12") "This NodeJS release has reached its end of life. See https://nodejs.org/en/about/releases/.";
197197+ knownVulnerabilities = optional (versionOlder version "14") "This NodeJS release has reached its end of life. See https://nodejs.org/en/about/releases/.";
198198 };
199199200200 passthru.python = python; # to ensure nodeEnv uses the same version
···11-# This file has been generated by node2nix 1.9.0. Do not edit!
11+# This file has been generated by node2nix 1.11.1. Do not edit!
2233{pkgs ? import <nixpkgs> {
44 inherit system;
···99 # to build it. This is a bit confusing for cross compilation.
1010 inherit (stdenv) hostPlatform;
1111 };
1212+1313+ makeOverlayable = mkDerivationSimple:
1414+ fnOrAttrs:
1515+ if builtins.isFunction fnOrAttrs
1616+ then makeDerivationExtensible mkDerivationSimple fnOrAttrs
1717+ else makeDerivationExtensibleConst mkDerivationSimple fnOrAttrs;
1818+1919+ # Based off lib.makeExtensible, with modifications:
2020+ makeDerivationExtensible = mkDerivationSimple: rattrs:
2121+ let
2222+ # NOTE: The following is a hint that will be printed by the Nix cli when
2323+ # encountering an infinite recursion. It must not be formatted into
2424+ # separate lines, because Nix would only show the last line of the comment.
2525+2626+ # An infinite recursion here can be caused by having the attribute names of expression `e` in `.overrideAttrs(finalAttrs: previousAttrs: e)` depend on `finalAttrs`. Only the attribute values of `e` can depend on `finalAttrs`.
2727+ args = rattrs (args // { inherit finalPackage; });
2828+ # ^^^^
2929+3030+ finalPackage =
3131+ mkDerivationSimple
3232+ (f0:
3333+ let
3434+ f = self: super:
3535+ # Convert f0 to an overlay. Legacy is:
3636+ # overrideAttrs (super: {})
3737+ # We want to introduce self. We follow the convention of overlays:
3838+ # overrideAttrs (self: super: {})
3939+ # Which means the first parameter can be either self or super.
4040+ # This is surprising, but far better than the confusion that would
4141+ # arise from flipping an overlay's parameters in some cases.
4242+ let x = f0 super;
4343+ in
4444+ if builtins.isFunction x
4545+ then
4646+ # Can't reuse `x`, because `self` comes first.
4747+ # Looks inefficient, but `f0 super` was a cheap thunk.
4848+ f0 self super
4949+ else x;
5050+ in
5151+ makeDerivationExtensible mkDerivationSimple
5252+ (self: let super = rattrs self; in super // f self super))
5353+ args;
5454+ in finalPackage;
5555+5656+ # makeDerivationExtensibleConst == makeDerivationExtensible (_: attrs),
5757+ # but pre-evaluated for a slight improvement in performance.
5858+ makeDerivationExtensibleConst = mkDerivationSimple: attrs:
5959+ mkDerivationSimple
6060+ (f0:
6161+ let
6262+ f = self: super:
6363+ let x = f0 super;
6464+ in
6565+ if builtins.isFunction x
6666+ then
6767+ f0 self super
6868+ else x;
6969+ in
7070+ makeDerivationExtensible mkDerivationSimple (self: attrs // f self attrs))
7171+ attrs;
7272+1273in
7474+7575+makeOverlayable (overrideAttrs:
7676+13771478# `mkDerivation` wraps the builtin `derivation` function to
1579# produce derivations that use this stdenv and its shell.
···7013471135, # TODO(@Ericson2314): Make always true and remove
72136 strictDeps ? if config.strictDepsByDefault then true else stdenv.hostPlatform != stdenv.buildPlatform
137137+73138, meta ? {}
74139, passthru ? {}
75140, pos ? # position used in error messages and for meta.position
···381446lib.extendDerivation
382447 validity.handled
383448 ({
384384- overrideAttrs = f: stdenv.mkDerivation (attrs // (f attrs));
385385-386449 # A derivation that always builds successfully and whose runtime
387450 # dependencies are the original derivations build time dependencies
388451 # This allows easy building and distributing of all derivations
···408471 args = [ "-c" "export > $out" ];
409472 });
410473411411- inherit meta passthru;
474474+ inherit meta passthru overrideAttrs;
412475 } //
413476 # Pass through extra attributes that are not inputs, but
414477 # should be made available to Nix expressions using the
415478 # derivation (e.g., in assertions).
416479 passthru)
417480 (derivation derivationArg)
481481+482482+)