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.
nix why-depends </run/current-system> /nix/store/<checksum-package-version.ext> nix why-depends </run/current-system> /nix/store/<checksum-package-version.ext> #!/bin/bash
# Show Dependency Reason Current Nixos
nix why-depends {{/run/current-system}} /nix/store/{{checksum-package-version.ext}} import subprocess
# Show Dependency Reason Current Nixos
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"nix",
"why-depends",
"</run/current-system>",
"/nix/store/<checksum-package-version.ext>"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: nix not found. Please install it first.")
if __name__ == "__main__":
run_command() 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.