Skip to content

Instantly share code, notes, and snippets.

@danbst
Created April 20, 2018 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danbst/1b7d6b97401ebdc34df0a03b8f3a1424 to your computer and use it in GitHub Desktop.
Save danbst/1b7d6b97401ebdc34df0a03b8f3a1424 to your computer and use it in GitHub Desktop.
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p gitMinimal nix-prefetch-git jq
set -e
project="$1"
branch="${2:-master}"
owner=$(echo "$project" | cut -d/ -f1)
repo=$(echo "$project" | cut -d/ -f2)
rev=$(git ls-remote "git://github.com/$project.git" "$branch" | head -n1 | awk '{print $1}')
rev=${rev:-$2}
hash=$(nix-prefetch-url "https://github.com/$project/archive/$rev.tar.gz")
function show() {
cat << EOF
{
"owner": "$owner",
"repo": "$repo",
"rev": "$rev",
"sha256": "$hash"
}
EOF
}
show
hash=$(nix-prefetch-git "github.com/$project.git" --rev "$rev" --quiet | jq -r .sha256)
show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment