nuclei: 3.3.5 -> 3.3.6 (#358083)
[NixPkgs.git] / maintainers / scripts / haskell / update-stackage.sh
blob2430edbdd4204b55d2aac3333b733ac1e154a192
1 #! /usr/bin/env nix-shell
2 #! nix-shell -i bash -p nix curl jq git gnused gnugrep -I nixpkgs=.
3 # shellcheck shell=bash
5 set -eu -o pipefail
7 # Stackage solver to use, LTS or Nightly
8 # (should be capitalized like the display name)
9 SOLVER=LTS
10 # Stackage solver verson, if any. Use latest if empty
11 VERSION=
12 TMP_TEMPLATE=update-stackage.XXXXXXX
13 readonly SOLVER
14 readonly VERSION
15 readonly TMP_TEMPLATE
17 toLower() {
18 printf "%s" "$1" | tr '[:upper:]' '[:lower:]'
21 tmpfile=$(mktemp "$TMP_TEMPLATE")
22 tmpfile_new=$(mktemp "$TMP_TEMPLATE")
24 stackage_config="pkgs/development/haskell-modules/configuration-hackage2nix/stackage.yaml"
26 trap 'rm "${tmpfile}" "${tmpfile_new}"' 0
27 touch "$tmpfile" "$tmpfile_new" # Creating files here so that trap creates no errors.
29 curl -L -s "https://stackage.org/$(toLower "$SOLVER")${VERSION:+-$VERSION}/cabal.config" >"$tmpfile"
30 old_version=$(grep '^# Stackage' $stackage_config | sed -e 's/.\+ \([A-Za-z]\+ [0-9.-]\+\)$/\1/g')
31 version="$SOLVER $(sed -rn "s/^--.*http:..(www.)?stackage.org.snapshot.$(toLower "$SOLVER")-//p" "$tmpfile")"
33 if [[ "$old_version" == "$version" ]]; then
34 echo "No new stackage version"
35 exit 0 # Nothing to do
38 echo "Updating Stackage from $old_version to $version."
40 # Create a simple yaml version of the file.
41 sed -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}"
51 cat > $stackage_config << EOF
52 # Stackage $version
53 # This file is auto-generated by
54 # maintainers/scripts/haskell/update-stackage.sh
55 default-package-overrides:
56 EOF
58 # Drop restrictions on some tools where we always want the latest version.
59 sed -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.
81 if [[ "${1:-}" == "--do-commit" ]]; then
82 git add $stackage_config
83 git commit -F - << EOF
84 haskellPackages: stackage $old_version -> $version
86 This commit has been generated by maintainers/scripts/haskell/update-stackage.sh
87 EOF