nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1import json
2import os
3import requests
4import shutil
5import subprocess
6import sys
7import tempfile
8
9# See YC_SDK_STORAGE_URL in
10# https://storage.yandexcloud.net/yandexcloud-yc/install.sh
11storage_url = "https://storage.yandexcloud.net/yandexcloud-yc"
12
13systems = [
14 ("aarch64", "darwin"),
15 ("aarch64", "linux"),
16 ("i686", "linux"),
17 ("x86_64", "darwin"),
18 ("x86_64", "linux"),
19]
20
21
22def to_goarch(cpu):
23 return {
24 "aarch64": "arm64",
25 "i686": "386",
26 "x86_64": "amd64",
27 }.get(cpu, cpu)
28
29
30nixpkgs_path = "."
31attr_path = os.getenv("UPDATE_NIX_ATTR_PATH", "yandex-cloud")
32
33package_attrs = json.loads(subprocess.run(
34 [
35 "nix",
36 "--extra-experimental-features", "nix-command",
37 "eval",
38 "--json",
39 "--file", nixpkgs_path,
40 "--apply", """p: {
41 dir = dirOf p.meta.position;
42 version = p.version;
43 }""",
44 "--",
45 attr_path,
46 ],
47 stdout=subprocess.PIPE,
48 text=True,
49 check=True,
50).stdout)
51
52old_version = package_attrs["version"]
53new_version = requests.get(f"{storage_url}/release/stable").text.rstrip()
54
55if new_version == old_version:
56 sys.exit()
57
58binaries = {}
59for cpu, kernel in systems:
60 goos = kernel
61 goarch = to_goarch(cpu)
62 system = f"{cpu}-{kernel}"
63
64 url = f"{storage_url}/release/{new_version}/{goos}/{goarch}/yc"
65
66 nix_hash = subprocess.run(
67 [
68 "nix-prefetch-url",
69 "--type", "sha256",
70 url,
71 ],
72 stdout=subprocess.PIPE,
73 text=True,
74 check=True,
75 ).stdout.rstrip()
76
77 sri_hash = subprocess.run(
78 [
79 "nix",
80 "--extra-experimental-features", "nix-command",
81 "hash",
82 "to-sri",
83 "--type", "sha256",
84 "--",
85 nix_hash,
86 ],
87 stdout=subprocess.PIPE,
88 text=True,
89 check=True,
90 ).stdout.rstrip()
91
92 binaries[system] = {
93 "url": url,
94 "hash": sri_hash,
95 }
96
97package_dir = package_attrs["dir"]
98file_path = os.path.join(package_dir, "sources.json")
99file_content = json.dumps({
100 "version": new_version,
101 "binaries": binaries,
102}, indent=2) + "\n"
103
104with tempfile.NamedTemporaryFile(mode="w") as t:
105 t.write(file_content)
106 t.flush()
107 shutil.copyfile(t.name, file_path)