Why does `nix-prefetch-url` not return hashes in SRI format?

Seems like SRI is the preferred format. Is there a reason that nix-prefetch-url doesn’t just output in that format?


I guess for backwards compatability, try nix store prefetch-file


Interesting, I didn’t know about nix store prefetch-file. I feel like the nix-prefetch-url docs should link to that.

It’s kind of annoying that it doesn’t just print out the SRI hash to stdout. Having to pipe things into jq is annoying bc (a) it requires another tool, (b) requires running it in a shell to use a pipe.

you could also do something like:

prefetch-sri() {
    nix-prefetch-url "$1" | xargs nix hash to-sri --type sha256

Ultimately though, nix will gladly accept any valid sha256 encoding, so it’s more of a consistency issue than a correctness issue.


Absolutely! I’m mostly quibbling over UX here, esp. in relation to writing auto-update scripts. Not an implementation bug AFAIU.

1 Like