at master 2.0 kB view raw
1#! /usr/bin/env nix-shell 2#! nix-shell -i bash -p curl jq git gnused -I nixpkgs=. 3# 4# SYNOPSIS 5# 6# Update Hackage index and hashes data exposed via pkgs.all-cabal-hashes. 7# 8# DESCRIPTION 9# 10# Find latest revision of the commercialhaskell/all-cabal-hashes repository's 11# hackage branch and update pkgs/data/misc/hackage/pin.json accordingly. 12# 13# This data is used by hackage2nix to generate hackage-packages.nix. Since 14# hackage2nix uses the latest version of a package unless an explicit 15# constraint is configured, running this script indirectly updates packages 16# (when hackage2nix is executed afterwards). 17# 18# Prints a version difference to stdout if the pin has been updated, nothing 19# otherwise. 20# 21# EXIT STATUS 22# 23# Always exit with zero (even if nothing changed) unless there was an error. 24 25set -euo pipefail 26 27if [[ "${1:-}" == "--do-commit" ]]; then 28 echo "$0: --do-commit is no longer supported. Use update-package-set.sh instead." 29 exit 100 30fi 31 32pin_file=pkgs/data/misc/hackage/pin.json 33current_commit="$(jq -r .commit $pin_file)" 34old_date="$(jq -r .msg $pin_file | sed 's/Update from Hackage at //')" 35git_info="$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/commercialhaskell/all-cabal-hashes/branches/hackage)" 36head_commit="$(echo "$git_info" | jq -r .commit.sha)" 37commit_msg="$(echo "$git_info" | jq -r .commit.commit.message)" 38new_date="$(echo "$commit_msg" | sed 's/Update from Hackage at //')" 39 40if [ "$current_commit" != "$head_commit" ]; then 41 echo "Updating all-cabal-hashes from $old_date to $new_date" >&2 42 url="https://github.com/commercialhaskell/all-cabal-hashes/archive/$head_commit.tar.gz" 43 hash="$(nix-prefetch-url "$url")" 44 jq -n \ 45 --arg commit "$head_commit" \ 46 --arg hash "$hash" \ 47 --arg url "$url" \ 48 --arg commit_msg "$commit_msg" \ 49 '{commit: $commit, url: $url, sha256: $hash, msg: $commit_msg}' \ 50 > $pin_file 51else 52 echo "No new all-cabal-hashes version" >&2 53 exit 0 54fi 55 56echo "$old_date -> $new_date"