···11#! /usr/bin/env nix-shell
22#! nix-shell -i bash -p coreutils haskellPackages.cabal2nix-unstable git nix -I nixpkgs=.
3344-# This script is used to regenerate nixpkgs' Haskell package set, using the
55-# tool hackage2nix from the nixos/cabal2nix repo. hackage2nix looks at the
66-# config files in pkgs/development/haskell-modules/configuration-hackage2nix
77-# and generates a Nix expression for package version specified there, using the
88-# Cabal files from the Hackage database (available under all-cabal-hashes) and
99-# its companion tool cabal2nix.
1010-#
1111-# Related scripts are update-hackage.sh, for updating the snapshot of the
1212-# Hackage database used by hackage2nix, and update-cabal2nix-unstable.sh,
1313-# for updating the version of hackage2nix used to perform this task.
1414-#
1515-# Note that this script doesn't gcroot anything, so it may be broken by an
1616-# unfortunately timed nix-store --gc.
44+set -euo pipefail
1751818-set -euo pipefail
66+self=$0
77+88+print_help () {
99+cat <<END_HELP
1010+Usage: $self [options]
1111+1212+Options:
1313+ --do-commit Commit changes to this file.
1414+ -f | --fast Do not update the transitive-broken.yaml file.
1515+ -h | --help Show this help.
1616+1717+This script is used to regenerate nixpkgs' Haskell package set, using the
1818+tool hackage2nix from the nixos/cabal2nix repo. hackage2nix looks at the
1919+config files in pkgs/development/haskell-modules/configuration-hackage2nix
2020+and generates a Nix expression for package version specified there, using the
2121+Cabal files from the Hackage database (available under all-cabal-hashes) and
2222+its companion tool cabal2nix.
2323+2424+Unless --fast is used, it will then use the generated nix expression by
2525+running regenerate-transitive-broken-packages.sh which updates the transitive-broken.yaml
2626+file. Then it re-runs hackage2nix.
2727+2828+Related scripts are update-hackage.sh, for updating the snapshot of the
2929+Hackage database used by hackage2nix, and update-cabal2nix-unstable.sh,
3030+for updating the version of hackage2nix used to perform this task.
3131+3232+Note that this script doesn't gcroot anything, so it may be broken by an
3333+unfortunately timed nix-store --gc.
3434+3535+END_HELP
3636+}
3737+3838+DO_COMMIT=0
3939+REGENERATE_TRANSITIVE=1
4040+4141+options=$(getopt -o "fh" -l "help,fast,do-commit" -- "$@")
4242+4343+eval set -- "$options"
4444+4545+while true; do
4646+ case "$1" in
4747+ --do-commit)
4848+ DO_COMMIT=1
4949+ ;;
5050+ -f|--fast)
5151+ REGENERATE_TRANSITIVE=0
5252+ ;;
5353+ -h|--help)
5454+ print_help
5555+ exit 0
5656+ ;;
5757+ --)
5858+ break;;
5959+ *)
6060+ print_help
6161+ exit 1
6262+ ;;
6363+ esac
6464+ shift
6565+done
19662067HACKAGE2NIX="${HACKAGE2NIX:-hackage2nix}"
2168···25722673config_dir=pkgs/development/haskell-modules/configuration-hackage2nix
27742828-echo "Obtaining Hackage data"
2929-extraction_derivation='with import ./. {}; runCommandLocal "unpacked-cabal-hashes" { } "tar xf ${all-cabal-hashes} --strip-components=1 --one-top-level=$out"'
3030-unpacked_hackage="$(nix-build -E "$extraction_derivation" --no-out-link)"
3131-3232-echo "Generating compiler configuration"
3333-compiler_config="$(nix-build -A haskellPackages.cabal2nix-unstable.compilerConfig --no-out-link)"
3434-3535-echo "Starting hackage2nix to regenerate pkgs/development/haskell-modules/hackage-packages.nix ..."
7575+run_hackage2nix() {
3676"$HACKAGE2NIX" \
3777 --hackage "$unpacked_hackage" \
3878 --preferred-versions <(for n in "$unpacked_hackage"/*/preferred-versions; do cat "$n"; echo; done) \
···4282 --config "$config_dir/stackage.yaml" \
4383 --config "$config_dir/broken.yaml" \
4484 --config "$config_dir/transitive-broken.yaml"
8585+}
45864646-if [[ "${1:-}" == "--do-commit" ]]; then
8787+echo "Obtaining Hackage data …"
8888+extraction_derivation='with import ./. {}; runCommandLocal "unpacked-cabal-hashes" { } "tar xf ${all-cabal-hashes} --strip-components=1 --one-top-level=$out"'
8989+unpacked_hackage="$(nix-build -E "$extraction_derivation" --no-out-link)"
9090+9191+echo "Generating compiler configuration …"
9292+compiler_config="$(nix-build -A haskellPackages.cabal2nix-unstable.compilerConfig --no-out-link)"
9393+9494+echo "Running hackage2nix to regenerate pkgs/development/haskell-modules/hackage-packages.nix …"
9595+run_hackage2nix
9696+9797+if [[ "$REGENERATE_TRANSITIVE" -eq 1 ]]; then
9898+9999+echo "Regenerating transitive-broken.yaml … (pass --fast to $self to skip this step)"
100100+101101+maintainers/scripts/haskell/regenerate-transitive-broken-packages.sh
102102+103103+echo "Running hackage2nix again to reflect changes in transitive-broken.yaml …"
104104+105105+run_hackage2nix
106106+107107+fi
108108+109109+110110+if [[ "$DO_COMMIT" -eq 1 ]]; then
111111+git add pkgs/development/haskell-modules/configuration-hackage2nix/transitive-broken.yaml
47112git add pkgs/development/haskell-modules/hackage-packages.nix
48113git commit -F - << EOF
49114haskellPackages: regenerate package set based on current config