Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1#! /usr/bin/env nix-shell 2#! nix-shell -i bash -p nix curl jq nix-prefetch-github git gnused gnugrep -I nixpkgs=. 3# shellcheck shell=bash 4 5set -eu -o pipefail 6 7# Stackage solver to use, LTS or Nightly 8# (should be capitalized like the display name) 9SOLVER=LTS 10TMP_TEMPLATE=update-stackage.XXXXXXX 11readonly SOLVER 12readonly TMP_TEMPLATE 13 14toLower() { 15 printf "%s" "$1" | tr '[:upper:]' '[:lower:]' 16} 17 18tmpfile=$(mktemp "$TMP_TEMPLATE") 19tmpfile_new=$(mktemp "$TMP_TEMPLATE") 20 21stackage_config="pkgs/development/haskell-modules/configuration-hackage2nix/stackage.yaml" 22 23trap 'rm "${tmpfile}" "${tmpfile_new}"' 0 24touch "$tmpfile" "$tmpfile_new" # Creating files here so that trap creates no errors. 25 26curl -L -s "https://stackage.org/$(toLower "$SOLVER")/cabal.config" >"$tmpfile" 27old_version=$(grep '^# Stackage' $stackage_config | sed -e 's/.\+ \([A-Za-z]\+ [0-9.-]\+\)$/\1/g') 28version="$SOLVER $(sed -rn "s/^--.*http:..(www.)?stackage.org.snapshot.$(toLower "$SOLVER")-//p" "$tmpfile")" 29 30if [[ "$old_version" == "$version" ]]; then 31 echo "No new stackage version" 32 exit 0 # Nothing to do 33fi 34 35echo "Updating Stackage from $old_version to $version." 36 37# Create a simple yaml version of the file. 38sed -r \ 39 -e '/^--/d' \ 40 -e 's|^constraints:||' \ 41 -e 's|^ +| - |' \ 42 -e 's|,$||' \ 43 -e '/installed$/d' \ 44 -e '/^$/d' \ 45 < "${tmpfile}" | sort --ignore-case >"${tmpfile_new}" 46 47cat > $stackage_config << EOF 48# Stackage $version 49# This file is auto-generated by 50# maintainers/scripts/haskell/update-stackage.sh 51default-package-overrides: 52EOF 53 54# Drop restrictions on some tools where we always want the latest version. 55sed -r \ 56 -e '/ cabal2nix /d' \ 57 -e '/ distribution-nixpkgs /d' \ 58 -e '/ jailbreak-cabal /d' \ 59 -e '/ language-nix /d' \ 60 -e '/ cabal-install /d' \ 61 < "${tmpfile_new}" >> $stackage_config 62 63if [[ "${1:-}" == "--do-commit" ]]; then 64git add $stackage_config 65git commit -F - << EOF 66haskellPackages: stackage $old_version -> $version 67 68This commit has been generated by maintainers/scripts/haskell/update-stackage.sh 69EOF 70fi