nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 55 lines 1.8 kB view raw
1#!/usr/bin/env nix-shell 2#!nix-shell -i python3 -p python3 bash nix-update jq 3import subprocess 4from os.path import join, dirname 5 6# Outer keys are as in Nix, the inner dict's values are as in upstream. 7# We set oldHash and newHash fields in the inner dict later. 8systems = { 9 "x86_64-linux": {"os": "linux", "arch": "amd64"}, 10 "x86_64-darwin": {"os": "macos", "arch": "amd64"}, 11 "aarch64-linux": {"os": "linux", "arch": "aarch64"}, 12 "aarch64-darwin": {"os": "macos", "arch": "aarch64"}, 13} 14 15# This will set the version correctly, 16# and will also set the hash for one of the systems. 17subprocess.run([ 18 "nix-update", 19 "fermyon-spin", 20 "--version-regex", 21 r"^v([\d\.]*)", 22 "--url", 23 "https://github.com/spinframework/spin" 24]) 25 26newVer = subprocess.run( 27 ["nix-instantiate", "--eval", "--raw", "-A", "fermyon-spin.version"], capture_output=True, encoding="locale" 28).stdout 29 30for nixTuple in systems: 31 url = ( 32 "https://github.com/spinframework/spin/releases/download/v" 33 f"{newVer}/spin-v{newVer}-{systems[nixTuple]['os']}-{systems[nixTuple]['arch']}.tar.gz" 34 ) 35 36 systems[nixTuple]["oldHash"] = subprocess.run( 37 ["nix-instantiate", "--eval", "--raw", "-A", f"fermyon-spin.passthru.packageHashes.{nixTuple}"], 38 capture_output=True, 39 encoding="locale", 40 ).stdout 41 42 systems[nixTuple]["newHash"] = subprocess.run( 43 ["bash", "-c", f"nix store prefetch-file {url} --json | jq -r '.hash'"], 44 capture_output=True, 45 encoding="locale", 46 ).stdout.strip() # Has a newline 47 48with open(join(dirname(__file__), "package.nix"), "r") as f: 49 file = f.read() 50 51for nixTuple in systems: 52 file = file.replace(systems[nixTuple]["oldHash"], systems[nixTuple]["newHash"]) 53 54with open(join(dirname(__file__), "package.nix"), "w") as f: 55 f.write(file)