A tool to detect and report duplicate dependencies in Nix flakes.
Nix flakes use a lock file (flake.lock) to pin dependencies to specific versions, ensuring reproducible builds.
However, when multiple flakes in your dependency tree depend on the same upstream flake (like nixpkgs or flake-utils),
they might reference different versions of it.
This creates several issues:
-
Increased Closure Size: Each version of a dependency must be downloaded and stored separately, significantly increasing disk usage and download times.
-
Evaluation Performance: Nix has to evaluate multiple versions of the same flake, slowing down your build times and
nix flakecommands. -
Inconsistent Behavior: Different parts of your project might use different versions of the same packages, leading to subtle bugs and version conflicts.
This commonly occurs when:
- Your project uses multiple third-party flakes
- Those flakes haven't synchronized their
flake.lockupdates - Transitive dependencies pin different versions of common utilities (like
flake-utils,nixpkgs, etc.)
flake-linter scans your flake.lock file and identifies all cases where the same dependency appears multiple times with different versions,
helping you spot these issues before they impact your project.
$ cd your-flake-project
$ nix run github:Mic92/flake-linter
github:numtide/flake-utils has multiple versions:
flake-utils is used by: crane, pre-commit-hooks-nix, root, rust-overlay
flake-utils_2 is used by: lanzaboote# Run on a specific flake.lock file
$ flake-linter /path/to/flake.lock
# Show all dependencies (including single versions)
$ flake-linter --verbose
# Exit with error code if duplicates are found (useful for CI)
$ flake-linter --fail-if-multiple-versionsRun directly with Nix:
nix run github:Mic92/flake-linterOr add to your flake inputs for regular use:
{
inputs.flake-linter.url = "github:Mic92/flake-linter";
}- Update Inputs: Run
nix flake updateto try getting your dependencies on the same versions - Override Inputs: Use flake input follows to force dependencies to use your version:
inputs.some-flake.inputs.nixpkgs.follows = "nixpkgs";
MIT