LinuxCommandLibrary

nix-why-depends

Show why a package depends on something

TLDR

Show why the currently running NixOS system requires a certain store path

$ nix why-depends [/run/current-system] [/nix/store/...]
copy

Show why a package from nixpkgs requires another package as a _build-time_ dependency
$ nix why-depends --derivation [nixpkgs#dependent] [nixpkgs#dependency]
copy

SYNOPSIS

nix-why-depends [--all] [--no-build] [--impure]

PARAMETERS

derivation
    The target derivation or package path whose dependencies are to be analyzed. This is the starting point of the dependency trace.

dependency
    The specific dependency whose path is to be found. This is the package or derivation that you're trying to understand why the target depends on.

--all
    Show all dependency paths between the derivation and the dependency. Without this flag, only the first found path is displayed.

--no-build
    Avoid building derivations during the dependency analysis. This speeds up the process but might result in incomplete or inaccurate results if some dependencies are only visible after a build.

--impure
    Allow impure builds during the dependency analysis. This might be needed for some derivations, but use it with caution as it can introduce non-determinism.

DESCRIPTION

The `nix-why-depends` command helps users understand why a specific package or derivation depends on another. It traces the dependency graph, showing the path from the target package to the dependency in question. This is invaluable for debugging dependency issues, identifying unnecessary dependencies, and optimizing Nix configurations. It can significantly improve a Nix user's understanding of their system's dependency structure, revealing often complex relationships between packages. This is useful for reducing rebuild times and creating leaner Nix environments. The command traverses the dependency graph starting from the specified derivation and reports the path to the dependent one.

CAVEATS

The results may vary depending on whether the derivations have been built. The `--no-build` flag can improve performance but potentially miss some dependencies.

EXAMPLE USAGE

nix-why-depends /path/to/my/package.nix bash
This finds a path from /path/to/my/package.nix to the bash package.

INTERPRETING OUTPUT

The output shows the chain of dependencies, with each line indicating a derivation and the attribute that depends on the next derivation in the chain. Carefully examine the attribute names to understand the specific dependency relationships.

SEE ALSO

Copied to clipboard