Skip to content

Automatic Follows

flake-file can use flake-edit follow to add and remove follows declarations whenever flake.nix is generated.

This is an alternative to the flake.lock flattening hook. Both approaches reduce duplicate transitive inputs, but they store the result in different places. Generally, choose one rather than enabling both.

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

Alternatively, enable the underlying option directly with flake-file.auto-follow.enable = true.

write-flake updates flake.lock, runs flake-edit follow, and updates the lock again. The generated-file check runs the same follow operation on a temporary copy, so nix flake check also detects missing or stale automatic follows.

Automatic follows require pkgs.flake-edit version 0.3.5 or newer. Enabling the feature with an older or missing package produces an evaluation error identifying the required version.

Automatic followsLock flattening hook
Source of truthfollows declarations in flake.nixRewritten relationships in flake.lock
VisibilityRelationships are visible when reviewing flake.nixKeeps flake.nix free of generated follows
ConfigurationSupports per-nested-input opt-outsConfigured for the whole lock file
WritesUpdates both flake.nix and flake.lockRewrites only flake.lock after generation
Best fitExplicit, reviewable Nix-native followsExisting lock-flattening workflows or minimal generated flakes

Use automatic follows when you want deduplication represented as ordinary flake declarations. Use the lock hook when you want deduplication to remain an implementation detail of the generated lock file.

When automatic follows are enabled, flake-edit manages nested follows declarations by default. Exclude a particular nested input when it should not be followed automatically:

{
flake-file.inputs.crane.inputs.nixpkgs.autoFollow = false;
}

An exclusion cannot also configure follows: one requests no automatic follow while the other requests an explicit follow. flake-file reports that conflicting configuration when automatic follows are enabled.

Contribute Community Sponsor