From f3f84855e8fa9b190a14f49c5c6db9e816e72c10 Mon Sep 17 00:00:00 2001 From: hyperfekt Date: Mon, 4 May 2020 01:01:57 +0200 Subject: maintainers/scripts/haskell/regenerate-hackage-packages.sh: init Introduces a script that can be used to update the Nix expressions for the Haskell package set. In service of that, also - introduces cabal2nix-latest, which pins the hackage2nix version used - changes all-cabal-hashes to use fetchFromGitHub - adds update-hackage.sh & update-cabal2nix-latest.sh & update-stackage.sh maintainer scripts --- .../scripts/haskell/regenerate-hackage-packages.sh | 20 +++++++++ .../scripts/haskell/update-cabal2nix-latest.sh | 17 ++++++++ maintainers/scripts/haskell/update-hackage.sh | 21 +++++++++ maintainers/scripts/haskell/update-stackage.sh | 51 ++++++++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100755 maintainers/scripts/haskell/regenerate-hackage-packages.sh create mode 100755 maintainers/scripts/haskell/update-cabal2nix-latest.sh create mode 100755 maintainers/scripts/haskell/update-hackage.sh create mode 100755 maintainers/scripts/haskell/update-stackage.sh (limited to 'maintainers') diff --git a/maintainers/scripts/haskell/regenerate-hackage-packages.sh b/maintainers/scripts/haskell/regenerate-hackage-packages.sh new file mode 100755 index 0000000000000..79b93f5b7cb1b --- /dev/null +++ b/maintainers/scripts/haskell/regenerate-hackage-packages.sh @@ -0,0 +1,20 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p coreutils haskellPackages.cabal2nix-latest -I nixpkgs=. + +# This script is used to regenerate nixpkgs' Haskell package set, using a tool +# called hackage2nix. hackage2nix looks at +# pkgs/development/haskell-modules/configuration-hackage2nix.yaml and generates +# a Nix expression for package version specified there, using the Cabal files +# from the Hackage database (available under all-cabal-hashes) and its +# companion tool cabal2nix. +# +# Related scripts are update-hackage.sh, for updating the snapshot of the +# Hackage database used by hackage2nix, and update-cabal2nix-latest.sh, +# for updating the version of hackage2nix used to perform this task. + +set -euo pipefail + +extractionDerivation='with import ./. {}; runCommand "unpacked-cabal-hashes" { } "tar xf ${all-cabal-hashes} --strip-components=1 --one-top-level=$out"' +unpacked_hackage="$(nix-build -E "$extractionDerivation" --no-out-link)" + +hackage2nix --hackage "$unpacked_hackage" --preferred-versions <(for n in "$unpacked_hackage"/*/preferred-versions; do cat "$n"; echo; done) --nixpkgs "$PWD" --config pkgs/development/haskell-modules/configuration-hackage2nix.yaml diff --git a/maintainers/scripts/haskell/update-cabal2nix-latest.sh b/maintainers/scripts/haskell/update-cabal2nix-latest.sh new file mode 100755 index 0000000000000..1f22bb1792f87 --- /dev/null +++ b/maintainers/scripts/haskell/update-cabal2nix-latest.sh @@ -0,0 +1,17 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p coreutils curl jq gnused haskellPackages.cabal2nix-latest -I nixpkgs=. + +# Updates cabal2nix-latest to the latest master of the nixos/cabal2nix repository. +# See regenerate-hackage-packages.sh for details on the purpose of this script. + +set -euo pipefail + +# fetch current master HEAD from Github +head_info="$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/NixOS/cabal2nix/branches/master)" +# extract commit hash +commit="$(jq -r .commit.sha <<< "$head_info")" +# extract commit timestamp and convert to date +date="$(date "--date=$(jq -r .commit.commit.committer.date <<< "$head_info")" +%F)" +# generate nix expression from cabal file, replacing the version with the commit date +echo '# This file defines cabal2nix-latest, used by maintainers/scripts/haskell/regenerate-hackage-packages.sh.' > pkgs/development/haskell-modules/cabal2nix-latest.nix +cabal2nix "https://github.com/NixOS/cabal2nix/archive/$commit.tar.gz" | sed -e 's/version = ".*"/version = "'"$date"'"/' >> pkgs/development/haskell-modules/cabal2nix-latest.nix diff --git a/maintainers/scripts/haskell/update-hackage.sh b/maintainers/scripts/haskell/update-hackage.sh new file mode 100755 index 0000000000000..de4b3bc0448ec --- /dev/null +++ b/maintainers/scripts/haskell/update-hackage.sh @@ -0,0 +1,21 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p nix curl jq nix-prefetch-github -I nixpkgs=. + +# See regenerate-hackage-packages.sh for details on the purpose of this script. + +set -euo pipefail + +pin_file=pkgs/data/misc/hackage/pin.json +current_commit="$(jq -r .commit $pin_file)" +head_commit="$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/commercialhaskell/all-cabal-hashes/branches/hackage | jq -r .commit.sha)" + +if [ "$current_commit" != "$head_commit" ]; then + url="https://github.com/commercialhaskell/all-cabal-hashes/archive/$head_commit.tar.gz" + hash="$(nix-prefetch-url "$url")" + jq -n \ + --arg commit "$head_commit" \ + --arg hash "$hash" \ + --arg url "$url" \ + '{commit: $commit, url: $url, sha256: $hash}' \ + > $pin_file +fi diff --git a/maintainers/scripts/haskell/update-stackage.sh b/maintainers/scripts/haskell/update-stackage.sh new file mode 100755 index 0000000000000..0e08c02bc2c6a --- /dev/null +++ b/maintainers/scripts/haskell/update-stackage.sh @@ -0,0 +1,51 @@ +#! /usr/bin/env bash + +set -eu -o pipefail + +tmpfile=$(mktemp "update-stackage.XXXXXXX") +# shellcheck disable=SC2064 +trap "rm ${tmpfile} ${tmpfile}.new" 0 + +curl -L -s "https://stackage.org/nightly/cabal.config" >"$tmpfile" +version=$(sed -rn "s/^--.*http:..(www.)?stackage.org.snapshot.nightly-//p" "$tmpfile") + +# Create a simple yaml version of the file. +sed -r \ + -e '/^--/d' \ + -e 's|^constraints:||' \ + -e 's|^ +| - |' \ + -e 's|,$||' \ + -e '/installed$/d' \ + -e '/^$/d' \ + < "${tmpfile}" | sort --ignore-case >"${tmpfile}.new" + +# Drop restrictions on some tools where we always want the latest version. +sed -r \ + -e '/ cabal-install /d' \ + -e '/ cabal2nix /d' \ + -e '/ cabal2spec /d' \ + -e '/ distribution-nixpkgs /d' \ + -e '/ git-annex /d' \ + -e '/ hindent /d' \ + -e '/ hledger/d' \ + -e '/ hlint /d' \ + -e '/ hoogle /d' \ + -e '/ hopenssl /d' \ + -e '/ jailbreak-cabal /d' \ + -e '/ json-autotype/d' \ + -e '/ language-nix /d' \ + -e '/ shake /d' \ + -e '/ ShellCheck /d' \ + -e '/ stack /d' \ + -e '/ weeder /d' \ + < "${tmpfile}.new" > "${tmpfile}" + +# Drop the previous configuration ... +# shellcheck disable=SC1004 +sed -e '/ # Stackage Nightly/,/^$/c \TODO\ +' -i pkgs/development/haskell-modules/configuration-hackage2nix.yaml + +# ... and replace it with the new one. +sed -e "/TODO/r $tmpfile" \ + -e "s/TODO/ # Stackage Nightly $version/" \ + -i pkgs/development/haskell-modules/configuration-hackage2nix.yaml -- cgit 1.4.1