NixOS flake or not to flake

Published June 21, 2024

This is the question since flakes were introduced in NixOS, we all know the answer.

Who cares! Flakes as far as today are something on top of what we all used to do before flakes.

Well, nothing for me before flakes excited since I started with them more or less. And this is actually a good point, I engaged with nix when I noticed shell.nix on every repository in my previous company and I started looking around to know more about what this nix was. When I decided to pick up Nix on my own, I started with flakes, and it is surprising now that I know a bit better how all of this came together. A relatively new feature compared with the longevity of the project overall turns to be the entry point for myself and many more people. I am sure there is something valuable here.

There are also pain points I am sure, for example to me, it looks like I always need to download something from the internet, yes there are nix registries, but what am I doing? Pinning, a pinned version of a nixpkgs? Am I loosing all the safe contained and explanatory fun from flakes with that? Probably not because the resolution of such reference will be in the lock file, but it didn’t feel right to me.

I am sure you are confused, and this is a common feeling when we look for answers that are probably not that valuable.

Use what you like. I started with Flake, when contributing to nixpkgs you don’t get them if you don’t want, flakes are an encapsulation mechanism, you can write your configuration.nix and then import it as a module inside a flake if you need to build a nixos derivation. Or you can write a shell.nix as you always did and then import it in a flake if you want. Or if the maintainer of the project you want to use does not want to, you can always import it in your own flake because this is what Nix is good at, it can be used as you want. Can this be overwhelming? I bet it is, but it is powerful.

Flakes are also an excuse for the community to implement a new user experience, since a project of the age of Nix is reasonable to turn a bit confusing to use.

My suggestion is to take a look at this blog post from Jade: “Flakes are not real”, but what do I do? I use flakes because I know how to use them, but when I have the time I experiment without them because I would like to contribute more to the project and since Flakes are not real I want to embrace the full capacity of this tool, so I want to be familiar with Nix without them.

Are you having trouble figuring out your way to building automation, release and troubleshoot your software? Let's get actionables lessons learned straight to you via email.