brewdiff
A Rust crate that provides diff functionality for Homebrew packages managed through nix-darwin. It compares what Homebrew actually has installed on the system versus what a nix-darwin configuration declares should be installed.
Purpose
This crate is designed to show users what Homebrew changes will occur when they activate a new nix-darwin configuration, similar to how the dix
crate shows Nix store diffs.
Features
- Extract Homebrew intent from nix-darwin profiles
- Query current Homebrew state (installed formulae, casks, and taps)
- Compute differences between current state and intended state
- Colorized output with clear add/remove indicators
- Thread-based async processing (mirrors dix pattern)
Example Output
<<< /run/current-system
>>> /nix/var/nix/profiles/system-123-link
ADDED
Formulae
[A] curl
Casks
[A] firefox
[A] visual-studio-code
REMOVED
Formulae
[R] wget
Casks
[R] slack
How It Works
- Reads the nix-darwin activation script to find the Brewfile path, then parses that Brewfile to extract Homebrew intent
- Queries Homebrew directly for current state:
- Uses
brew leaves
for formulae (only user-installed packages, not dependencies) - Uses
brew list --cask
for casks - Uses
brew tap
for taps - Uses
mas list
for Mac App Store apps
- Uses
- Diffs current state with intended state to find additions and removals
- Formats the diff with colors and clear indicators
API
use brewdiff;
use Path;
// Primary use case: compare current state with new nix-darwin profile
let new_profile = new;
// Async diff computation
let handle = spawn_homebrew_diff;
if let Ok = handle.join
// Or synchronous diff with output
let lines_written = write_homebrew_diffln?;