about summary refs log tree commit diff
path: root/nixpkgs/pkgs/os-specific/darwin/apple-source-releases/generate-sdk-packages.sh
blob: 418a1d625d6aeb5c6a7b4a12ab12eb5b3e928f8d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq

usage() {
    cat <<EOF
usage: $0 macos 11.0.1
EOF
}

if [ "$#" != 2 ]; then
    usage
    exit 1
fi

cd $(dirname "$0")

sdkName="$1-$2"
outfile="$sdkName.nix"

>$outfile echo "# Generated using:  ./$(basename "$0") $1 $2

{ applePackage' }:

{"

parse_line() {
    readarray -t -d$'-' package < <(printf "%s" $2)
    local pname=${package[0]} version=${package[1]}

    if [ -d $pname ]; then
        sha256=$(nix-prefetch-url "https://github.com/apple-oss-distributions/$pname/archive/refs/tags/$pname-$version.tar.gz")
        >>$outfile echo "$pname = applePackage' \"$pname\" \"$version\" \"$sdkName\" \"$sha256\" {};"
    fi
}
readarray -s1 -c1 -C parse_line < <(curl -sSL "https://github.com/apple-oss-distributions/distribution-${1//-/_}/raw/${sdkName//./}/release.json" | jq -r ".projects[].tag")

>>$outfile echo '}'