biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / build-support / binary-cache / make-binary-cache.py
blob589d005562b1fb20f92e962eb4c2b810b27043ff
2 import json
3 import os
4 import subprocess
6 with open(os.environ["NIX_ATTRS_JSON_FILE"], "r") as f:
7 closures = json.load(f)["closure"]
9 os.chdir(os.environ["out"])
11 nixPrefix = os.environ["NIX_STORE"] # Usually /nix/store
13 with open("nix-cache-info", "w") as f:
14 f.write("StoreDir: " + nixPrefix + "\n")
16 def dropPrefix(path):
17 return path[len(nixPrefix + "/"):]
19 for item in closures:
20 narInfoHash = dropPrefix(item["path"]).split("-")[0]
22 xzFile = "nar/" + narInfoHash + ".nar.xz"
23 with open(xzFile, "w") as f:
24 subprocess.run("nix-store --dump %s | xz -c" % item["path"], stdout=f, shell=True)
26 fileHash = subprocess.run(["nix-hash", "--base32", "--type", "sha256", item["path"]], capture_output=True).stdout.decode().strip()
27 fileSize = os.path.getsize(xzFile)
29 # Rename the .nar.xz file to its own hash to match "nix copy" behavior
30 finalXzFile = "nar/" + fileHash + ".nar.xz"
31 os.rename(xzFile, finalXzFile)
33 with open(narInfoHash + ".narinfo", "w") as f:
34 f.writelines((x + "\n" for x in [
35 "StorePath: " + item["path"],
36 "URL: " + finalXzFile,
37 "Compression: xz",
38 "FileHash: sha256:" + fileHash,
39 "FileSize: " + str(fileSize),
40 "NarHash: " + item["narHash"],
41 "NarSize: " + str(item["narSize"]),
42 "References: " + " ".join(dropPrefix(ref) for ref in item["references"]),
43 ]))