Skip to content

Commit

Permalink
dotnet: fetch hash from nuget.org in update.sh
Browse files Browse the repository at this point in the history
This brings down the time needed to update one version from ~10min to ~20s for me
  • Loading branch information
js6pak authored and corngood committed Nov 17, 2024
1 parent ecc5208 commit d566f47
Show file tree
Hide file tree
Showing 7 changed files with 600 additions and 577 deletions.
224 changes: 112 additions & 112 deletions pkgs/development/compilers/dotnet/8/bootstrap-sdk.nix

Large diffs are not rendered by default.

136 changes: 68 additions & 68 deletions pkgs/development/compilers/dotnet/9/bootstrap-sdk.nix

Large diffs are not rendered by default.

33 changes: 28 additions & 5 deletions pkgs/development/compilers/dotnet/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,43 @@ platform_sources () {
echo " };"
}

nuget_url="$(curl -fsSL "https://api.nuget.org/v3/index.json" | jq --raw-output '.resources[] | select(."@type" == "PackageBaseAddress/3.0.0")."@id"')"
nuget_index="$(curl -fsSL "https://api.nuget.org/v3/index.json")"

get_nuget_resource() {
jq -r '.resources[] | select(."@type" == "'"$1"'")."@id"' <<<"$nuget_index"
}

nuget_package_base_url="$(get_nuget_resource "PackageBaseAddress/3.0.0")"
nuget_registration_base_url="$(get_nuget_resource "RegistrationsBaseUrl/3.6.0")"

generate_package_list() {
local version="$1" indent="$2"
shift 2
local pkgs=( "$@" ) pkg url hash
local pkgs=( "$@" ) pkg url hash catalog_url catalog hash_algorithm

for pkg in "${pkgs[@]}"; do
url=${nuget_url}${pkg,,}/${version,,}/${pkg,,}.${version,,}.nupkg
if ! hash=$(nix-prefetch-url "$url"); then
url=${nuget_package_base_url}${pkg,,}/${version,,}/${pkg,,}.${version,,}.nupkg

if hash=$(curl -s --head "$url" -o /dev/null -w '%header{x-ms-meta-sha512}') && [[ -n "$hash" ]]; then
# Undocumented fast path for nuget.org
# https://github.com/NuGet/NuGetGallery/issues/9433#issuecomment-1472286080
hash=$(nix hash convert --to sri --hash-algo sha512 "$hash")
elif {
catalog_url=$(curl -sL --compressed "${nuget_registration_base_url}${pkg,,}/${version,,}.json" | jq -r ".catalogEntry") && [[ -n "$catalog_url" ]] &&
catalog=$(curl -sL "$catalog_url") && [[ -n "$catalog" ]] &&
hash_algorithm="$(jq -er '.packageHashAlgorithm' <<<"$catalog")"&& [[ -n "$hash_algorithm" ]] &&
hash=$(jq -er '.packageHash' <<<"$catalog") && [[ -n "$hash" ]]
}; then
# Documented but slower path (requires 2 requests)
hash=$(nix hash convert --to sri --hash-algo "${hash_algorithm,,}" "$hash")
elif hash=$(nix-prefetch-url "$url" --type sha512); then
# Fallback to downloading and hashing locally
echo "Failed to fetch hash from nuget for $url, falling back to downloading locally" >&2
hash=$(nix hash convert --to sri --hash-algo sha512 "$hash")
else
echo "Failed to fetch hash for $url" >&2
exit 1
fi
hash=$(nix hash convert --to sri --hash-algo sha256 "$hash")

echo "$indent(fetchNupkg { pname = \"${pkg}\"; version = \"${version}\"; hash = \"${hash}\"; })"
done
Expand Down
204 changes: 102 additions & 102 deletions pkgs/development/compilers/dotnet/versions/6.0.nix

Large diffs are not rendered by default.

220 changes: 110 additions & 110 deletions pkgs/development/compilers/dotnet/versions/7.0.nix

Large diffs are not rendered by default.

224 changes: 112 additions & 112 deletions pkgs/development/compilers/dotnet/versions/8.0.nix

Large diffs are not rendered by default.

136 changes: 68 additions & 68 deletions pkgs/development/compilers/dotnet/versions/9.0.nix

Large diffs are not rendered by default.

0 comments on commit d566f47

Please sign in to comment.