1#! /usr/bin/env nix-shell
2#! nix-shell -i bash -p coreutils curl jq gnused haskellPackages.cabal2nix-unstable -I nixpkgs=.
3
4# Updates cabal2nix-unstable to the latest master of the nixos/cabal2nix repository.
5# See regenerate-hackage-packages.sh for details on the purpose of this script.
6
7set -euo pipefail
8
9# fetch current master HEAD from Github
10head_info="$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/NixOS/cabal2nix/branches/master)"
11# extract commit hash
12commit="$(jq -r .commit.sha <<< "$head_info")"
13# extract commit timestamp and convert to date
14date="$(date "--date=$(jq -r .commit.commit.committer.date <<< "$head_info")" +%F)"
15
16# generate nix expression from cabal file, replacing the version with the commit date
17function mkPackage() {
18 output=pkgs/development/haskell-modules/cabal2nix-unstable/$1.nix
19 echo "# This file defines $1-unstable, used by maintainers/scripts/haskell/regenerate-hackage-packages.sh." > "$output"
20 cabal2nix --subpath "$1" "https://github.com/NixOS/cabal2nix/archive/$commit.tar.gz" | sed -Ee 's/version = "(.*)"/version = "\1-unstable-'"$date"'"/' >> "$output"
21 nixfmt "$output"
22}
23
24mkPackage "cabal2nix"
25mkPackage "distribution-nixpkgs"
26mkPackage "hackage-db"
27mkPackage "language-nix"