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")
17 return path
[len(nixPrefix
+ "/"):]
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
,
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"]),