mnix: Nix binary-cache client PoC in MoonBit (install hello from cache.nixos.org) (#1)
This commit was merged in pull request #1.
This commit is contained in:
1 parent
4e7ce11973
commit
fa70164336
48 files changed
+3112
-2
No files matched your search
@@ -0,0 +1,46 @@
|
||||
///|
|
||||
/// Compute the transitive closure of store paths over `References`.
|
||||
///
|
||||
/// `roots` are `<hash>-<name>` base names. `fetch` returns the narinfo for a
|
||||
/// store hash (or None when the cache lacks it — which is an error here: a
|
||||
/// closure with a missing member is not installable). Result is ordered
|
||||
/// dependencies-first (post-order DFS), roots last, each path once.
|
||||
pub async fn compute(
|
||||
roots : Array[String],
|
||||
fetch : async (String) -> @narinfo.NarInfo? raise @store.NixError,
|
||||
) -> Array[@narinfo.NarInfo] raise @store.NixError {
|
||||
let done : Map[String, Bool] = Map([])
|
||||
let order : Array[@narinfo.NarInfo] = []
|
||||
for r in roots {
|
||||
visit(r, fetch, done, order, 0)
|
||||
}
|
||||
order
|
||||
}
|
||||
|
||||
///|
|
||||
async fn visit(
|
||||
base : String,
|
||||
fetch : async (String) -> @narinfo.NarInfo? raise @store.NixError,
|
||||
done : Map[String, Bool],
|
||||
order : Array[@narinfo.NarInfo],
|
||||
depth : Int32,
|
||||
) -> Unit raise @store.NixError {
|
||||
if done.contains(base) {
|
||||
return
|
||||
}
|
||||
done[base] = true // mark first: references may be cyclic only via self
|
||||
if depth > 10000 {
|
||||
raise Parse("closure recursion too deep at \{base}")
|
||||
}
|
||||
let sp = @store.StorePath::parse_base(base)
|
||||
let ni = match fetch(sp.hash) {
|
||||
Some(n) => n
|
||||
None => raise Network("path \{base} not found in binary cache")
|
||||
}
|
||||
for r in ni.references {
|
||||
if r != base {
|
||||
visit(r, fetch, done, order, depth + 1)
|
||||
}
|
||||
}
|
||||
order.push(ni)
|
||||
}
|
||||
Reference in new issue
Block a user