#!/usr/bin/env python3 """Compose a flake.lock for the freshly installed machine — offline. The generated downstream flake has exactly one input, `nomarchy`. A normal `nix flake lock` would fetch it from its forge; on an offline install we already KNOW the answer: the live ISO was built from a specific nomarchy rev whose source (and all transitive inputs, via the ISO's pinned store paths) is on hand. So we write the lock nix would have written: root ─▶ nomarchy (locked to the baked rev+narHash) └─▶ every node from nomarchy's own flake.lock, verbatim Nix resolves locked inputs by narHash against the store before touching the network, so evaluation on the target works without connectivity. Usage: compose-lock.py where / are the flake-lock node fields for the nomarchy input (any input type — github, git, …), baked at package build. """ import json import sys def main() -> None: src_lock, out, locked_json, original_json = sys.argv[1:5] locked = json.loads(locked_json) if not locked.get("rev"): sys.exit("compose-lock: no rev in locked metadata (ISO built from a dirty tree?)") with open(src_lock) as f: upstream = json.load(f) nodes = dict(upstream["nodes"]) # nomarchy's root node describes ITS inputs; that mapping becomes the # input set of the new `nomarchy` node. nomarchy_inputs = nodes.pop("root")["inputs"] if "nomarchy" in nodes: sys.exit("compose-lock: upstream lock already has a 'nomarchy' node") nodes["nomarchy"] = { "inputs": nomarchy_inputs, "locked": locked, "original": json.loads(original_json), } nodes["root"] = {"inputs": {"nomarchy": "nomarchy"}} with open(out, "w") as f: json.dump({"nodes": nodes, "root": "root", "version": 7}, f, indent=2) f.write("\n") print(f"compose-lock: wrote {out} (nomarchy @ {locked['rev'][:12]})") if __name__ == "__main__": main()