Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1#!/usr/bin/env nix-shell 2#!nix-shell -i bash -p curl jq 3 4set -euo pipefail 5 6# so if the script fails, debug logs are on stderr 7log() { 8 >&2 echo "DART_UPDATER: $@" 9} 10 11# fetch the latest version number from upstream 12NEW_VER_DETAILS=$(curl -sL https://storage.googleapis.com/dart-archive/channels/stable/release/latest/VERSION) 13NEW_VER=$(jq -r '.version' <<< "$NEW_VER_DETAILS") 14 15MY_PATH=$(dirname $(realpath "$0")) 16SRC_FILE=$(mktemp) 17 18log "file to write is $SRC_FILE" 19 20PRELUDE="let version = \"$NEW_VER\"; in 21{ fetchurl }: { 22 versionUsed = version;" 23echo "$PRELUDE" > "$SRC_FILE" 24log "wrote prelude" 25 26# Fetches the source, then writes the fetcher and hash into the sources file. 27# Arguments: 28# - $1: VARIABLE NAME of (table of nix platform -> dart platform mappings) ("DARWIN_PLATFORMS"|"LIN_PLATFORMS") 29# - $2: Dart-OS ("macos"|"linux") 30write_for_platform() { 31 BASE_OF_ALL_URLS='https://storage.googleapis.com/dart-archive/channels/stable/release' 32 BASE_URL_WRITTEN="$BASE_OF_ALL_URLS/\${version}/sdk" 33 BASE_URL_FETCHED="$BASE_OF_ALL_URLS/$NEW_VER/sdk" 34 35 TABLE_NAME=$1 36 declare -n TABLE=$TABLE_NAME 37 38 for platform in "${!TABLE[@]}"; do 39 DART_PLATFORM="${TABLE[$platform]}" 40 log "trying for dartplatform $DART_PLATFORM (platform $platform) (OS $2)" 41 42 URL_POSTFIX="dartsdk-$2-$DART_PLATFORM-release.zip" 43 URL="$BASE_URL_FETCHED/$URL_POSTFIX" 44 log "URL for $DART_PLATFORM: $URL" 45 46 HASH=$(nix-prefetch-url "$URL" --type sha256) 47 log "hash for platform $platform: $HASH" 48 49 FETCHER=" \"\${version}-$platform\" = fetchurl { 50 url = \"$BASE_URL_WRITTEN/$URL_POSTFIX\"; 51 sha256 = \"$HASH\"; 52 };" 53 54 echo "$FETCHER" >> $SRC_FILE 55 done 56 log "finished for $1" 57 58} 59 60# Map nix platforms -> Dart platforms 61X8664="x64" 62AARCH64="arm64" 63I686="ia32" 64declare -A DARWIN_PLATFORMS=(["aarch64-darwin"]="$AARCH64" 65 ["x86_64-darwin"]="$X8664") 66 67declare -A LIN_PLATFORMS=( ["x86_64-linux"]="$X8664" 68 ["i686-linux"]="$I686" 69 ["aarch64-linux"]="$AARCH64") 70 71write_for_platform "DARWIN_PLATFORMS" "macos" 72write_for_platform "LIN_PLATFORMS" "linux" 73 74echo '}' >> $SRC_FILE 75 76log "moving tempfile to target directory" 77mv "$SRC_FILE" "$MY_PATH/sources.nix"