arnaucube
arnaucube/hyperplonkPublic Self-hosted repository
hyperplonk/nix/update-nix
nix/update-nixRaw
 1#!/usr/bin/env nix-shell
 2#! nix-shell -i bash -p curl jq nix
 3#
 4#   Updates nixpkgs.json to the latest or chosen nixpkgs revision
 5#
 6#   Usage: ./update-nix
 7#          ./update-nix $rev
 8#          ./update-nix $owner $rev
 9#
10#   Arguments default to owner=nixos and rev=master and refer
11#   to the github owner of a nixpkgs fork and a git revision.
12#
13set -exo pipefail
14
15owner="nixos"
16
17if [ ! -z "$2" ]; then
18    owner="$1"
19    rev="$2"
20else
21    rev="${1:-master}"
22fi
23
24resolved_rev=$(curl "https://api.github.com/repos/${owner}/nixpkgs/commits?sha=${rev}" | jq -r 'first.sha')
25url="https://github.com/${owner}/nixpkgs/archive/${resolved_rev}.tar.gz"
26digest=$(nix-prefetch-url --unpack "$url")
27echo "{\"url\": \"${url}\", \"sha256\": \"${digest}\"}" | jq '.' > nix/nixpkgs.json