diff options
3 files changed, 59 insertions, 16 deletions
diff --git a/pkgs/development/tools/build-managers/scala-cli/default.nix b/pkgs/development/tools/build-managers/scala-cli/default.nix index 40b230a72c3..1eb6b92cbd4 100644 --- a/pkgs/development/tools/build-managers/scala-cli/default.nix +++ b/pkgs/development/tools/build-managers/scala-cli/default.nix @@ -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; }; } diff --git a/pkgs/development/tools/build-managers/scala-cli/sources.json b/pkgs/development/tools/build-managers/scala-cli/sources.json new file mode 100644 index 00000000000..a69e67d3bf8 --- /dev/null +++ b/pkgs/development/tools/build-managers/scala-cli/sources.json @@ -0,0 +1,13 @@ +{ + "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" + } + } +} diff --git a/pkgs/development/tools/build-managers/scala-cli/update.nix b/pkgs/development/tools/build-managers/scala-cli/update.nix new file mode 100644 index 00000000000..fd79a1cf3a8 --- /dev/null +++ b/pkgs/development/tools/build-managers/scala-cli/update.nix @@ -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 +'' |