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 '/^with-compiler:/d' \ 44 -e '/installed$/d' \ 45 -e '/^$/d' \ 46 < "${tmpfile}" | sort --ignore-case >"${tmpfile_new}" 47 48cat > $stackage_config << EOF 49# Stackage $version 50# This file is auto-generated by 51# maintainers/scripts/haskell/update-stackage.sh 52default-package-overrides: 53EOF 54 55# Drop restrictions on some tools where we always want the latest version. 56sed -r \ 57 -e '/ cabal2nix /d' \ 58 -e '/ distribution-nixpkgs /d' \ 59 -e '/ jailbreak-cabal /d' \ 60 -e '/ language-nix /d' \ 61 -e '/ hackage-db /d' \ 62 -e '/ cabal-install /d' \ 63 -e '/ lsp /d' \ 64 -e '/ lsp-types /d' \ 65 -e '/ lsp-test /d' \ 66 -e '/ hie-bios /d' \ 67 -e '/ ShellCheck /d' \ 68 -e '/ Agda /d' \ 69 < "${tmpfile_new}" >> $stackage_config 70# Explanations: 71# cabal2nix, distribution-nixpkgs, jailbreak-cabal, language-nix: These are our packages and we know what we are doing. 72# lsp, lsp-types, lsp-test, hie-bios: These are tightly coupled to hls which is not in stackage. They have no rdeps in stackage. 73# ShellCheck: latest version of command-line dev tool. 74# Agda: The Agda community is fast-moving; we strive to always include the newest versions of Agda and the Agda packages in nixpkgs. 75 76if [[ "${1:-}" == "--do-commit" ]]; then 77git add $stackage_config 78git commit -F - << EOF 79haskellPackages: stackage $old_version -> $version 80 81This commit has been generated by maintainers/scripts/haskell/update-stackage.sh 82EOF 83fi