I’m shaky in my understanding of flakes but I keep seeing projects posting flake files instead of shell.nix files or being shared as flakes instead of packages
How can I understand flakes fundamentally better? I’m a visual learner if good educational videos are out there but I also love a blog post from a good writer
There isn’t anything hard or inherently different about flakes with nix. The only different thing is that it’s blessed by having some cli integration and acting as an entry point to nix expressions and has a rather opinionated/restricted schema.
There some magic under the hood, but in short:
Nix expression inputs with some update mechanisms as a first party tool.
Somewhat easy whitelisting for pure-eval, though the same can be accomplished without flakes.
Cli
That’s about it. There isn’t anything to learn other than discover bugs in the implementation.
I don’t have direct experience with flakes but I’m ready to take the plunge and have been doing a lot of research. Vimjoyer has excellent Nix videos and he explains flakes in multiple. Here’s one.
But flakes do not come in isolation, they come with pure eval and bugs and eval-time penalties and etc etc.
Except these bugs get rediscovered by every new user and they get bewildered and come here. It seems handwavey and out-of-touch to put it this way; it reminds me of maths profs/textbooks that say “proof is trivial” and then actually writing it out it ends up being 500 pages long. No matter how you look at it, the bugs are the API.
Anyway @ammaratef45, here’s an explainer for flakes:
And here’s how you can achieve some of the same input pinning goals without flakes (this predates system.nix):
With system.nix:
One of flakes’ 57 goals is to provide a unified API for consumers of projects, hence you would see a flake.nix in a project repo and the attributes returned by the outputs function explain what the flake provides. Alternatively you can use nix flake show <flake-url> to see a summary of said flake outputs.
These outputs are then used by the so-called “nix 3” interface which is basically everything under section 8.5 of the nix manual: Experimental Commands - Nix 2.35.2 Reference Manual
Different commands will need/expect different outputs, they are documented in a pretty scattershot way in the manual but it is ultimately all there.
Flakes - Official NixOS Wiki has a bit of info but it’s not 100% comprehensive nor does it provide the full context. Still it may be helpful as a summary of the various supported outputs.