# orbit A small package manager written in MoonBit that uses any OCI registry (Gitea, GHCR, Harbor, `registry:2`, ...) as its repository, with [ORAS](https://github.com/oras-project/oras) as the transport. > **Status: not compiled yet.** This was written without access to a MoonBit toolchain. Expect a few compile fixes on first build. The likeliest spots are listed under *First build* below. ## What it does - **Publish:** `orbit publish ` packs `/files/` into `pkg.tar.gz` and pushes it with `/orbit.json` as the OCI config blob. - **Install with dependencies:** it reads only the small config blob (`oras manifest fetch-config`) to plan, then pulls the layers by digest. - **Version constraints:** `1.2.3`, `1.2`, `^1.2.0`, `~1.2.0`, `>=1.2`, `*`. Prereleases match only when the constraint asks for one. - **Content-addressed store:** packages unpack into `~/.orbit/store///`, and their binaries are symlinked into `~/.orbit/bin/`. - **File ownership:** two packages can't provide the same binary. - **Upgrade and rollback:** the previous two builds are kept, and `orbit rollback ` switches back instantly with no network. - **Remove:** `orbit remove` refuses to delete what other packages need, then autoremoves orphaned dependencies. - **gc** deletes builds that are neither current nor kept for rollback. ## Package format ``` mypkg/ orbit.json files/ bin/mytool share/... ``` ```json { "name": "mytool", "version": "1.4.0", "description": "Does a thing", "bin": ["bin/mytool"], "depends": { "libfoo": "^2.1.0" } } ``` In the registry this becomes `/mytool:1.4.0`, plus the `latest` tag: | Part | Media type | |---|---| | config | `application/vnd.latha.orbit.config.v1+json` (the orbit.json) | | layer `pkg.tar.gz` | `application/vnd.latha.orbit.layer.v1.tar+gzip` | Because these are ordinary OCI artifacts, you can sign them with `cosign` or `notation` and attach SBOMs using the registry's own tooling. ## Usage ```sh oras login git.site.latha.org # once, with a Gitea token orbit init git.site.latha.org/ # Gitea: registry is / eval "$(orbit env)" orbit publish examples/hello orbit install hello hello # -> hello from orbit orbit upgrade orbit rollback hello orbit remove hello ``` Use `--plain-http` (or `ORBIT_PLAIN_HTTP=1`) for a local `registry:2` without TLS: ```sh docker run -d -p 5000:5000 registry:2 orbit init localhost:5000/pkgs --plain-http ``` ## Building ```sh moon build --target native --release moon test --target native # semver / manifest unit tests # the binary is under target/native/release/build/main/ ``` Linux only for now: arguments come from `/proc/self/cmdline`. It needs `oras`, `tar` and `/bin/sh` on `PATH`. ## Layout ``` src/main/ stub.c C glue: system(), popen(), file read/write, getenv, exit sys.mbt FFI bindings, UTF-8, string helpers, shell quoting semver.mbt versions, constraints, tag selection (+ tests) model.mbt orbit.json / state.json / config.json (+ tests) registry.mbt oras wrappers: tags, resolve, fetch-config, pull, push ops.mbt dependency planner, install/remove/upgrade/rollback/gc main.mbt CLI ``` ## First build: likely fix-ups The code avoids most of the standard library (string helpers are built on `for c in s` only), but a few calls depend on the compiler version: - `suberror OrbitError String` and `raise` in signatures. Older compilers use `type! OrbitError String` and `!` call syntax. - `Bytes::makei`, `Int::unsafe_to_char`, `StringBuilder::write_char`. - `@json.parse(String)`, which may want a `StringView`, and `Json::Object` / `Json::String` patterns. - `Json::stringify(indent=2)`. - C FFI argument ownership. The stub never decrefs, so the worst case is a small leak. ## Known limits - Dependency resolution is greedy (highest satisfying version, first come), not a SAT solver. - There's no lock file for concurrent runs, and no install hooks, by design. - `search` needs the registry's catalog API, which Gitea doesn't expose. Use `orbit info ` there.