divnix / nix-book

The Nix Package Manager
https://book.divnix.com
Creative Commons Zero v1.0 Universal
71 stars 11 forks source link

List of not-covered topics #21

Open jonringer opened 2 years ago

jonringer commented 2 years ago

Just need to write these down before I forget:

nrdxp commented 2 years ago

I have another one. Let attribute-sets let {}. Not sure if it needs to be covered though, as I think it's just the the syntatic desugaring of rec blocks, although a bit more explicit.

jonringer commented 2 years ago

Let attribute-sets

I'm not even familiar with this. But as an interesting aside, let blocks are implemented as a rec attr set.

nrdxp commented 2 years ago

I only found about them recently after getting to know the Nix tree-sitter grammar a bit. So for let {}, lets label the attribute-set x. It must contain a body key which is an arbitrary expression where all the other attributes defined in x are in scope. It is essentially another syntax for let in. And if body is an attribute-set itself, can be used as an alternative to rec. So:

let {
  x = 1;
  y = 2;
  body = x + y;
}

evals to 3.

jonringer commented 2 years ago

seems pretty advanced, in rust-lang book terms, I think that would be something which would go into the rust-nomicon instead "intro to nix" book :/

jonringer commented 2 years ago

Was thinking of moving back the build a package section and instead putting a how to use nixpkgs section. Then cover, the most common scenarios: using a flake, using nix develop, nix build, nix eval