Flakes: How critical is learning and using flakes? Am I missing out on something?

I’m fairly new to NixOS; I’ve only been using it for 3 months.

So far, the whole configuration.nix, along with declarative, immutable, and reproducibility features, have been some of the best features to keep me using NixOS. I love how I’m able to migrate my configuration.nix to different laptops/desktops, and how it reproduces itself with a few mere commands.

…But what are Flakes?

I haven’t gone as far to venture into Flakes, which I keep reading is “experimental,” but I also don’t understand what they are. I’ve tried reading from the wiki: Flakes - NixOS Wiki. But I don’t seem to understand the benefits of using flakes, such as “Nix expression,” or how it improves the Nix ecosystem.

The only things I’ve been figuring out is to see what packages work or are broken on Nix, and how I would download the Flatpak version if the Nix pkgs fail to work.
I’ve also been figuring out if NixOS poses any specific necessary hardware configuration on different devices (computers with AMD/nvidia/intel GPUs, Mac desktops, and etc.). I also use NixOS on an external M.2 drive so I can test it on different hardware, and to see if it conflicts from system to system.

But aside from that, I don’t know why I would bother learning or trying out Flakes. Can anyone point me to a direction, some useful reading material, or break it down for me in a few sentences?


1 Like

Well, the biggest selling point for a just-NixOS user is that they do away with channels. Channels are currently how you update your system and stuff, there’s a stateful set of files somewhere on your system that specifies what version of nixpkgs your system currently uses to build itself.

This is horribly imperative, if you move your configuration.nix between systems you’ll have no idea if it’s going to work on there too.

People used to work around this by fetchurl-ing a specific nixpks tarball. Updating this was a pain, so tools were created to make this easier, etc. etc., but ultimately this was a design flaw of nix.

Flakes replace this with an input schema, which can just track git branches, and adds a lockfile much like the npm/cargo ones, which can be updated with nix flake update. Now you actually have reproducible configurations, and built-in support for managing your dependencies in nix.

Besides fixing this glaring problem, the basic concept is a file much like Cargo.toml, package.json and pyproject.toml. It defines what your project contains. This is useful, because now when you run into a random nix project in the wild, you can easily add it as a dependency to your nix project, and use its outputs in a standardized way.

There are still some issues with flakes, like the integration with NixOS isn’t perfect yet, documentation is lacking, and there are some unresolved issues with how they work.

There’s also the fact that, yes, they are experimental, and everything may fundamentally change so you need to rewrite your flake in the future. And there’s some community dissent caused by how they were introduced, which ripples through every discussion and hampers progress towards actual stabilization.

With that said, personally I think flakes are an obviously good thing. They also (currently, they will apparently be decoupled in the near future) come with a new nix CLI which fixes many UX problems. I don’t think using nix without flakes makes much sense, it just completely fixes so many UX problems. I look forward to stabilization so I can say that without feeling like I’m going to have pitchforks thrown at me.

  • Flakes give you far more comfortable control over the exact dependencies that you use in any given Nix … context (for lack of a better word without baggage).

  • Flakes make it far easier to compose and share nix … things (once again, trying to stay away from technical vocab).


The documentation team tried to work out a dispassionate summary of the highly-level facts, with links to the technical details and ongoing discussions: Flakes — nix.dev documentation

Feedback and suggestions to improve the documentation are very welcome. Hopefully we manage to avoid people having to ask the same questions all over again. My biggest personal gripe is that so far flakes are mostly advertised rather than explained.

1 Like

In the spirit of advertising somebody else work, I was helped a great deal in understanding the syntax of flakes by this repository: GitHub - Misterio77/nix-starter-configs: Simple and documented config templates to help you get started with NixOS + home-manager + flakes. All the boilerplate you need!

It might help others finding this post.