1#!/usr/bin/env nix-shell
2#!nix-shell -i bash -p cabal2nix curl jq haskellPackages.cabal2nix-unstable -I nixpkgs=.
3#
4# This script will update the spago derivation to the latest version using
5# cabal2nix.
6#
7# Note that you should always try building spago after updating it here, since
8# some of the overrides in pkgs/development/haskell/configuration-nix.nix may
9# need to be updated/changed.
10
11set -eo pipefail
12
13# This is the directory of this update.sh script.
14script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
15
16# Spago derivation created with cabal2nix.
17spago_derivation_file="${script_dir}/spago.nix"
18
19# This is the current revision of spago in Nixpkgs.
20old_version="$(sed -En 's/.*\bversion = "(.*?)".*/\1/p' "$spago_derivation_file")"
21
22# This is the latest release version of spago on GitHub.
23new_version=$(curl --silent "https://api.github.com/repos/purescript/spago/releases" | jq '.[0].tag_name' --raw-output)
24
25echo "Updating spago from old version $old_version to new version $new_version."
26echo "Running cabal2nix and outputting to ${spago_derivation_file}..."
27
28echo "# This has been automatically generated by the script" > "$spago_derivation_file"
29echo "# ./update.sh. This should not be changed by hand." >> "$spago_derivation_file"
30
31cabal2nix --revision "$new_version" "https://github.com/purescript/spago.git" >> "$spago_derivation_file"
32
33# TODO: This should ideally also automatically update the docsSearchVersion
34# from pkgs/development/haskell/configuration-nix.nix.
35
36echo
37echo "Finished. Make sure you run the following commands to confirm Spago builds correctly:"
38echo ' - `nix build -L -f ./. spago`'
39echo ' - `sudo nix build -L -f ./. spago.passthru.tests --option sandbox relaxed`'