MCPcopy Index your code
hub / github.com/Mic92/nix-diff-rs

github.com/Mic92/nix-diff-rs @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
110 symbols 246 edges 11 files 17 documented · 15% updated 3d agoassets · 2026-03-28★ 601 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

nix-diff-rs

A Rust port of nix-diff, a tool to explain why two Nix derivations differ.

nix-diff output with inline word highlighting

Features

  • Compare two Nix derivations and show their differences
  • Support for multiple input types:
  • .drv files (pre-built derivations)
  • Realized store paths
  • .nix files (will be instantiated automatically)
  • Flake references (e.g., nixpkgs#hello, path:/path/to/flake#package)
  • Colored output with support for NO_COLOR environment variable
  • Delta-style inline word highlighting (shows what changed in each line)
  • Minimal dependencies

Installation

nix run github:Mic92/nix-diff-rs

Usage

nix-diff [OPTIONS] <INPUT1> <INPUT2>

Arguments:
  <INPUT1>    First input (.drv file, store path, .nix file, or flake#attr)
  <INPUT2>    Second input (.drv file, store path, .nix file, or flake#attr)

Options:
  --color <MODE>         Color mode: always, auto, never (default: auto)
  --no-inline-highlight  Disable word-level highlighting within changed lines
  --context <LINES>      Number of context lines (default: 3)
  --input-list-limit <N> Max added/removed inputs to list (default: 10)
  --depth <N>            Max recursion depth into input derivations
  -v, --verbose          Show output-path changes and full input lists
  -h, --help             Show this help message

By default, the output hides mechanical noise such as output-path changes (which differ whenever anything else differs) and env vars that mirror output paths ($out, $dev, ...). Use --verbose to show everything, or --depth N to limit how deep the diff recurses into dependencies.

When color is enabled, changed words within changed lines are highlighted with reverse-video (like delta or diff-so-fancy), so you can instantly spot store-path hash changes and version bumps without scanning full lines.

Examples

Compare two derivations:

nix-diff /nix/store/abc123-hello.drv /nix/store/def456-hello.drv

Compare realized store paths:

nix-diff /nix/store/abc123-hello /nix/store/def456-hello

Compare Nix files (will be instantiated automatically):

nix-diff hello.nix goodbye.nix

Compare flake outputs:

# Compare packages from flakes
nix-diff nixpkgs#hello nixpkgs#hello-wayland

# Compare local flake outputs
nix-diff .#packages.x86_64-linux.myapp .#packages.x86_64-linux.myapp-dev

# Compare using flake paths
nix-diff path:/path/to/flake1#package path:/path/to/flake2#package

Limit recursion depth (useful when stdenv changed and you only care about the top-level differences):

nix-diff --depth 1 nixpkgs/nixos-25.11#hello nixpkgs/nixos-unstable#hello

Disable colors:

nix-diff --color never input1 input2
# or
NO_COLOR=1 nix-diff input1 input2

Development

# Enter development shell
nix develop

# Build
cargo build

# Run tests
cargo test

# Run benchmarks
cargo bench

# Format code
nix fmt

License

BSD-3-Clause (same as the original nix-diff)

Core symbols most depended-on inside this repo

write_indent
called by 28
src/render.rs
parse_derivation
called by 9
src/parser.rs
format_string_diff
called by 8
src/render.rs
write_section
called by 7
src/render.rs
setup_nix_env
called by 6
tests/common.rs
empty_drv
called by 5
src/render.rs
diff_bytes
called by 5
src/diff.rs
format_derivation_diff
called by 4
src/render.rs

Shape

Function 50
Method 38
Class 17
Enum 5

Languages

Rust100%

Modules by API surface

src/render.rs34 symbols
src/types.rs22 symbols
src/diff.rs18 symbols
src/instantiate.rs11 symbols
src/parser.rs8 symbols
tests/snapshot_test.rs6 symbols
tests/integration_test.rs4 symbols
src/main.rs4 symbols
benches/nixos_derivation.rs2 symbols
tests/common.rs1 symbols

For agents

$ claude mcp add nix-diff-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact