Skip to content

Repository files navigation

moonbit-overlay

Binary distributed MoonBit toolchains.

NOTE: moonbit-compiler was already open sourced, BUT only wasm-gc backend is available. Considering this is an incomplete compiler and the version is quite lagging, this project will still only be able to use patched pre-built binaries for a long time.

Quick Start

Run moon in one line

nix run github:moonbit-community/moonbit-overlay#moon

List all available binaries

nix run github:moonbit-community/moonbit-overlay#<tab>

Create devshell from template

nix flake init -t github:moonbit-community/moonbit-overlay

Features

  • build from source in future.
  • versioning!
  • patchelf works :)

Example

flake with overlay

{
  description = "A startup basic MoonBit project";

  inputs = {
    flake-parts.url = "github:hercules-ci/flake-parts";
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

    devshell.url = "github:numtide/devshell";
    moonbit-overlay.url = "github:moonbit-community/moonbit-overlay";
  };

  outputs = inputs@{ flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      imports = [
        inputs.devshell.flakeModule
      ];

      perSystem = { inputs', system, pkgs, ... }: {
        _module.args.pkgs = import inputs.nixpkgs {
          inherit system;
          overlays = [ inputs.moonbit-overlay.overlays.default ];
        };

        devshells.default = {
            packages = with pkgs; [
              moonbit-bin.moonbit.latest
            ];
          };
      };

      systems = [
        "x86_64-linux"
        "aarch64-darwin"
        "x86_64-darwin"
      ];
    };
}

MoonBit project builds and Mooncakes dependency packaging are handled by moon-nix. This repository only distributes MoonBit toolchains.

Bundled MoonBit Toolchains

moonbit-bin.moonbit.latest

MoonBit LSP (distributed with compiler)

The moonbit-bin.moonbit.${version} package already includes the language server. Invoke it through moon lsp; current toolchains dispatch that command to the bundled moon-lsp executable.

moonbit-bin.moonbit.latest

Moonx (executable package runner)

Like the official installer, the toolchain also ships moonx as a symlink to moon. The moon binary selects the moonx CLI when it is invoked under the name moonx, so moonx runs packages from the Mooncakes registry without installing them:

nix run github:moonbit-community/moonbit-overlay#moonx -- user/module/package
nix run github:moonbit-community/moonbit-overlay#moonx -- kokic/fakefetch/cli/ffetch

Version

latest

moonbit-bin.moonbit.latest

nightly

moonbit-bin.moonbit.nightly

nightly is a rolling channel that tracks the upstream nightly build (the same one the official installer fetches with install.sh nightly).

specific version

moonbit-bin.moonbit.v0_1_20241031-7204facb6

Check available versions in the directory.

The original version of MoonBit is written as v0.1.20241031+7204facb6, for convenience, we escape it to format like v0_1_20241031-7204facb6.

legacyPackages & packages

The overlay now provides both legacyPackages and packages attributes:

  • legacyPackages: This is the original, structured attribute set. Packages are grouped by type (e.g., moonbit, cli, core) and version, making it easier to navigate the package hierarchy.
  • packages: This is a flattened attribute set, where each package is exposed as a single attribute (e.g., moonbit_latest, cli_v0_1_20241031-7204facb6). This structure is required for nix flake check to work correctly, as it expects all packages to be directly accessible under the packages attribute.

Both are provided to maintain compatibility and usability: use legacyPackages for structured access, and packages for flake checks and direct access.

Some deprecated packages are still exposed for compatibility; attempting to use them will show a warning and prevent building.

TODO

  • overridable
  • build from source (core) see pull#10
  • re-support legacy default.nix

Inspiration

The moonbit-overlay is heavily inspired by rust-overlay.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Reproducible nix overlay of binary distributed MoonBit toolchains and LSP

Resources

Stars

25 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages