Not so long ago, I installed NixOS. It is quite wonderful in its declarative view to package management and system configuration.
From near the beginning, and in many of the third-party Nix utilities I use, there is a lot about this thing called Flakes. For all I know, it has something to do with declaratively managing Nix Channels, however whenever I search for an article on Nix Flakes, I almost instantly get overwhelmed by so much information.
Could any of you inform me about what Flakes is, what it is used for, and how to use it?
Nix flakes is a two part concept. First, there’s the dependency management. It allows you to specify what external nix code you want to depend on, in a way that locks versions of those dependencies. It will then call a function in your flake.nix file called outputs, which can technically return anything you want.
Second, there’s the CLI. All the subcommands under the nix command (not e.g. nix-build or nix-shell) will operate on flakes by default, and it documents a conventional schema for the return value of your outputs function. You don’t have to follow this convention, but it’s by far the most common way people write flakes.
Other than that, it’s just regular Nix, except that it doesn’t allow your Nix code to do “impure” things like accessing environment variables or importing / reading files not checked into git.