Practical nix flakes anatomy: a guided tour of flake.nix

I’ve written an overview of the most common(and some of the less common) components of a flake.nix file here.

There’s quite a lot of details about flakes’ inputs and outputs and how they all work together. There’s also some common code patterns that one might encounter when using flakes but ones that I haven’t seen in detail.

While the guide does require some initial knowledge of nix and flakes, I tried to make the sections as non-convoluted and self-contained as possible.

Feedback is very much welcome!

27 Likes

This is very good. I’ve had several questions about how flakes operate but never known how to tackle them (combine with lack of time and incentive…), but this pushed me over;
I’m using it to modularize my infrastructures and creating tests. Thanks for taking the time to write it.

1 Like

Really detailed, love it.

There is one point I’d want to mention, and that’s to discourage the use of the registry, as that can break eval for others if that registry entry points to a store path.

Possibly devShell.<system> and defaultPackage.<system> are worth a mention too, despite their deprecation, to clarify what people should use instead.

2 Likes

Thanks for the feedback! I revisited the article and made some updates:

  1. A note about the registry (nixpkgs specifically)
  2. Added deprecated outputs
  3. Turns out I forgot all about bundlers, though I haven’t really seen one that wasn’t from NixOS/bundlers in the wild
  4. Fixed borked URL to 2.21 release notes, all other URLs seem OK
2 Likes

I’m learning nix and co. and just wanted to say that your blog is a gold mine! Thank you very much!

1 Like

The one thing i wanted so desperate to know about.
Im just half way through yet, and couldn’t wait to Thank you :pray:.

I’d love to see the content from this upstreamed to https://www.nix.dev! Documentation on the internals of flakes is sorely lacking within the community, and this would be a great step to improve that.

1 Like

I concur: I often use this guide as reference material.
It’s good enough to canonize.