Import From Derivation: Difference between revisions

imported>Roberth
m Use (f drv) to clarify that it's only such usages that cause IFD
imported>Asymmetric
m add link to blog post, fix section formatting
Line 67: Line 67:
version of nixpkgs, and then importing the source.
version of nixpkgs, and then importing the source.


<h2>When to use IFD</h2>
== When to use IFD ==


IFD is a powerful feature, but it should be avoided _if possible_. IFD extends the duration of evaluation, which is single threaded and it affects the predictions of the `nix` progress bar.
IFD is a powerful feature, but it should be avoided _if possible_. IFD extends the duration of evaluation, which is single threaded and it affects the predictions of the `nix` progress bar.
Line 75: Line 75:
As a rule of thumb, if you can avoid IFD by refactoring Nix code or moving your build logic into the derivations themselves, you should do so.
As a rule of thumb, if you can avoid IFD by refactoring Nix code or moving your build logic into the derivations themselves, you should do so.


<h2>Recognizing IFD</h2>
== Recognizing IFD ==


The textbook case of IFD looks like `import (f drv)` where `f drv` is an expression that requires a build in order to return a value. However, `import` is not the only function that can require a build. For example, `builtins.readFile` can have the same effect.
The textbook case of IFD looks like `import (f drv)` where `f drv` is an expression that requires a build in order to return a value. However, `import` is not the only function that can require a build. For example, `builtins.readFile` can have the same effect.
Line 93: Line 93:
* <code>lib.cleanSource { src = f drv; }</code>
* <code>lib.cleanSource { src = f drv; }</code>
* ...
* ...
== Further reading ==
* https://fzakaria.com/2020/10/20/nix-parallelism-import-from-derivation.html