lol
1#!/usr/bin/env nix-shell
2#!nix-shell -i bash -p nix-prefetch-scripts
3
4set -eou pipefail
5
6version=$1
7
8bucket="https://download.pytorch.org/libtorch"
9CUDA_VERSION=cu121
10
11url_and_key_list=(
12 "aarch64-darwin-cpu $bucket/cpu/libtorch-macos-arm64-${version}.zip libtorch-macos-arm64-${version}.zip"
13 "x86_64-darwin-cpu $bucket/cpu/libtorch-macos-x86_64-${version}.zip libtorch-macos-x86_64-${version}.zip"
14 "x86_64-linux-cpu $bucket/cpu/libtorch-cxx11-abi-shared-with-deps-${version}%2Bcpu.zip libtorch-cxx11-abi-shared-with-deps-${version}-cpu.zip"
15 "x86_64-linux-cuda $bucket/${CUDA_VERSION}/libtorch-cxx11-abi-shared-with-deps-${version}%2B${CUDA_VERSION}.zip libtorch-cxx11-abi-shared-with-deps-${version}-${CUDA_VERSION}.zip"
16)
17
18hashfile="binary-hashes-$version.nix"
19echo " \"$version\" = {" >> $hashfile
20
21for url_and_key in "${url_and_key_list[@]}"; do
22 key=$(echo "$url_and_key" | cut -d' ' -f1)
23 url=$(echo "$url_and_key" | cut -d' ' -f2)
24 name=$(echo "$url_and_key" | cut -d' ' -f3)
25
26 echo "prefetching ${url}..."
27 hash=$(nix hash to-sri --type sha256 $(nix-prefetch-url --unpack "$url" --name "$name"))
28
29 echo " $key = {" >> $hashfile
30 echo " name = \"$name\";" >> $hashfile
31 echo " url = \"$url\";" >> $hashfile
32 echo " hash = \"$hash\";" >> $hashfile
33 echo " };" >> $hashfile
34
35 echo
36done
37
38echo " };" >> $hashfile
39echo "done."