1#! /usr/bin/env nix-shell
2#! nix-shell -i bash -p nix curl jq git gnused -I nixpkgs=.
3
4# See regenerate-hackage-packages.sh for details on the purpose of this script.
5
6set -euo pipefail
7
8pin_file=pkgs/data/misc/hackage/pin.json
9current_commit="$(jq -r .commit $pin_file)"
10old_date="$(jq -r .msg $pin_file | sed 's/Update from Hackage at //')"
11git_info="$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/commercialhaskell/all-cabal-hashes/branches/hackage)"
12head_commit="$(echo "$git_info" | jq -r .commit.sha)"
13commit_msg="$(echo "$git_info" | jq -r .commit.commit.message)"
14new_date="$(echo "$commit_msg" | sed 's/Update from Hackage at //')"
15
16if [ "$current_commit" != "$head_commit" ]; then
17 url="https://github.com/commercialhaskell/all-cabal-hashes/archive/$head_commit.tar.gz"
18 hash="$(nix-prefetch-url "$url")"
19 jq -n \
20 --arg commit "$head_commit" \
21 --arg hash "$hash" \
22 --arg url "$url" \
23 --arg commit_msg "$commit_msg" \
24 '{commit: $commit, url: $url, sha256: $hash, msg: $commit_msg}' \
25 > $pin_file
26fi
27
28if [[ "${1:-}" == "--do-commit" ]]; then
29git add pkgs/data/misc/hackage/pin.json
30git commit -F - << EOF
31all-cabal-hashes: $old_date -> $new_date
32
33This commit has been generated by maintainers/scripts/haskell/update-hackage.sh
34EOF
35fi