Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 6 could do with a definition of derivation #193

Open
Soupstraw opened this issue Feb 4, 2022 · 3 comments
Open

Chapter 6 could do with a definition of derivation #193

Soupstraw opened this issue Feb 4, 2022 · 3 comments

Comments

@Soupstraw
Copy link

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.

@apoelstra
Copy link

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!

@fricklerhandwerk
Copy link
Contributor

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

@Soupstraw
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

3 participants