1 { lib, curl, writeShellScript, jq, gnused, git, nix, coreutils }: { platforms, pname, version }:
3 writeShellScript "${pname}-update-script" ''
5 PATH=${lib.makeBinPath [ curl jq gnused git nix coreutils ]}
7 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//')
9 if [[ "${version}" = "$latest_version" ]]; then
10 echo "The new version same as the old version."
14 nixpkgs=$(git rev-parse --show-toplevel)
15 sources_json="$nixpkgs/pkgs/development/tools/build-managers/scala-cli/sources.json"
19 for platform in ${lib.concatStringsSep " " platforms}; do
20 asset=$(jq ".assets.\"$platform\".asset" --raw-output < $sources_json)
21 release_asset_url="https://github.com/Virtuslab/scala-cli/releases/download/v$latest_version/$asset"
23 asset_hash=$(nix-prefetch-url "$release_asset_url")
25 asset_object=$(jq --compact-output --null-input \
26 --arg asset "$asset" \
27 --arg sha256 "$asset_hash" \
28 --arg platform "$platform" \
29 '{asset: $asset, sha256: $sha256, platform: $platform}')
30 platform_assets+=($asset_object)
33 printf '%s\n' "''${platform_assets[@]}" | \
34 jq -s "map ( { (.platform): . | del(.platform) }) | add" | \
35 jq --arg version $latest_version \
36 '{ version: $version, assets: . }' > $sources_json