# orbit
A small package manager written in MoonBit that uses any OCI registry (Gitea, GHCR, Harbor, `registry:2`, ...) as its repository, speaking the OCI Distribution v2 protocol directly over HTTP/TLS.
> **Status:** builds cleanly (no warnings) with MoonBit `moonc v1.0.0-rc1` / `moon 0.1.20261126`, and the unit tests pass. publish, install (with dependencies), upgrade, rollback, remove and gc have been exercised end to end against a local `registry:2` and Gitea.
## What it does
- **Publish:** `orbit publish
` packs `/files/` into `pkg.tar.gz` and pushes it with `/orbit.json` as the OCI config blob.
- **Lazy CDCL SAT solver:** resolves global and project dependency graphs with backtracking, conflict explanations, and `channel::pkg` dependency pins, reading only needed config blobs and caching immutable `sha256` manifests under `~/.orbit/cache/manifests/`.
- **Pixi-style project environments:** `orbit new`, `orbit.toml` manifests, deterministic `orbit.lock` lockfiles, `[tasks]`, `orbit run`, and isolated `.orbit/bin/` environments symlinked from the shared store (`-g` / `--global` targets the global environment inside a project).
- **Version constraints:** `1.2.3`, `=1.2.3`, `==1.2.3`, `1.2`, `1.2.*`, `^1.2.0`, `~1.2.0`, `>=1.2`, `<=2.0`, `>1.0`, `<2.0`, `!=1.3.0`, `*`, and comma-separated ranges (`>=1.2.0, <2.0.0`). Prereleases match only when the constraint mentions a `-`.
- **Content-addressed store:** packages unpack into `~/.orbit/store///`, and their binaries are symlinked into `~/.orbit/bin/` (global) or `/.orbit/bin/` (project).
- **File ownership:** two packages can't provide the same binary.
- **Conflicts:** packages can declare that they can't be installed together, and a global install offers to replace the one in the way.
- **Upgrade and rollback:** global installs keep the previous two builds, and `orbit rollback ` switches back instantly with no network.
- **Remove:** `orbit remove` refuses to delete what other global packages need and autoremoves orphaned dependencies; in projects it updates `orbit.toml` and `orbit.lock`.
- **Self-update:** `orbit self-update` replaces the running Orbit with the newest `orbit` package in the registry, wherever it was installed.
- **gc** deletes store builds that are neither globally 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",
"documentation": "https://example.com/mytool",
"bin": ["bin/mytool"],
"depends": { "libfoo": "^2.1.0" }
}
```
In a channel this becomes `/mytool:1.4.0`, plus the `latest` tag. The manifest sets `artifactType` to `application/vnd.latha.orbit.v1`, which is how `orbit search` tells Orbit packages apart from other OCI artifacts such as Helm charts. Packages published before this have no `artifactType`, so search also recognises the Orbit config media type:
| Part | Media type |
|---|---|
| config | `application/vnd.latha.orbit.config.v1+json` (`orbit.json`, with OCI labels for package-page metadata) |
| layer `pkg.tar.gz` | `application/vnd.latha.orbit.layer.v1.tar+gzip` |
### Conflicts
`conflicts` names packages that can't be installed beside this one, with the
versions it applies to (`*` for all):
```json
{
"name": "mytool-nightly",
"version": "1.5.0",
"bin": ["bin/mytool"],
"conflicts": { "mytool": "*", "oldplugin": "<2.0.0" }
}
```
- Only one of the two packages has to declare it, and the named package need not exist.
- Unlike dependencies, a conflict covers prereleases without naming one. It applies to a package name in any channel.
- The solver looks for versions that don't conflict, and explains the conflict if there are none.
- If a global `orbit install` can't be satisfied beside the installed packages, it asks before removing the ones it conflicts with. Without a terminal it fails unless you pass `--replace`. It never removes a package that another one needs, and downloads everything before removing anything.
- `orbit upgrade` and project commands never replace packages. In a project, `orbit remove` the old one first.
- `orbit rollback` refuses a build that conflicts with an installed package.
- Orbit versions from before this field ignore it, and can't read an `orbit.lock` that contains it.
### Registry details
The optional `description` and `documentation` fields supply Gitea's **About**
text and **Documentation** link. Use a public or otherwise accessible HTTP(S)
URL for the link. Gitea does not render a bundled README inline, but you can
ship one under `files/share/doc//README.md`, as the `greet` example does.
Layers over 4 MiB are uploaded in 4 MiB pieces, so a proxy's limit on one request doesn't stop a large package.
Because these are ordinary OCI artifacts, you can sign them with `cosign` or `notation` and attach SBOMs using the registry's own tooling.
### Channel index
A channel can hold an index of its packages at `/orbit-index:latest` (the name is reserved), so `orbit search` takes two requests per channel, matches descriptions too, and needs no catalog API. Each namespace (a Gitea user or organisation) has its own index, written by whoever can publish there. A nested channel such as `nandi/example` is separate from `nandi`. Without an index, search asks the registry's catalog.
The manifest has `artifactType` `application/vnd.latha.orbit.index.v1` and one JSON layer (`application/vnd.latha.orbit.index.v1+json`):
```json
{"packages":[{"name":"mytool","version":"1.4.0","description":"...","versions":["1.4.0"],"digest":"sha256:..."}]}
```
- `orbit publish` adds the package to the index, and creates the index from the catalog if there is none. `--no-index` skips this.
- `orbit index [--channel ]` rebuilds it from the catalog. Use it after deleting a package, or if two publishes ran at once and one entry was lost. On a registry without a catalog, name the packages: `orbit index mytool othertool`.
- `digest` is the manifest digest of `version`. Indexes built before it was added lack it; `orbit index` adds it.
- Installs and version lookups never read the index, so a stale one can't change what is installed.
- Search and `orbit info` keep a copy of each channel's list in `~/.orbit/cache/indexes/` and use it for an hour without touching the network. After that it fetches the list again, or uses the old copy with a warning if the registry can't be reached. `orbit search --refresh` fetches now. Your own `publish`, `index`, `login` and `logout` drop the copies they affect. A channel without an index is cached too, if it has at most 100 repositories.
- The index is built with the publisher's login. On a registry where packages in one namespace can be private while others are public, a public index reveals the private names, descriptions and versions. Gitea sets visibility per owner, so this doesn't apply there.
## Usage
### Global environment
```sh
orbit login git.site.latha.org # once, with a Gitea token (needed to publish)
eval "$(orbit env)"
orbit channel add example git.site.latha.org/nandi/example # once
orbit publish examples/hello --channel example
orbit install example::hello
hello # -> hello from orbit
orbit upgrade
orbit rollback hello
orbit remove hello
```
### Project workflow (Pixi-style)
Inside a directory with `orbit.toml` (or pass `--manifest-path `), commands target the project unless you pass `-g` / `--global`:
```sh
orbit new myapp && cd myapp
orbit add example::hello example::greet
orbit run greet
orbit lock --update
orbit install --locked
orbit update
orbit remove hello
```
An `orbit.toml` looks like:
```toml
[project]
name = "myapp"
version = "0.1.0"
channels = ["example", "main"]
[[channels]]
name = "example"
url = "git.site.latha.org/nandi/example"
[dependencies]
hello = { version = "^1.0.0", channel = "example" }
greet = { version = ">=1.0.0, <2.0.0", channel = "example" }
[tasks]
hi = "greet"
```
See [examples/project](examples/project/README.md) for a working example project using `example::hello` and `example::greet`.
Credentials are stored in `~/.orbit/auth.json` (`$ORBIT_ROOT/auth.json`, mode `0600`). Orbit also falls back to `~/.docker/config.json` (`$DOCKER_CONFIG/config.json`) including `credHelpers` and `credsStore`. Use `orbit logout ` to remove stored credentials from Orbit.
If a registry rejects the saved login, Orbit reads anonymously without a message, so public packages still work. Publishing always needs a valid login. When an anonymous read is refused or finds nothing, Orbit reports the rejected login instead of moving to the next channel, because the package may be private.
## Channels
Packages come from **channels**, which work like channels in pixi. A channel is a name for a registry namespace. The built-in `main` channel is `git.site.latha.org/nandi`, so no setup is needed.
The packages in `main` are built by [orbit-packages](https://git.site.latha.org/nandi/orbit-packages), whose CI follows their upstreams.
Add your own in `~/.orbit/config.toml` (`$ORBIT_ROOT/config.toml`), highest priority first. [examples/config.toml](examples/config.toml) adds the `example` channel:
```toml
[[channels]]
name = "example"
url = "git.site.latha.org/nandi/example" # host/namespace, no https://
# [[channels]]
# name = "local"
# url = "localhost:5000/pkgs"
# plain-http = true # registry without TLS
```
`orbit channel add [--plain-http]` appends one at the lowest priority, and `orbit channel list` shows the order. To remove or reorder channels, edit the file. `orbit init` creates a commented starter file.
```sh
orbit channel add example git.site.latha.org/nandi/example
orbit install greet # first channel that has greet
orbit install example::greet # from a specific channel
orbit publish examples/greet --channel example # default: main
```
- **`main` is always included.** It comes first, so another channel can't silently replace one of its packages. To lower its priority, add a block with only `name = "main"` where you want it.
- **Strict priority.** The first channel that has a package name wins, even if a lower one has a newer or the only matching version. Dependencies are found the same way.
- **Unreachable channels stop the lookup.** Orbit moves to the next channel only when the registry says the package doesn't exist. Network and login errors fail.
- **Packages remember their channel.** `upgrade` and `rollback` keep it. `orbit install other::name` switches it. A package stays tied to its channel *name*, so changing that channel's URL changes where upgrades come from.
- **Environment.** `ORBIT_REGISTRY=/` replaces the URL of `main`, and `ORBIT_PLAIN_HTTP=1` applies to `main`. Other channels aren't affected.
A `config.json` from an earlier version still sets the URL of `main` until a `config.toml` exists. `orbit channel add` carries it over.
For a local `registry:2` without TLS:
```sh
docker run -d -p 5000:5000 registry:2
orbit channel add local localhost:5000/pkgs --plain-http
```
## Rolling release
Every push to `main` that passes the tests replaces the
[`rolling` release](https://git.site.latha.org/nandi/orbit/releases/tag/rolling)
with a static Linux x86_64 binary. It doesn't need glibc or OpenSSL, only `tar`,
`/bin/sh`, and the system's CA certificates (`ca-certificates` on most distros;
set `SSL_CERT_FILE` if they live somewhere unusual).
```sh
base=https://git.site.latha.org/nandi/orbit/releases/download/rolling
curl -fLO "$base/orbit-linux-x86_64" -fLO "$base/SHA256SUMS" &&
sha256sum -c SHA256SUMS &&
install -Dm755 orbit-linux-x86_64 ~/.local/bin/orbit
```
After that, `orbit self-update` keeps it current from the registry (see
[Updating Orbit](#updating-orbit)).
`just build-musl` makes the same binary locally in `dist/`. It needs `zig`,
`perl`, `make`, and `curl`. [scripts/build-musl.sh](scripts/build-musl.sh) compiles
MoonBit's C output and a pinned OpenSSL with `zig cc -target x86_64-linux-musl`.
`moonbitlang/async` normally loads OpenSSL with `dlopen`, which static binaries
can't do, so [openssl_static.c](scripts/musl/openssl_static.c) supplies the
linked-in functions instead.
## Updating Orbit
```sh
orbit self-update # newest orbit in its channel, if newer than this one
orbit self-update '~0.1' # newest build matching a constraint (can go back)
```
Orbit is the `orbit` package in `main`, built by orbit-packages whenever the
version in `moon.mod` changes.
- An Orbit installed some other way (`just install`, the rolling release) is
replaced where it runs, such as `~/.local/bin/orbit`. It downloads the
package, checks that the new binary runs and reports the version it should,
then swaps it in with one rename. Nothing is added to your installed
packages, and the download is deleted afterwards. `orbit upgrade orbit` does
the same when `orbit` isn't an installed package.
- An Orbit installed with `orbit install orbit` is upgraded like any other
package, so `orbit rollback orbit` still works.
- It uses the channel `orbit` is installed from, else the usual channel
priority. The directory holding the binary must be writable by you.
## Building
```sh
moon build --target native --release
moon test --target native # unit and mock-registry tests
just prove # proofs of src/kernel (needs an SMT solver: z3, cvc5 or alt-ergo)
# the binary is _build/native/release/build/main/main.exe
```
Or run `just install` to build and copy the binary to `~/.local/bin/orbit`.
It also adds Orbit's package bin directory to `~/.bashrc` if the setup line
isn't already there. Open a new Bash shell or run `source ~/.bashrc` to pick
up the change in your current shell. `~/.local/bin` must already be on `PATH`
to run `orbit` itself by name.
Linux only for now: arguments come from `/proc/self/cmdline`. It needs `tar` and `/bin/sh` on `PATH`.
### Package Orbit with Orbit
From the repo root, build and stage the `orbit` package. The package version
comes from `moon.mod`; publishing is a separate step.
```sh
package_dir=$(sh scripts/package-orbit.sh) &&
_build/native/release/build/main/main.exe publish "$package_dir"
```
This publishes to the `main` channel (use `--channel ` for another), so log in with `orbit login ` first if needed. The
package contains a native Linux binary for the build machine's architecture.
Use the same architecture on the install machine. `tar` is still a
system prerequisite; the package does not bundle it.
To bootstrap from source, install the published package with the binary you just
built. After adding Orbit's bin directory to `PATH`, use the installed binary
for future upgrades and rollbacks:
```sh
bootstrap=_build/native/release/build/main/main.exe
"$bootstrap" install orbit
eval "$("$bootstrap" env)"
orbit self-update # same as `orbit upgrade orbit` here
# If needed: orbit rollback orbit
```
## Layout
`src/kernel/` holds the code whose behaviour is proved rather than tested: number
parsing, version ordering and constraints, sorting, and solver literals. See its
[README](src/kernel/README.md).
```
src/main/
stub.c C glue: time, termios echo toggle, getenv, symlink, stderr, exit
sys.mbt FFI bindings, UTF-8, string helpers, spinner, atomic writes
sha256.mbt streaming FIPS 180-4 SHA-256 (+ tests)
auth.mbt credentials store (~/.orbit/auth.json + Docker config fallback)
oci.mbt OCI Distribution v2 HTTP transport, Bearer/Basic auth, redirects
semver.mbt versions, relational/compound constraints, parsing over src/kernel (+ tests)
model.mbt orbit.json / state.json / config.json (+ tests)
registry.mbt OCI registry ops: tags, resolve, cached manifests, fetch, publish, login
index.mbt channel index: build, publish, read (+ tests)
index_cache.mbt local copies of channel listings for search and info (+ tests)
details.mbt package details shown by install and info (+ tests)
solver.mbt lazy Resolvo-style CDCL SAT solver & UNSAT explainer (+ tests)
ops.mbt SAT-backed global install/upgrade, remove/rollback/gc/search
project.mbt orbit.toml, orbit.lock, .orbit/ environments, project CLI (+ tests)
conflicts.mbt declared conflicts, replacing installed packages (+ tests)
channels.mbt config.toml, channel priority and lookup (+ tests)
self_update.mbt replacing the running orbit with a newer build
main.mbt CLI
registry_wbtest.mbt mock-OCI registry, SAT global, and project workflow tests
```
## Planning
The backlog lives in [`planning/`](planning/), managed with
[means](https://github.com/hmans/means). Browse it with
`means tui --path ./planning`.
## Toolchain notes
Fixes needed for current MoonBit, kept here in case you build with an older compiler:
- The project uses `moon.mod` / `moon.pkg` (the `.json` forms are no longer accepted).
- `suberror OrbitError { OrbitError(String) }`, and `@json` is imported explicitly in `moon.pkg`.
- `Json` values are built with `Json::string`, `Json::array`, `Json::object`, `Json::boolean`; the uppercase constructors are only used in patterns.
- C FFI parameters are annotated `#borrow(...)`, matching `stub.c`, which never decrefs its arguments.
## Known limits
- There's no lock file for concurrent runs, and no install hooks, by design.
- `orbit gc` only preserves global current and rollback builds (run `orbit install` / `orbit sync` in a project to re-populate missing store entries from its `orbit.lock`).
- `orbit info ` reads installed package details (the project's, then the global ones) without contacting the registry. A package that isn't installed, or `orbit info [channel::]@` for another build, is looked up in the same cached channel listings as `orbit search`: it shows the newest version's description, documentation link, digest, bins, dependencies and conflicts. With the digest from the index and the config blob in the manifest cache, a repeated `info` needs no network; another version, or an index without digests, is resolved in the registry. Use `orbit versions ` to list published versions.
- `search` needs a channel index or the registry's catalog API (Gitea has it, also without a login). Otherwise use `orbit versions `.