summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2019-08-14 13:07:21 +0200
committertv <tv@krebsco.de>2019-08-14 13:41:46 +0200
commitaac6c242e8da2d630da4b712e20622db604da75a (patch)
tree1ee00f45b9c7c3f8faba7e8761d6cc5d5a0c3cdc /krebs/5pkgs
parentd81e1101ac47010415f2848d22327cc5c807ef0f (diff)
nix-prefetch-github: init
Diffstat (limited to 'krebs/5pkgs')
-rw-r--r--krebs/5pkgs/simple/nix-prefetch-github.nix25
1 files changed, 25 insertions, 0 deletions
diff --git a/krebs/5pkgs/simple/nix-prefetch-github.nix b/krebs/5pkgs/simple/nix-prefetch-github.nix
new file mode 100644
index 000000000..14096c33f
--- /dev/null
+++ b/krebs/5pkgs/simple/nix-prefetch-github.nix
@@ -0,0 +1,25 @@
+{ curl, jq, nix, writeDashBin }:
+
+writeDashBin "nix-prefetch-github" ''
+ # usage: nix-prefetch-github OWNER REPO [REF]
+ set -efu
+
+ owner=$1
+ repo=$2
+ ref=''${3-master}
+
+ info_url=https://api.github.com/repos/$owner/$repo/commits/$ref
+ info=$(${curl}/bin/curl -fsS "$info_url")
+ rev=$(printf %s "$info" | ${jq}/bin/jq -r .sha)
+
+ name=$owner-$repo-$ref
+ url=https://github.com/$owner/$repo/tarball/$rev
+ sha256=$(${nix}/bin/nix-prefetch-url --name "$name" --unpack "$url")
+
+ export owner repo rev sha256
+ ${jq}/bin/jq -n '
+ env | {
+ owner, repo, rev, sha256
+ }
+ '
+''