nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 51 lines 1.0 kB view raw
1#!/usr/bin/env nix-shell 2#! nix-shell -p nix jq curl cargo rsync 3#! nix-shell -i bash 4 5set -eu 6 7cd "$(dirname "$0")" 8 9crate=rure 10 11echo "Getting latest version from crates.io API" >&2 12 13curlOpts=( 14 -H "Accept: application/json" 15 -H "User-Agent: $crate update script (https://github.com/nixos/nixpkgs/)" 16) 17 18version="$(curl "${curlOpts[@]}" "https://crates.io/api/v1/crates/$crate" \ 19 | jq -r .crate.max_stable_version)" 20 21echo "Prefetching latest tarball from crates.io" >&2 22 23url="https://crates.io/api/v1/crates/$crate/$version/download" 24prefetch="$(nix-prefetch-url --print-path --type sha256 --unpack "$url")" 25 26cat > pin.json <<EOF 27{ 28 "pname": "$crate", 29 "version": "$version", 30 "hash": "sha256:$(printf '%s' "$prefetch" | head -n1)" 31} 32EOF 33 34echo "Generating updated Cargo.lock" >&2 35 36tmp="$(mktemp -d)" 37 38cleanup() { 39 echo "Removing $tmp" >&2 40 rm -rf "$tmp" 41} 42 43trap cleanup EXIT 44 45rsync -a --chmod=ugo=rwX "$(printf '%s' "$prefetch" | tail -n1)/" "$tmp" 46 47pushd "$tmp" 48cargo update 49popd 50 51cp "$tmp/Cargo.lock" ./Cargo.lock