stdenv.mkDerivation: public -> finalPackage

main
Robert Hensing 2 years ago
parent f066dddaa5
commit 0e00acafe9
  1. 4
      doc/stdenv/meta.chapter.md
  2. 9
      doc/stdenv/stdenv.chapter.md
  3. 2
      doc/using/overrides.chapter.md
  4. 6
      nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
  5. 2
      nixos/doc/manual/release-notes/rl-2205.section.md
  6. 2
      pkgs/applications/misc/hello/default.nix
  7. 6
      pkgs/stdenv/generic/make-derivation.nix

@ -178,7 +178,7 @@ NixOS tests run in a VM, so they are slower than regular package tests. For more
Alternatively, you can specify other derivations as tests. You can make use of
the optional parameter to inject the correct package without
relying on non-local definitions, even in the presence of `overrideAttrs`.
Here that's `finalAttrs.public`, but you could choose a different name if
Here that's `finalAttrs.finalPackage`, but you could choose a different name if
`finalAttrs` already exists in your scope.
`(mypkg.overrideAttrs f).passthru.tests` will be as expected, as long as the
@ -190,7 +190,7 @@ all places.
{ stdenv, callPackage }:
stdenv.mkDerivation (finalAttrs: {
# ...
passthru.tests.example = callPackage ./example.nix { my-package = finalAttrs.public; }
passthru.tests.example = callPackage ./example.nix { my-package = finalAttrs.finalPackage; };
})
```

@ -336,8 +336,7 @@ The `rec` keyword works at the syntax level and is unaware of overriding.
Instead, the definition references `finalAttrs`, allowing users to change `withFeature`
consistently with `overrideAttrs`.
`finalAttrs` also contains the attribute `public`, which represents the final package,
including the output paths, etc.
`finalAttrs` also contains the attribute `finalPackage`, which includes the output paths, etc.
Let's look at a more elaborate example to understand the differences between
various bindings:
@ -352,11 +351,11 @@ let pkg =
packages = [];
# `passthru.tests` is a commonly defined attribute.
passthru.tests.simple = f finalAttrs.public;
passthru.tests.simple = f finalAttrs.finalPackage;
# An example of an attribute containing a function
passthru.appendPackages = packages':
finalAttrs.public.overrideAttrs (newSelf: super: {
finalAttrs.finalPackage.overrideAttrs (newSelf: super: {
packages = super.packages ++ packages';
});
@ -368,7 +367,7 @@ let pkg =
in pkg
```
Unlike the `pkg` binding in the above example, the `finalAttrs` parameter always references the final attributes. For instance `(pkg.overrideAttrs(x)).finalAttrs.public` is identical to `pkg.overrideAttrs(x)`, whereas `(pkg.overrideAttrs(x)).original` is the same as the original `pkg`.
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`.
See also the section about [`passthru.tests`](#var-meta-tests).

@ -48,7 +48,7 @@ In the above example, the `separateDebugInfo` attribute is overridden to be true
The argument `previousAttrs` is conventionally used to refer to the attr set originally passed to `stdenv.mkDerivation`.
The argument `finalAttrs` refers to the final attributes passed to `mkDerivation`, plus the `public` attribute which is the result of `mkDerivation` — the derivation or package.
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.
If only a one-argument function is written, the argument has the meaning of `previousAttrs`.

@ -57,9 +57,9 @@
</para>
<para>
Additionally, <literal>passthru</literal> can now reference
<literal>finalAttrs.public</literal> containing the final
package, including attributes such as the output paths and
<literal>overrideAttrs</literal>.
<literal>finalAttrs.finalPackage</literal> containing the
final package, including attributes such as the output paths
and <literal>overrideAttrs</literal>.
</para>
<para>
New language integrations can be simplified by overriding a

@ -23,7 +23,7 @@ In addition to numerous new and upgraded packages, this release has the followin
This allows packaging configuration to be overridden in a consistent manner by
providing an alternative to `rec {}` syntax.
Additionally, `passthru` can now reference `finalAttrs.public` containing
Additionally, `passthru` can now reference `finalAttrs.finalPackage` containing
the final package, including attributes such as the output paths and
`overrideAttrs`.

@ -28,7 +28,7 @@ stdenv.mkDerivation (finalAttrs: {
(nixos { environment.noXlibs = true; }).pkgs.hello;
};
passthru.tests.run = callPackage ./test.nix { hello = finalAttrs.public; };
passthru.tests.run = callPackage ./test.nix { hello = finalAttrs.finalPackage; };
meta = with lib; {
description = "A program that produces a familiar, friendly greeting";

@ -24,10 +24,10 @@ let
# separate lines, because Nix would only show the last line of the comment.
# 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`.
args = rattrs (args // { inherit public; });
args = rattrs (args // { inherit finalPackage; });
# ^^^^
public =
finalPackage =
mkDerivationSimple
(f0:
let
@ -51,7 +51,7 @@ let
makeDerivationExtensible mkDerivationSimple
(self: let super = rattrs self; in super // f self super))
args;
in public;
in finalPackage;
# makeDerivationExtensibleConst == makeDerivationExtensible (_: attrs),
# but pre-evaluated for a slight improvement in performance.

Loading…
Cancel
Save