Should I use flake or not

I switched to the flake-based NixOS configuration on my laptop for more than two years. It works as well as the channel-based setup, with two additional benefits:

  1. It’s reproducible and updatable. In the flake-based setup, all the input revisions (channel revisiots) are recorded inside a text file flake.lock in the flake-based setup. You could bring flake.nix, flake.lock and other configuration files to another computer and set them up with exactly the same version of everything. You could update input-by-input with nix flake lock --update-input inputname, or update all the inputs by nix flake update without manually changing the hashes.

    In contrast, the only way to ensure reproducibility for the channel-based setup when setting up on another machine (or after system-wide reinstallation) is not to use the channel, but pin everything with fetchers and hashes instead. When updating, you’ll need to nix-prefetch every pinned source and update the hashes manually inside the configuration files. That makes updating laborious, and being reluctant to update exposes the setup to the risk of newly-discovered security vulnerabilities.

  2. The configuration can be passed into other flakes. For example, I use Home Manager to manage my per-user dot files, and I could get the system-level configuration by adding the system flake as a flake input:

    {
      inputs.system-config.url = "git+file:///etc/nixos";
    }
    

    There are two use cases for me:

    1. pkgs from the system: It’s sometimes required to ensure that the version of some user-installed packages be compatible to some others installed system-wide. That’s when
      pkgsSystem = inputs.system-config.legacyPackages.${system};
      
      comes in handy.
    2. Home Manager xsession configuration with the desktop environment installed system-wide.
3 Likes