NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.06k stars 1.47k forks source link

Diffing values #1164

Open Ericson2314 opened 7 years ago

Ericson2314 commented 7 years ago

When doing my nixpkgs refactors, I'm often trying to avoid changing any hashes. To help me diagnose why a hash changes, it would be really nice to be able to compare two nix values and do a tree diff.

For example, comparing { a = { q = null; }; } and { a = { }; b = [ 2 ]; }, I'd love something like:

{
  a = {
    -q = null;
  };
  +b = [ 2 ];
}

It's possible a nixpkgs lib function would suffice, in which case I'll reopen the issue there.

Ericson2314 commented 7 years ago

One thing that would be nice to toggle is whether to recur into derivations or just treat them as an atom. Ideally I'd be able to say "always atomic" "never atomic" or "non-atomic for n derivations deep".

vcunat commented 7 years ago

Several times I diffed the *.drv files and "recursed manually" into suspicious differences. Some tool for this would be nice to have, though I suspect it would be tricky to cover more complex cases reasonably...

thufschmitt commented 7 years ago

Wouldn't something using toJSON (or toXML, but this would probably be less readable) and then a json diffing tool be sufficient for most cases and simpler to implement than rewriting this in nix ?

Of course the call to toJSON would still need to be wrapped to prevent unwanted stuff from being evaluated − if you want to diff the entire nixpkgs repo for example −, but that should be feasible I think

Ericson2314 commented 7 years ago

@regnat Good point. I was going to raise a concern about laziness and cycles, but that is a problem with my original proposal too. Pruning at a certain depth (or, even better, an attempt to break cycles along the lines of the infinite recursion check) would solve that.

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

stale[bot] commented 2 years ago

I closed this issue due to inactivity. → More info