nix-pills
nix-pills copied to clipboard
Chapter 6 could do with a definition of derivation
The intro to chapter 6 mentions that
Derivations are the building blocks of a Nix system, from a file system view point.
.. and then it jumps to describing how to create a derivation. As someone who is only starting to learn Nix, it would be really helpful to have a subsection about what a derivation is exactly and why i would want to create one.
I think a good solution to this would be to take the glossary entry for "derivation" and then address some of the issues pointed out in Ian Henry's How to Learn Nix.
To add to this, the existing text "A derivation from a Nix language view point is simply a set, with some attributes. Therefore you can pass the derivation around with variables like anything else." is misleading. A derivation is not a set; if you take a derivation and modify it with // newAttrs you will find that nothing happens -- in fact // builtins.trace "hello?" newAttrs will show that newAttrs is not even evaluated.
See this stackexchange post where a user stumbled over these same words, and eventually discovered that lib.overrideDerivation is needed to get "set-like" behavior from a derivation. Reading the source code of overrideDerivation shows it is using the drvAttrs attribute of the derivation .... which is defined in the pills as "basically the input we gave to the derivation function" ... while the actual Nix manual does not mention this at all!
@apoelstra fully agree, this is a surprisingly nasty topic that needs some untangling. Related: https://github.com/NixOS/nix/issues/7829
A derivation is not a set; if you take a derivation and modify it with
// newAttrsyou will find that nothing happens -- in fact// builtins.trace "hello?" newAttrswill show thatnewAttrsis not even evaluated.
I've stumbled upon this very same problem in the past