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?

6 Likes

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

5 Likes

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.

1 Like

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.

3 Likes

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

1 Like