1#! /usr/bin/env nix-shell
2#! nix-shell -i bash -p coreutils haskellPackages.cabal2nix-unstable git nix -I nixpkgs=.
3
4# This script is used to regenerate nixpkgs' Haskell package set, using the
5# tool hackage2nix from the nixos/cabal2nix repo. hackage2nix looks at the
6# config files in pkgs/development/haskell-modules/configuration-hackage2nix
7# and generates a Nix expression for package version specified there, using the
8# Cabal files from the Hackage database (available under all-cabal-hashes) and
9# its companion tool cabal2nix.
10#
11# Related scripts are update-hackage.sh, for updating the snapshot of the
12# Hackage database used by hackage2nix, and update-cabal2nix-unstable.sh,
13# for updating the version of hackage2nix used to perform this task.
14
15set -euo pipefail
16
17HACKAGE2NIX="${HACKAGE2NIX:-hackage2nix}"
18
19# To prevent hackage2nix fails because of encoding.
20# See: https://github.com/NixOS/nixpkgs/pull/122023
21export LC_ALL=C.UTF-8
22
23extraction_derivation='with import ./. {}; runCommand "unpacked-cabal-hashes" { } "tar xf ${all-cabal-hashes} --strip-components=1 --one-top-level=$out"'
24unpacked_hackage="$(nix-build -E "$extraction_derivation" --no-out-link)"
25config_dir=pkgs/development/haskell-modules/configuration-hackage2nix
26
27echo "Starting hackage2nix to regenerate pkgs/development/haskell-modules/hackage-packages.nix ..."
28"$HACKAGE2NIX" \
29 --hackage "$unpacked_hackage" \
30 --preferred-versions <(for n in "$unpacked_hackage"/*/preferred-versions; do cat "$n"; echo; done) \
31 --nixpkgs "$PWD" \
32 --config "$config_dir/main.yaml" \
33 --config "$config_dir/stackage.yaml" \
34 --config "$config_dir/broken.yaml" \
35 --config "$config_dir/transitive-broken.yaml"
36
37if [[ "${1:-}" == "--do-commit" ]]; then
38git add pkgs/development/haskell-modules/hackage-packages.nix
39git commit -F - << EOF
40haskellPackages: regenerate package set based on current config
41
42This commit has been generated by maintainers/scripts/haskell/regenerate-hackage-packages.sh
43EOF
44fi
45
46echo "Regeneration of hackage-packages.nix finished."