Skip to content
AlexAntonikPublic

About

Interactive TUI viewer for Nix dependency graphs

Resources

Stars

142 stars

Watchers

2 watching

Forks

Repository files navigation

nix-graph

demo

Interactive TUI viewer for Nix dependency graphs. Like nix-tree, but more feature rich (sort, filter, reverse (dependents) view) and not that cool (Not in Haskell). Written in pure Go, no dependencies; only nix at runtime.

How it works

It runs nix path-info and renders the closure of the target as an expandable tree. You can inverse graph at any node so tree becomes dependents tree.

Columns:

  • NAR Size: The uncompressed size (in bytes) of store path after it is serialized into a Nix Archive (NAR) format.
  • Closure size: Size of the store path and all its transitive dependencies.
  • Added size: Size of the store path, and all its transitive dependencies minus sizes of already present dependencies in store, i.e., the cost of having that store path on top of all other paths.

Install

Install from nixpkgs, or run it without installing:

nix run github:AlexAntonik/nix-graph

Nix profile:

nix profile add github:Alexantonik/nix-graph

Flakes:

# flake.nix
{
  inputs.nix-graph.url = "github:AlexAntonik/nix-graph";
  inputs.nix-graph.inputs.nixpkgs.follows = "nixpkgs";

  outputs = { self, nixpkgs, nix-graph }: {
    nixosConfigurations.yourhostname = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ./configuration.nix
        ({ pkgs, ... }: {
          environment.systemPackages = [
            inputs.nix-graph.packages.${pkgs.stdenv.hostPlatform.system}.nix-graph
          ];
        })
      ];
    };
  };
}

fetchTarball:

# configuration.nix
{ config, pkgs, ... }:
let
  # replace this with an actual commit id or tag
  commit = "0000000000000000000000000000000000000000";
  nix-graph = import (builtins.fetchTarball {
    url = "https://github.com/AlexAntonik/nix-graph/archive/${commit}.tar.gz";
    # replace this with an actual hash
    sha256 = "0000000000000000000000000000000000000000000000000000";
  }) { inherit pkgs; };
in {
  environment.systemPackages = [ nix-graph ];
  # or home.packages = [ nix-graph ];
}

Usage

nix-graph [path]

where path is a store path, profile, or derivation (default: /run/current-system).

Examples:

nix-graph                                             # current system closure
nix-graph "$(which bash)"                             # current bash closure
nix-graph /nix/store/x9...m-nix-2.34.8                # a specific package closure
nix-graph "$(nix eval --raw 'nixpkgs#bash.drvPath')"  # a .drv: build-time graph

Reverse view (p)

Press p to flip the tree at selected node: the node you are on becomes root and the tree inverts, showing its dependents. Press p again and it flips back to dependencies. That means you can walk down from the top level to some package, flip the view, trace your way back up to see what depends on it, flip again, and keep going back and forth as much as you want. esc resets to the default dependency tree, and P opens every package as its own root.

Contributing

All contributions, issues and feature requests are welcome.

Similar

  • nix-tree — Inspiration, similar functionality
  • nix-melt — A ranger-like flake.lock viewer

About

Interactive TUI viewer for Nix dependency graphs

Resources

Stars

142 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages