nix-pills icon indicating copy to clipboard operation
nix-pills copied to clipboard

Chapter 6 could do with a definition of derivation

Open Soupstraw opened this issue 3 years ago • 3 comments

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.

Soupstraw avatar Feb 04 '22 10:02 Soupstraw

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 avatar Mar 08 '23 23:03 apoelstra

@apoelstra fully agree, this is a surprisingly nasty topic that needs some untangling. Related: https://github.com/NixOS/nix/issues/7829

fricklerhandwerk avatar Mar 14 '23 11:03 fricklerhandwerk

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.

I've stumbled upon this very same problem in the past

Soupstraw avatar Mar 14 '23 11:03 Soupstraw