diff --git a/doc/languages-frameworks/haskell.section.md b/doc/languages-frameworks/haskell.section.md index cba4d0561b074..3abe5ac03dbfd 100644 --- a/doc/languages-frameworks/haskell.section.md +++ b/doc/languages-frameworks/haskell.section.md @@ -1060,8 +1060,11 @@ by hand, but rather autogenerated by [`hackage2nix`](https://github.com/NixOS/ca which by default uses the [`configuration-hackage2nix.yaml`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/haskell-modules/configuration-hackage2nix.yaml) file to generate all the derivations. -To modify the contents `configuration-hackage2nix.yaml`, follow the -instructions on [`hackage2nix`](https://github.com/NixOS/cabal2nix/tree/master/hackage2nix). +To regenerate [`hackage-packages.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/haskell-modules/hackage-packages.nix) +after making changes to the [`configuration-hackage2nix.yaml`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/haskell-modules/configuration-hackage2nix.yaml) +file or updating the snapshot of the Hackage database with the [`update-hackage.sh`](https://github.com/NixOS/nixpkgs/blob/master/maintainers/scripts/update-hackage.sh) +maintainer script, run the [`regenerate-hackage-packages.sh`](https://github.com/NixOS/nixpkgs/blob/master/maintainers/scripts/regenerate-hackage-packages.sh) +maintainer script. ## Other resources diff --git a/maintainers/scripts/regenerate-hackage-packages.sh b/maintainers/scripts/regenerate-hackage-packages.sh new file mode 100755 index 0000000000000..467c815121e44 --- /dev/null +++ b/maintainers/scripts/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 + +# fetch and unpack hackage hashes +unpacked_hackage="$(nix-build . -A all-cabal-hashes --no-out-link)" +# run hackage2nix, the one from the argument if given +eval ${1:-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/update-cabal2nix-latest.sh b/maintainers/scripts/update-cabal2nix-latest.sh new file mode 100755 index 0000000000000..2adee8dc6e262 --- /dev/null +++ b/maintainers/scripts/update-cabal2nix-latest.sh @@ -0,0 +1,17 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p coreutils curl jq gnused cabal2nix -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/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/update-hackage.sh b/maintainers/scripts/update-hackage.sh new file mode 100755 index 0000000000000..cb5c352eade53 --- /dev/null +++ b/maintainers/scripts/update-hackage.sh @@ -0,0 +1,12 @@ +#! /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 + +current_commit="$(nix-instantiate --eval . -A all-cabal-hashes.commit)" +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 + nix-prefetch-github commercialhaskell all-cabal-hashes --rev "$head_commit" > pkgs/data/misc/hackage/pin.json +fi diff --git a/pkgs/data/misc/hackage/default.nix b/pkgs/data/misc/hackage/default.nix index 73429770b295a..45132deb49010 100644 --- a/pkgs/data/misc/hackage/default.nix +++ b/pkgs/data/misc/hackage/default.nix @@ -1,6 +1,6 @@ -{ fetchurl }: - -fetchurl { - url = "https://github.com/commercialhaskell/all-cabal-hashes/archive/e8df5568f80e6230e29c2381e842db35fe11cd71.tar.gz"; - sha256 = "1fz4iax88pmlqpb4zp3l6mb6bmkzzha0q6mm3xasabh5yl83dbhy"; -} +# Hackage database snapshot, used by maintainers/scripts/regenerate-hackage-packages.sh +{ fetchFromGitHub }: +let + pin = builtins.fromJSON (builtins.readFile ./pin.json); +in + fetchFromGitHub (pin // { passthru.commit = pin.rev; }) diff --git a/pkgs/data/misc/hackage/pin.json b/pkgs/data/misc/hackage/pin.json new file mode 100644 index 0000000000000..fd72621995bea --- /dev/null +++ b/pkgs/data/misc/hackage/pin.json @@ -0,0 +1,6 @@ +{ + "owner": "commercialhaskell", + "repo": "all-cabal-hashes", + "rev": "5f32599b70a90c90b5660de1db3195e16001cec9", + "sha256": "0xa7yfz4jqffdn9rrrpbcm3nlbw2p07gqdglz4yyys8q5nfvld69" +} \ No newline at end of file diff --git a/pkgs/development/haskell-modules/cabal2nix-latest.nix b/pkgs/development/haskell-modules/cabal2nix-latest.nix new file mode 100644 index 0000000000000..568899090a91a --- /dev/null +++ b/pkgs/development/haskell-modules/cabal2nix-latest.nix @@ -0,0 +1,40 @@ +# This file defines cabal2nix-latest, used by maintainers/scripts/regenerate-hackage-packages.sh. +{ mkDerivation, aeson, ansi-wl-pprint, base, bytestring, Cabal +, containers, deepseq, directory, distribution-nixpkgs, fetchzip +, filepath, hackage-db, hopenssl, hpack, language-nix, lens +, monad-par, monad-par-extras, mtl, optparse-applicative, pretty +, process, split, stdenv, tasty, tasty-golden, text, time +, transformers, yaml +}: +mkDerivation { + pname = "cabal2nix"; + version = "2020-05-05"; + src = fetchzip { + url = "https://github.com/NixOS/cabal2nix/archive/b7c82dbe6d2bb571c92771385bdee6451b087b0f.tar.gz"; + sha256 = "0gxzb368w8w7kg9y0imzr0bzr8qnvhblm9sz326p8yff26xbk9h5"; + }; + isLibrary = true; + isExecutable = true; + libraryHaskellDepends = [ + aeson ansi-wl-pprint base bytestring Cabal containers deepseq + directory distribution-nixpkgs filepath hackage-db hopenssl hpack + language-nix lens optparse-applicative pretty process split text + time transformers yaml + ]; + executableHaskellDepends = [ + aeson base bytestring Cabal containers directory + distribution-nixpkgs filepath hopenssl language-nix lens monad-par + monad-par-extras mtl optparse-applicative pretty + ]; + testHaskellDepends = [ + base Cabal containers directory filepath language-nix lens pretty + process tasty tasty-golden + ]; + preCheck = '' + export PATH="$PWD/dist/build/cabal2nix:$PATH" + export HOME="$TMPDIR/home" + ''; + homepage = "https://github.com/nixos/cabal2nix#readme"; + description = "Convert Cabal files into Nix build instructions"; + license = stdenv.lib.licenses.bsd3; +} diff --git a/pkgs/development/haskell-modules/non-hackage-packages.nix b/pkgs/development/haskell-modules/non-hackage-packages.nix index 9a2ff6f4a2adf..aaa406ea14303 100644 --- a/pkgs/development/haskell-modules/non-hackage-packages.nix +++ b/pkgs/development/haskell-modules/non-hackage-packages.nix @@ -7,6 +7,10 @@ # files. self: super: { + # Used by maintainers/scripts/regenerate-hackage-packages.sh, and generated + # from the latest master instead of the current version on Hackage. + cabal2nix-latest = self.callPackage ./cabal2nix-latest.nix { }; + multi-ghc-travis = throw ("haskellPackages.multi-ghc-travis has been renamed" + " to haskell-ci, which is now on hackage");