mnix: Nix binary-cache client PoC in MoonBit

Store path model + nixbase32, narinfo parser, ed25519 signature
verification, NAR reader/writer, closure computation, xz/zstd NAR fetch
with hash verification, atomic store unpack, profile management, Hydra-based
name resolution, and the mnix CLI. README documents usage, the /nix/store
limitation, and what a fuller implementation needs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
SpriteandClaude Sonnet 5.5 committed 2026-11-24 22:09:44 +00:00
1 parent 82c08d45b1
commit 7ed4bc8e51
9 files changed
+359 -12

No files matched your search

+8 -2
View File
@@ -6,7 +6,7 @@ fn pname_of(name : String) -> String {
if chars[i] == '-' && i + 1 < chars.length() {
let n = chars[i + 1]
if n >= '0' && n <= '9' {
return name[0:i].to_string()
return name[0:i].to_owned()
}
}
}
@@ -23,7 +23,7 @@ async fn resolve_target(
return (sp, pname_of(sp.name))
}
// "<hash>-<name>" base name given directly?
if target.length() > 33 && target[32:33].to_string() == "-" {
if target.length() > 33 && target[32:33].to_owned() == "-" {
let sp = @store.StorePath::parse_base(target)
return (sp, pname_of(sp.name))
}
@@ -237,6 +237,12 @@ async fn cmd_run(
None => ""
}
let extra : Map[String, String] = { "PATH": "\{cfg.profile.dir}/bin:\{path}" }
// The OS spawns argv[0] using *our* PATH, not the child's: resolve
// profile commands to their symlink explicitly.
let candidate = "\{cfg.profile.dir}/bin/\{argv[0]}"
if !argv[0].contains("/") && @installer.lexists(candidate) {
argv[0] = candidate
}
try {
if cfg.store_dir == @store.default_store_dir {
@process.run(argv[0], argv[1:], extra_env=extra)
+2 -2
View File
@@ -25,7 +25,7 @@ async fn detect_system() -> String raise @store.NixError {
if code != 0 {
raise Io("uname -m exited with \{code}")
}
let arch = out.text().trim().to_string() catch {
let arch = out.text().trim().to_owned() catch {
e => raise Io("decoding uname output: \{e}")
}
match arch {
@@ -49,7 +49,7 @@ async fn load_config(m : @argparse.Matches) -> Config raise @store.NixError {
}
}
let store_dir = match opt(m, "store") {
Some(s) => s.trim_end(chars="/").to_string()
Some(s) => s.trim_end(chars="/").to_owned()
None => "\{root}/store"
}
let channel = @resolve.Channel::parse(opt(m, "channel").unwrap())
+4 -4
View File
@@ -93,7 +93,7 @@ fn build_command() -> @argparse.Command {
positionals=[
PositionArg(
"command",
num_args=@argparse.ValueRange::new(lower=1),
num_args=@argparse.ValueRange(lower=1),
allow_hyphen_values=true,
),
],
@@ -107,7 +107,7 @@ async fn run_cli() -> Int32 {
// `run` takes arbitrary trailing arguments: split argv at the subcommand
// so flags meant for the child are not interpreted by mnix.
let argv = @env.args()
let args = argv[1:].to_array()
let args = argv[1:].to_owned()
let mut run_tail : Array[String]? = None
let mut head = args
for i in 0..<args.length() {
@@ -125,8 +125,8 @@ async fn run_cli() -> Int32 {
}
}
if ok {
head = args[0:i + 1].to_array()
run_tail = Some(args[i + 1:].to_array())
head = args[0:i + 1].to_owned()
run_tail = Some(args[i + 1:].to_owned())
}
break
}
-1
View File
@@ -10,7 +10,6 @@ import {
"moonbitlang/core/argparse",
"moonbitlang/core/env",
"moonbitlang/core/encoding/utf8",
"moonbitlang/async",
"moonbitlang/async/fs",
"moonbitlang/async/process",
"lin2077-zeming/moonxz/lib" @xz,