4 ms·
> What they add from vanilla Nix. Flakes add a couple of things: 1. They ensure the version of nixpkgs used is 'locked': In pre-flake Nix, working with nixpkg
by rgoulter 4y ago
> What they add from vanilla Nix.
Flakes add a couple of things:
1. They ensure the version of nixpkgs used is 'locked': In pre-flake Nix, working with nixpkgs involved using channels. The channel more/less was a clone of some git repository. But, what revision is checked out may vary from machine to machine, since the channels may be updated at different times.
2. Flakes provide a consistent entry point to Nix code. In pre-flake Nix, there were different conventions, but you'd have to know the contents of a file named "default.nix" to know how to work with it. With "flake.nix", the file follows a specific schema, and has a standard way of working with it.
> What they take away.
There's added restrictions on purity. IIRC, stuff like fetchUrl needs to specify the checksum when using flakes.
> How they work.
In pre-flake Nix, you'd need to have certain channels installed to use some expressions (or to use a tool like Niv to avoid using system channels).
With flakes, pretty much once you've declared your inputs and declared the outputs of your nix code (what its packages, overlays, apps, etc. are), the Nix code used by the flake is otherwise the same.
> Why channels are unnecessary with flakes (once they're complete) as TFA implies.
Channels are an implicit per-user way that inputs are used in Nix code. Flakes need inputs to be declared.
> Why else I should care about them.
The CLI is much nicer. e.g. you can have "nix run github:<owner>/<repo>" and it fetches/builds/runs the repo, if it specifies a default app or default package. - Stuff like this is why I'd compare Nix to "like Docker, without containers".
> Are they just adding the equivalent of lockfiles to vanilla Nix? If so, why is that such a hard transition? My initial impression on reading about Nix, and I've read a lot, is that Nix already had lockfiles.
I think the tool Niv offered similar functionality as the input locking from Nix flakes. But, well, that's a community tool, and still doesn't imply a standard way of invoking a Nix file.
There was a lot of fuss over the big Nix 2.4 release, which had many changes since Nix 2.3. Some of the frustration was that the Nix 2.4 release made breaking changes to non-flake stuff which worked in Nix 2.3.
I used non-flake nix for some time before trying out flakes. I needn't have waited. It's initially a bit of boilerplate to copy-paste. But, I didn't have pain moving stuff to flakes, and flakes are neat.
- ghoward 4y agoThis is a great answer, thank you. I think what hindered my understanding was the claim that Nix was purely functional, so it never made sense why flakes were needed. Knowing that Nix is not purely functional, i.e., that channels were still an implicit input, might be the missing piece for me.
- ChadNauseam 4y agoYup. Here's a mental model you may find useful: in Nix, the process executed by the build graph is always purely functional. But when you run `nix-build`, it has to compute the build graph, and that is not necessarily functional. Nix flakes provide a functional way to generate the build graph