From aff01371c15af5bc2abffcb9851a550cdbe58dbb Mon Sep 17 00:00:00 2001 From: "(cdep)illabout" Date: Thu, 26 Aug 2021 10:20:27 +0900 Subject: [PATCH] purescript: add updateScript for automatic updates --- .../purescript/purescript/default.nix | 8 +++- .../compilers/purescript/purescript/update.sh | 43 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100755 pkgs/development/compilers/purescript/purescript/update.sh diff --git a/pkgs/development/compilers/purescript/purescript/default.nix b/pkgs/development/compilers/purescript/purescript/default.nix index 2d444578db54..9b71975f5023 100644 --- a/pkgs/development/compilers/purescript/purescript/default.nix +++ b/pkgs/development/compilers/purescript/purescript/default.nix @@ -20,6 +20,7 @@ in stdenv.mkDerivation rec { pname = "purescript"; version = "0.14.4"; + # These hashes can be updated automatically by running the ./update.sh script. src = if stdenv.isDarwin then @@ -51,8 +52,11 @@ in stdenv.mkDerivation rec { $PURS --bash-completion-script $PURS > $out/share/bash-completion/completions/purs-completion.bash ''; - passthru.tests = { - minimal-module = pkgs.callPackage ./test-minimal-module {}; + passthru = { + updateScript = ./update.sh; + tests = { + minimal-module = pkgs.callPackage ./test-minimal-module {}; + }; }; meta = with lib; { diff --git a/pkgs/development/compilers/purescript/purescript/update.sh b/pkgs/development/compilers/purescript/purescript/update.sh new file mode 100755 index 000000000000..de8787ba4cca --- /dev/null +++ b/pkgs/development/compilers/purescript/purescript/update.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p curl jq -I nixpkgs=. +# +# This script will update the purescript derivation to the latest version. + +set -eo pipefail + +# This is the directory of this update.sh script. +script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +purescript_derivation_file="${script_dir}/default.nix" + +# This is the current revision of PureScript in Nixpkgs. +old_version="$(sed -En 's/.*\bversion = "(.*?)".*/\1/p' "$purescript_derivation_file")" + +# This is the latest release version of PureScript on GitHub. +new_version=$(curl --silent "https://api.github.com/repos/purescript/purescript/releases" | jq '.[0].tag_name' --raw-output | sed -e 's/v//') + +echo "Updating purescript from old version v${old_version} to new version v${new_version}." +echo + +echo "Fetching both old and new release tarballs for Darwin and Linux in order to confirm hashes." +echo +old_linux_version_hash="$(nix-prefetch-url "https://github.com/purescript/purescript/releases/download/v${old_version}/linux64.tar.gz")" +echo "v${old_version} linux tarball hash (current version): $old_linux_version_hash" +new_linux_version_hash="$(nix-prefetch-url "https://github.com/purescript/purescript/releases/download/v${new_version}/linux64.tar.gz")" +echo "v${new_version} linux tarball hash: $new_linux_version_hash" +old_darwin_version_hash="$(nix-prefetch-url "https://github.com/purescript/purescript/releases/download/v${old_version}/macos.tar.gz")" +echo "v${old_version} darwin tarball hash (current version): $old_darwin_version_hash" +new_darwin_version_hash="$(nix-prefetch-url "https://github.com/purescript/purescript/releases/download/v${new_version}/macos.tar.gz")" +echo "v${new_version} darwin tarball hash: $new_darwin_version_hash" +echo + +echo "Replacing version and hashes in ${purescript_derivation_file}." +sed -i -e "s/${old_linux_version_hash}/${new_linux_version_hash}/" "$purescript_derivation_file" +sed -i -e "s/${old_darwin_version_hash}/${new_darwin_version_hash}/" "$purescript_derivation_file" +sed -i -e "s/${old_version}/${new_version}/" "$purescript_derivation_file" +echo + +echo "Finished. Make sure you run the following commands to confirm PureScript builds correctly:" +echo ' - `nix build -L -f ./. purescript`' +echo ' - `nix build -L -f ./. purescript.passthru.tests.minimal-module`' +echo ' - `sudo nix build -L -f ./. spago.passthru.tests --option sandbox relaxed`'