1#!/usr/bin/env nix-shell
2#!nix-shell -i bash -p jq nix nix-prefetch-github
3
4nixpkgs="$(git rev-parse --show-toplevel || (printf 'Could not find root of nixpkgs repo\nAre we running from within the nixpkgs git repo?\n' >&2; exit 1))"
5
6narhash() {
7 nix --extra-experimental-features nix-command store prefetch-file --json "$1" | jq -r .hash
8}
9
10set -euo pipefail
11
12declare -A architectures
13declare -A versions
14declare -A hashes
15
16architectures["x86_64-linux"]="x86_64-unknown-linux-gnu"
17architectures["x86_64-darwin"]="x86_64-apple-darwin"
18architectures["aarch64-darwin"]="aarch64-apple-darwin"
19
20BASE_URL="https://files.nordicsemi.com/artifactory/swtools/external/nrfutil"
21
22for a in ${!architectures[@]}; do
23 versions["$a"]=$(curl "$BASE_URL/index/${architectures[${a}]}/index.json" | jq -r '.packages.nrfutil.latest_version')
24 hashes["$a"]=$(narhash "$BASE_URL/packages/nrfutil/nrfutil-${architectures[${a}]}-${versions[${a}]}.tar.gz")
25done
26
27{
28 printf "{\n"
29 printf " version = \"${versions["x86_64-linux"]}\";\n"
30 for a in ${!architectures[@]}; do
31 printf " ${a} = {\n"
32 printf " name = \"${architectures[${a}]}\";\n"
33 printf " hash = \"${hashes[${a}]}\";\n"
34 printf " };\n"
35 done
36 printf "}\n"
37} > "${nixpkgs}/pkgs/by-name/nr/nrfutil/source.nix"