On this page



Docs pulled from | This Revision | about 1 hour ago

Restrict a derivation to a predictable set of attribute names, so that the returned attrset is not strict in the actual derivation, saving a lot of computation when the derivation is non-trivial.

This is useful in situations where a derivation might only be used for its passthru attributes, improving evaluation performance.

The returned attribute set is lazy in derivation. Specifically, this means that the derivation will not be evaluated in at least the situations below.

For illustration and/or testing, we define derivation such that its evaluation is very noticeable.

let derivation = throw "This won't be evaluated.";

In the following expressions, derivation will not be evaluated:

(lazyDerivation { inherit derivation; }).type

attrNames (lazyDerivation { inherit derivation; })

(lazyDerivation { inherit derivation; } // { foo = true; }).foo

(lazyDerivation { inherit derivation; meta.foo = true; }).meta

In these expressions, derivation will be evaluated:

"${lazyDerivation { inherit derivation }}"

(lazyDerivation { inherit derivation }).outPath

(lazyDerivation { inherit derivation }).meta

And the following expressions are not valid, because the refer to implementation details and/or attributes that may not be present on some derivations:

(lazyDerivation { inherit derivation }).buildInputs

(lazyDerivation { inherit derivation }).passthru

(lazyDerivation { inherit derivation }).pythonPath

Noogle also knows