Generate nix code to fetch package from url


#1

I am trying to generate nix code to fetch programs from different types of url:
git://github.com/antirez/lua-cmsgpack.git or http://program.com/0.4.tar.gz

Iam looking for a program that would convert the input git://github.com/antirez/lua-cmsgpack.git into

builtins.fetchGit {
  "url": "git://github.com/antirez/lua-cmsgpack.git",
  "rev": "57b1f90cf6cec46450e87289ed5a676165d31071",
  "date": "2018-06-14T11:56:56+02:00",
  "sha256": "0yiwl4p1zh9qid3ksc4n9fv5bwaa9vjb0vgwnkars204xmxdj8fj",
  "fetchSubmodules": false
}

and http://program.com/0.4.tar.gz intofetchurl { url = http://program.com/0.4.tar.gz; sha256 = ... }

In the first example, I can run nix-prefetch-git --quiet git://github.com/antirez/lua-cmsgpack.git but it still means that I detected in advance it was a git url. I am looking for a more holistic program that detects the protocol / domain and depending on those generate the appropriate fetch instructions like fetchFromGithub or fetchFromGitlab or fetchurl.

Is there anything like it available ?


#2

like why nix-prefetch-url doesn’t have a --quiet option that outputs the json as nix-prefetch-git does ?


#3

I wrote nix-update-source to deal with similar issues - I want to generate some nix code (or JSON code which can be imported from nix) based on some inputs, but let it generate the digest for me. So far I’ve only added support for git / github types, but it should be reasonably straightforward to add a plain fetchurl type.

If you’re interested in contributing, a url handler shouldn’t bet much more than 10 lines, you could use the github handler for reference: https://github.com/timbertson/nix-update-source/blob/bcbc0182428ade7fbb814182fc240781a6610ee8/bin/nix-update-source#L49