Skip to content

Lock Flattening

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.

flake-file ships support for two established flattening tools:

spikespaz/allfollow automatically adds follows entries for all transitive inputs.

{ inputs, ... }: {
imports = [ inputs.flake-file.flakeModules.allfollow ];
}

Source: modules/prune-lock/allfollow.nix

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

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.

Contribute Community Sponsor