nix Verified current stable Not installed? Package Management

Nix / Show Dependency Reason Current Nixos

Show Dependency Reason Current Nixos

Identifies why a specific package is included in the current NixOS system by analyzing dependencies.

$
Terminal
nix why-depends </run/current-system> /nix/store/<checksum-package-version.ext>

When To Use

During system integrity verification processes to troubleshoot unexpected package presence in current system.

Pro Tip

Consider using the `--json` flag if you require machine-readable output for automated analysis.

Anatomy of Output

Understanding the result

/nix/store/some-package-1.0.0: dependent on '/nix/store/dependency-2.0.0' (build) Package Path

The absolute path of the analyzed package.

Reason: installed due to 'some meta-package' Reason

Indicates the meta-package influencing this dependency.

Referenced from: /run/current-system Reference Path

The system path where the dependency was identified.

Troubleshooting

Common pitfalls

error: path '/nix/store/invalid-path' does not exist

Solution: Verify the path syntax and ensure the package exists in the Nix store.

error: cannot find derivation for 'nixpkgs#nonexistent-package'

Solution: Check the correctness of the package name or ensure the relevant channel is up-to-date.

error: invalid argument: 'XYZ' is not a valid dependency

Solution: Ensure the provided arguments conform to accepted package naming conventions.

Command Breakdown

What each part is doing

nix
Base Command
The executable that performs this operation. Here it runs Nix before the shell applies any redirect operators.
</run/current-system>
run current system
The value supplied for run current system.
<checksum-package-version.ext>
checksum package version.ext
The value supplied for checksum package version.ext.

Alternative Approaches

Comparable commands in other tools

Alternative package management tools for the same job.