forked from mirrors/nixpkgs
Merge pull request #175496 from kubukoz/scala-cli-updater
This commit is contained in:
commit
346b98c22b
|
@ -1,21 +1,14 @@
|
|||
{ stdenv, coreutils, lib, installShellFiles, zlib, autoPatchelfHook, fetchurl }:
|
||||
{ stdenv, coreutils, lib, installShellFiles, zlib, autoPatchelfHook, fetchurl, callPackage }:
|
||||
|
||||
let
|
||||
version = "0.1.5";
|
||||
assets = {
|
||||
x86_64-darwin = {
|
||||
asset = "scala-cli-x86_64-apple-darwin.gz";
|
||||
sha256 = "1sczbvvhh1ff8mdb6zj4q3fnrz1qsqmr58jlb1s3fy1wv2p5ywxl";
|
||||
};
|
||||
x86_64-linux = {
|
||||
asset = "scala-cli-x86_64-pc-linux.gz";
|
||||
sha256 = "1ahvjgcghh1pmgfsajg0b8bf5aaqxdx0f6b6qgljs0xfqm7zs05v";
|
||||
};
|
||||
};
|
||||
pname = "scala-cli";
|
||||
sources = builtins.fromJSON (builtins.readFile ./sources.json);
|
||||
inherit (sources) version assets;
|
||||
|
||||
platforms = builtins.attrNames assets;
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
pname = "scala-cli";
|
||||
inherit version;
|
||||
inherit pname version;
|
||||
nativeBuildInputs = [ installShellFiles ]
|
||||
++ lib.optional stdenv.isLinux autoPatchelfHook;
|
||||
buildInputs = [ coreutils zlib stdenv.cc.cc ];
|
||||
|
@ -27,7 +20,6 @@ stdenv.mkDerivation {
|
|||
url = "https://github.com/Virtuslab/scala-cli/releases/download/v${version}/${asset.asset}";
|
||||
sha256 = asset.sha256;
|
||||
};
|
||||
|
||||
unpackPhase = ''
|
||||
runHook preUnpack
|
||||
gzip -d < $src > scala-cli
|
||||
|
@ -61,6 +53,7 @@ stdenv.mkDerivation {
|
|||
license = licenses.asl20;
|
||||
description = "Command-line tool to interact with the Scala language";
|
||||
maintainers = [ maintainers.kubukoz ];
|
||||
platforms = builtins.attrNames assets;
|
||||
};
|
||||
|
||||
passthru.updateScript = callPackage ./update.nix { } { inherit platforms pname version; };
|
||||
}
|
||||
|
|
13
pkgs/development/tools/build-managers/scala-cli/sources.json
Normal file
13
pkgs/development/tools/build-managers/scala-cli/sources.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"version": "0.1.6",
|
||||
"assets": {
|
||||
"x86_64-darwin": {
|
||||
"asset": "scala-cli-x86_64-apple-darwin.gz",
|
||||
"sha256": "1wcm47x0w4gdhkqrqjn0qvgnn36c707mz9m260pdnnffja203vyr"
|
||||
},
|
||||
"x86_64-linux": {
|
||||
"asset": "scala-cli-x86_64-pc-linux.gz",
|
||||
"sha256": "1jwv67p2r6kxqlz8p2zvk5g5jdswl8cymj822b88lbp78a497kc6"
|
||||
}
|
||||
}
|
||||
}
|
37
pkgs/development/tools/build-managers/scala-cli/update.nix
Normal file
37
pkgs/development/tools/build-managers/scala-cli/update.nix
Normal file
|
@ -0,0 +1,37 @@
|
|||
{ lib, curl, writeShellScript, jq, gnused, git, nix, coreutils }: { platforms, pname, version }:
|
||||
|
||||
writeShellScript "${pname}-update-script" ''
|
||||
set -o errexit
|
||||
PATH=${lib.makeBinPath [ curl jq gnused git nix coreutils ]}
|
||||
|
||||
latest_version=$(curl -s "https://api.github.com/repos/VirtusLab/scala-cli/releases?per_page=1" | jq ".[0].tag_name" --raw-output | sed 's/^v//')
|
||||
|
||||
if [[ "${version}" = "$latest_version" ]]; then
|
||||
echo "The new version same as the old version."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
nixpkgs=$(git rev-parse --show-toplevel)
|
||||
sources_json="$nixpkgs/pkgs/development/tools/build-managers/scala-cli/sources.json"
|
||||
|
||||
platform_assets=()
|
||||
|
||||
for platform in ${lib.concatStringsSep " " platforms}; do
|
||||
asset=$(jq ".assets.\"$platform\".asset" --raw-output < $sources_json)
|
||||
release_asset_url="https://github.com/Virtuslab/scala-cli/releases/download/v$latest_version/$asset"
|
||||
|
||||
asset_hash=$(nix-prefetch-url "$release_asset_url")
|
||||
|
||||
asset_object=$(jq --compact-output --null-input \
|
||||
--arg asset "$asset" \
|
||||
--arg sha256 "$asset_hash" \
|
||||
--arg platform "$platform" \
|
||||
'{asset: $asset, sha256: $sha256, platform: $platform}')
|
||||
platform_assets+=($asset_object)
|
||||
done
|
||||
|
||||
printf '%s\n' "''${platform_assets[@]}" | \
|
||||
jq -s "map ( { (.platform): . | del(.platform) }) | add" | \
|
||||
jq --arg version $latest_version \
|
||||
'{ version: $version, assets: . }' > $sources_json
|
||||
''
|
Loading…
Reference in a new issue