2021-05-05 21:38:46 +01:00
|
|
|
#! /usr/bin/env nix-shell
|
|
|
|
#! nix-shell -i bash -p nix curl jq nix-prefetch-github git gnused gnugrep -I nixpkgs=.
|
2022-03-20 10:05:56 +00:00
|
|
|
# shellcheck shell=bash
|
2020-05-04 00:01:57 +01:00
|
|
|
|
|
|
|
set -eu -o pipefail
|
|
|
|
|
2022-03-20 09:58:00 +00:00
|
|
|
# Stackage solver to use, LTS or Nightly
|
|
|
|
# (should be capitalized like the display name)
|
|
|
|
SOLVER=Nightly
|
2022-03-20 10:08:20 +00:00
|
|
|
TMP_TEMPLATE=update-stackage.XXXXXXX
|
2022-03-20 09:58:00 +00:00
|
|
|
readonly SOLVER
|
2022-03-20 10:08:20 +00:00
|
|
|
readonly TMP_TEMPLATE
|
2022-03-20 09:58:00 +00:00
|
|
|
|
|
|
|
toLower() {
|
|
|
|
printf "%s" "$1" | tr '[:upper:]' '[:lower:]'
|
|
|
|
}
|
|
|
|
|
2022-03-20 10:08:20 +00:00
|
|
|
tmpfile=$(mktemp "$TMP_TEMPLATE")
|
|
|
|
tmpfile_new=$(mktemp "$TMP_TEMPLATE")
|
2021-05-04 12:43:44 +01:00
|
|
|
|
2021-05-05 21:38:46 +01:00
|
|
|
stackage_config="pkgs/development/haskell-modules/configuration-hackage2nix/stackage.yaml"
|
2021-05-04 12:43:44 +01:00
|
|
|
|
2022-03-20 10:08:20 +00:00
|
|
|
trap 'rm "${tmpfile}" "${tmpfile_new}"' 0
|
|
|
|
touch "$tmpfile" "$tmpfile_new" # Creating files here so that trap creates no errors.
|
2020-05-04 00:01:57 +01:00
|
|
|
|
2022-03-20 09:58:00 +00:00
|
|
|
curl -L -s "https://stackage.org/$(toLower "$SOLVER")/cabal.config" >"$tmpfile"
|
|
|
|
old_version=$(grep '^# Stackage' $stackage_config | sed -e 's/.\+ \([A-Za-z]\+ [0-9.-]\+\)$/\1/g')
|
|
|
|
version="$SOLVER $(sed -rn "s/^--.*http:..(www.)?stackage.org.snapshot.$(toLower "$SOLVER")-//p" "$tmpfile")"
|
2020-05-04 00:01:57 +01:00
|
|
|
|
2021-05-04 12:43:44 +01:00
|
|
|
if [[ "$old_version" == "$version" ]]; then
|
|
|
|
echo "No new stackage version"
|
|
|
|
exit 0 # Nothing to do
|
|
|
|
fi
|
|
|
|
|
2022-03-20 09:58:00 +00:00
|
|
|
echo "Updating Stackage from $old_version to $version."
|
2021-06-19 13:18:17 +01:00
|
|
|
|
2020-05-04 00:01:57 +01:00
|
|
|
# Create a simple yaml version of the file.
|
|
|
|
sed -r \
|
|
|
|
-e '/^--/d' \
|
|
|
|
-e 's|^constraints:||' \
|
|
|
|
-e 's|^ +| - |' \
|
|
|
|
-e 's|,$||' \
|
|
|
|
-e '/installed$/d' \
|
|
|
|
-e '/^$/d' \
|
2022-03-20 10:08:20 +00:00
|
|
|
< "${tmpfile}" | sort --ignore-case >"${tmpfile_new}"
|
2020-05-04 00:01:57 +01:00
|
|
|
|
2021-05-05 21:38:46 +01:00
|
|
|
cat > $stackage_config << EOF
|
2022-03-20 09:58:00 +00:00
|
|
|
# Stackage $version
|
2021-05-05 21:38:46 +01:00
|
|
|
# This file is auto-generated by
|
|
|
|
# maintainers/scripts/haskell/update-stackage.sh
|
|
|
|
default-package-overrides:
|
|
|
|
EOF
|
|
|
|
|
2020-05-04 00:01:57 +01:00
|
|
|
# Drop restrictions on some tools where we always want the latest version.
|
|
|
|
sed -r \
|
|
|
|
-e '/ cabal2nix /d' \
|
|
|
|
-e '/ distribution-nixpkgs /d' \
|
|
|
|
-e '/ jailbreak-cabal /d' \
|
|
|
|
-e '/ language-nix /d' \
|
2022-02-27 10:47:32 +00:00
|
|
|
-e '/ cabal-install /d' \
|
2022-03-20 10:08:20 +00:00
|
|
|
< "${tmpfile_new}" >> $stackage_config
|
2021-05-03 21:52:32 +01:00
|
|
|
|
|
|
|
if [[ "${1:-}" == "--do-commit" ]]; then
|
2021-05-07 21:37:14 +01:00
|
|
|
git add $stackage_config
|
2021-05-04 12:43:44 +01:00
|
|
|
git commit -F - << EOF
|
2022-03-20 09:58:00 +00:00
|
|
|
haskellPackages: stackage $old_version -> $version
|
2021-05-04 12:43:44 +01:00
|
|
|
|
|
|
|
This commit has been generated by maintainers/scripts/haskell/update-stackage.sh
|
|
|
|
EOF
|
2021-05-03 21:52:32 +01:00
|
|
|
fi
|