Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For text files it is possible to do it like so:
builtins.hashString "sha256" (builtins.readFile /tmp/a)
but that doesn't work for binary files.
With builtins.hashFile any kind of file can be conveniently hashed.
Fixes: #1835
I added some tests and also tested it manually in the repl:
Also works on binary files:
I'm not sure why my test in
tests/lang/eval-fail-hashfile-missing.nix
isn't working. It evaluates but it shouldn't. In the repl it doesn't evaluate.This is my first edit in the Nix source so please be kind if I forgot something ;)
By the way: I found it really weird that
EvalState::coerceToPath
andEvalState::forceString
take the same arguments but in a different order. Is that intentional or is that something which we should fix?