Closed sternenseemann closed 2 years ago
This is probably not a huge concern for real-world use cases and not necessarily an issue fixable in
nix-diff
, but something to be aware of.
I wouldn’t say so, as even a simple
builtins.readFile ./foo
will inline the file into the drv, and if it contains any binary data that is not unicode, nix-diff
fails currently.
I think the easiest fix here is to use Data.Text.Encoding.decodeUtf8With Data.Text.Encoding.Error.lenientDecode
and use the resulting text. This will replace all non-utf8 bytes with the unicode replacement character and we can go on and use the nix-derivation parser on the result.
I’m gonna prepare a PR.
Text.IO.readFile
uses the system's locale (which usually will be UTF-8):Files that will be diffed may be any files imported into the nix store by virtue of being referenced as Nix path in a derivation. One example of this which likely many will run into is the gzipped patch file
pkgs/development/libraries/glibc/2.33-master.patch.gz
from nixpkgs. Any diff involving any such file will causenix-diff
to fail with an exception.A simple fix for this would probably be catching the exception while reading
leftText
andrightText
and re-reading them asByteString
s if one is thrown. Then it'd possible to simply print whether the binary files differ or not.Much more tricky to fix is the incorrect assumption that derivation files will be encoded according to the current locale: This is not true, in fact derivation are not guaranteed to be properly encoded at all, since Nix strings can contain arbitrary byte sequences. By virtue of
nix-derivation
assuming a derivation may (as an intermediate form) be representable asText
,nix-diff
also has to assume some Unicode-compatible encoding, which won't work in all cases:This is probably not a huge concern for real-world use cases and not necessarily an issue fixable in
nix-diff
, but something to be aware of.