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.
The lock-flattening hook is an alternative to automatic follows declarations with flake-edit. Flattening keeps generated follows out of flake.nix and records the deduplication only in flake.lock. See the comparison table before choosing; generally, enable one approach rather than both.
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.