Lock Flattening
The Problem
Section titled “The Problem”Nix flakes fetch every input’s own lock file, which can result in many copies of the same package set (e.g. multiple nixpkgs versions) being downloaded and stored. Flattening forces all inputs to share common dependencies.
Built-in Modules
Section titled “Built-in Modules”flake-file ships support for two established flattening tools:
allfollow
Section titled “allfollow”spikespaz/allfollow automatically adds follows entries for all transitive inputs.
{ inputs, ... }: { imports = [ inputs.flake-file.flakeModules.allfollow ];}Source: modules/prune-lock/allfollow.nix
nix-auto-follow
Section titled “nix-auto-follow”fzakaria/nix-auto-follow detects duplicate inputs and injects follows for them.
{ inputs, ... }: { imports = [ inputs.flake-file.flakeModules.nix-auto-follow ];}Source: modules/prune-lock/nix-auto-follow.nix
How it integrates
Section titled “How it integrates”Both modules configure flake-file.prune-lock options, which instruct write-flake to run the flattener after writing flake.nix. You can also use the raw options for a custom tool:
{ pkgs, ... }: { flake-file.prune-lock = { enable = true; program = pkgs: pkgs.my-flattener; };}See the Options Reference for the full prune-lock schema.