Interactively browse dependency graphs of Nix derivations.
Go to file
github-actions[bot] 63128e73f8 flake.lock: Update
Flake lock file updates:

• Updated input 'nixpkgs':
    'github:nixos/nixpkgs/6132b0f6e344ce2fe34fc051b72fb46e34f668e0' (2024-05-30)
  → 'github:nixos/nixpkgs/1e3deb3d8a86a870d925760db1a5adecc64d329d' (2024-06-27)
2024-07-01 12:28:12 +12:00
.github/workflows ci: Update nixos versions to test 2024-05-13 10:29:49 +12:00
src Shutdown vty when done 2024-04-07 21:50:10 +12:00
test Delete duplicate file 2021-09-04 22:23:12 +12:00
.gitignore Stop using flakes 2021-05-05 23:51:34 +12:00
asciicast.sh Update asciicast 2021-02-28 00:12:41 +13:00
CHANGELOG.md Release v0.4.1 2024-04-07 22:13:40 +12:00
default.nix Move to a flake-based setup 2022-10-24 11:52:14 +13:00
flake.lock flake.lock: Update 2024-07-01 12:28:12 +12:00
flake.nix Get back to nixpkgs-unstable 2024-04-01 22:38:48 +13:00
format.sh ci: Do not try to format absent file 2022-11-07 15:15:05 +13:00
LICENSE Add LICENSE 2020-12-22 10:52:02 +13:00
nix-tree.cabal Release v0.4.1 2024-04-07 22:13:40 +12:00
README.md Use more condensed repology badge 2024-02-22 12:31:21 +13:00
shell.nix Revert "Remove shell.nix, use 'nix develop' instead" 2022-12-04 22:56:45 +08:00

nix-tree

Build Status Packaging status

Interactively browse dependency graphs of Nix derivations.

asciicast

Installation

nix-tree is on nixpkgs since 20.09, so just use your preferred method for adding packages to your system, eg:

nix-env -iA nix-tree

Or, for flake enabled systems:

nix profile install 'nixpkgs#nix-tree'

To run the current development version:

nix run github:utdemir/nix-tree -- --help

Usage

$ nix-tree --help
Usage: nix-tree [INSTALLABLE] [--store STORE] [--version] [--derivation] [--impure] [--dot]

  Interactively browse dependency graphs of Nix derivations.

Available options:
  INSTALLABLE              A store path or a flake reference.
                           Paths default to "~/.nix-profile" and "/var/run/current-system"
  --store STORE            The URL of the Nix store, e.g. "daemon" or "https://cache.nixos.org"
                           See "nix help-stores" for supported store types and settings.
  --version                Show the nix-tree version
  --derivation             Operate on the store derivation rather than its outputs
  --impure                 Allow access to mutable paths and repositories
  --dot                    Print the dependency graph in dot format
  -h,--help                Show this help text

Keybindings:
  hjkl/Arrow Keys : Navigate
  w               : Open why-depends mode
  /               : Open search mode
  s               : Change sort order
  y               : Yank selected path to clipboard
  ?               : Show help
  q/Esc           : Quit / close modal

Glossary

  • NAR Size: Size of the store path itself.
  • Closure size: Total size of the store path and all its transitive dependencies.
  • Added size: Size of the store path, and all its unique transitive dependencies. In other words, the cost of having that store path on top of all other paths. See issue #14 for a better explanation.

Tips

nix-build prints built paths to stdout, which can be piped conveniently with | xargs -o nix-tree. Examples:

# Output of a local derivation
nix-build . --no-out-link | xargs -o nix-tree

# Build time dependencies (passing a `.drv` path)
nix-instantiate . | xargs -o nix-tree --derivation

# Dependencies from shell.nix
nix-build shell.nix -A inputDerivation | xargs -o nix-tree

# All outputs of a derivation in nixpkgs
nix-build '<nixpkgs>' -A openssl.all --no-out-link | xargs -o nix-tree

nix-tree also supports flake references:

# Build time dependencies of a flake on the current directory
nix-tree --derivation '.#'

# Same thing works for any flake reference
nix-tree --derivation 'nixpkgs#asciiquarium'

Run nix-tree on your current nixos system:

nix-tree /nix/var/nix/profiles/system

Query the binary cache before download, with the --store option:

# Query the runtime dependency of `stellarium` (2 GiB closure) without download
nix eval --raw 'nixpkgs#stellarium.outPath' | xargs -o nix-tree --store https://cache.nixos.org

For valid --store options, see nix help-stores. For example,

# Build in a temporary chroot store and examine the output
nix build --store /tmp/chroot-store 'nixpkgs#hello' --print-out-paths | xargs -o nix-tree --store /tmp/chroot-store

Contributing

All contributions, issues and feature requests are welcome.

To hack on it, simply run nix-shell and use cabal as usual. Please run ./format.sh before sending a PR.

  • nix-du: Visualise which gc-roots to delete to free some space in your nix store
  • nix-melt: A ranger-like flake.lock viewer
  • nix-query-tree-viewer: GTK viewer for the output of nix-store --query --tree
  • nix-visualize: Uses the Nix package manager to visualize the dependencies of a given package