at 25.11-pre 2.9 kB view raw
1#! /usr/bin/env nix-shell 2#! nix-shell -i bash -p nix curl jq 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 10# Stackage solver verson, if any. Use latest if empty 11VERSION= 12TMP_TEMPLATE=update-stackage.XXXXXXX 13readonly SOLVER 14readonly VERSION 15readonly TMP_TEMPLATE 16 17toLower() { 18 printf "%s" "$1" | tr '[:upper:]' '[:lower:]' 19} 20 21tmpfile=$(mktemp "$TMP_TEMPLATE") 22tmpfile_new=$(mktemp "$TMP_TEMPLATE") 23 24stackage_config="pkgs/development/haskell-modules/configuration-hackage2nix/stackage.yaml" 25 26trap 'rm "${tmpfile}" "${tmpfile_new}"' 0 27touch "$tmpfile" "$tmpfile_new" # Creating files here so that trap creates no errors. 28 29curl -L -s "https://stackage.org/$(toLower "$SOLVER")${VERSION:+-$VERSION}/cabal.config" >"$tmpfile" 30old_version=$(grep '^# Stackage' $stackage_config | sed -e 's/.\+ \([A-Za-z]\+ [0-9.-]\+\)$/\1/g') 31version="$SOLVER $(sed -rn "s/^--.*http:..(www.)?stackage.org.snapshot.$(toLower "$SOLVER")-//p" "$tmpfile")" 32 33if [[ "$old_version" == "$version" ]]; then 34 echo "No new stackage version" 35 exit 0 # Nothing to do 36fi 37 38echo "Updating Stackage from $old_version to $version." 39 40# Create a simple yaml version of the file. 41sed -r \ 42 -e '/^--/d' \ 43 -e 's|^constraints:||' \ 44 -e 's|^ +| - |' \ 45 -e 's|,$||' \ 46 -e '/^with-compiler:/d' \ 47 -e '/installed$/d' \ 48 -e '/^$/d' \ 49 < "${tmpfile}" | sort --ignore-case >"${tmpfile_new}" 50 51cat > $stackage_config << EOF 52# Stackage $version 53# This file is auto-generated by 54# maintainers/scripts/haskell/update-stackage.sh 55default-package-overrides: 56EOF 57 58# Drop restrictions on some tools where we always want the latest version. 59sed -r \ 60 -e '/ cabal2nix /d' \ 61 -e '/ distribution-nixpkgs /d' \ 62 -e '/ jailbreak-cabal /d' \ 63 -e '/ language-nix /d' \ 64 -e '/ hackage-db /d' \ 65 -e '/ cabal-install /d' \ 66 -e '/ cabal-install-solver /d' \ 67 -e '/ lsp /d' \ 68 -e '/ lsp-types /d' \ 69 -e '/ lsp-test /d' \ 70 -e '/ hie-bios /d' \ 71 -e '/ ShellCheck /d' \ 72 -e '/ Agda /d' \ 73 -e '/ stack /d' \ 74 < "${tmpfile_new}" >> $stackage_config 75# Explanations: 76# cabal2nix, distribution-nixpkgs, jailbreak-cabal, language-nix: These are our packages and we know what we are doing. 77# lsp, lsp-types, lsp-test, hie-bios: These are tightly coupled to hls which is not in stackage. They have no rdeps in stackage. 78# ShellCheck: latest version of command-line dev tool. 79# Agda: The Agda community is fast-moving; we strive to always include the newest versions of Agda and the Agda packages in nixpkgs. 80 81if [[ "${1:-}" == "--do-commit" ]]; then 82git add $stackage_config 83git commit -F - << EOF 84haskellPackages: stackage $old_version -> $version 85 86This commit has been generated by maintainers/scripts/haskell/update-stackage.sh 87EOF 88fi