Nix-prefetch integration for vim?

I found this emacs helper to update source hashes:

Anyone knows if is there something similar for vim?

just exec it out?

! nix-prefetch-url <url>

sure, I can do that, but I was looking for something more advanced, like finding what url needs to be fetched, based on my current buffer, and update automatically the hash in the file

this is probably more involved than you would think, most url’s are parameterized with version, and most fetch-helpers like fetchFromGithub abstract over the underlying url

try this

function! NixPrefetchUrlSha()
  execute ':normal F"lyt"'
  let l:reg = getreg('"')
  normal! /sha256
  execute ':normal nf"ldt"'
  let l:cmd = '! /run/current-system/sw/bin/nix-prefetch-url ' . '"' . l:reg . '" 2>/dev/null | tail -1 | tr -d "\n"'
  let l:sha = system(l:cmd) | redraw!
  execute ":normal i" . l:sha
noremap <Leader>npus :call NixPrefetchUrlSha()<CR> " Nix Prefetch Url Sha

if you position your cursor inside the “url” string, that function will soak it up, run nix-prefetch-url to compute the SHA (and download the thing), before jumping into the sha256 = “” and inserting that computed sha into that string.

This of course won’t work, as @jonringer mentioned if the URL contains a ${version}

thanks, more or less works, I get a E486: Pattern not found: \<register\> error, but the new hash is fetched. Another possibility would be nix-prefetch-url "<nixpkgs>" -A $pkg.src , that way the ${version} works.
I think is a good start, I’ll try to take a look to it when I have more time

If you get it to work the way you want, post it back.
I would be keen

sure, I don’t know if I will be able to improve it, but if I can I’ll post it