---
title: "Building from Source"
description: "How to test and build Genesis from source — the Phoenix dev server, the Tauri desktop app, the Nix dev shell, and the signed macOS build flow."
sidebar:
order: 2
---
# Building from Source
This page covers local development on a current (v0.15.0) Genesis checkout: running the Phoenix dev server and its development tasks, building the Tauri desktop app, using the Nix dev shell, and producing a signed, notarized macOS app. If you are packaging Genesis for a Linux or BSD distribution, the [packaging guide](/developer/packaging) covers the maintainer workflow — this page targets local development.
{/* 前置要求 */}
## Prerequisites
{/* Genesis 使用 Elixir 1.20.4 和 Erlang/OTP 29 开发和发布。 */}
Genesis is developed, tested, and released on **Elixir 1.20.4** with **Erlang/OTP 29**. Those are the pins in `.github/workflows/ci.yml` (`ELIXIR_VERSION` / `OTP_VERSION`), in the desktop release workflow `build-desktop.yml`, and in `flake.nix` (`erlang_29` extended with `elixir_1_20`). Use them for local work.
{/* 各应用的 mix.exs 版本约束更宽松,只用于依赖解析。 */}
The per-app `elixir:` constraints in this umbrella are looser than the pins — `~> 1.18` in `apps/evo_git/mix.exs`, `~> 1.15` in `apps/evo_dash/mix.exs` — so they only gate dependency resolution; the toolchain the project is actually verified on is the CI pin. One trap is worth knowing: nixpkgs' `erlang_29` package set defaults to Elixir 1.18, which cannot compile the app, which is exactly why the flake extends it to Elixir 1.20.
{/* 使用 asdf 或 mise 安装 Elixir 和 Erlang。 */}
Install the toolchain with asdf or mise:
```bash
# asdf
asdf plugin add erlang && asdf plugin add elixir
# mise
mise use erlang@29 elixir@1.20.4
```
The repository does not track a `.tool-versions` file — pinning `erlang 29` / `elixir 1.20.4` in your own is a local convenience. If you use Nix, the dev shell provides both versions directly (see [NixOS dev shell](#nixos-dev-shell)).
Other install routes: the official installers at [elixir-lang.org/install.html](https://elixir-lang.org/install.html) (the most reliable way to get exactly 1.20.4), `brew install elixir` on macOS, `sudo apt install elixir erlang-dev` on Ubuntu/Debian, `sudo pacman -S elixir` on Arch, `sudo dnf install elixir` on Fedora. Distro packages often lag the pin — check `elixir --version` before chasing a build error.
{/* 从源码运行 Phoenix 开发服务器 */}
## Run the Phoenix dev server from source
```bash
git clone https://github.com/EMI-Group/genesis.git
cd genesis
mix deps.get
mix assets.setup
mix phx.server
```
{/* 然后打开 http://127.0.0.1:4100。 */}
Then open **http://127.0.0.1:4100**. `config/dev.exs` binds `{127, 0, 0, 1}` and reads the port from the `PORT` environment variable with `4100` as the fallback, so `PORT=4200 mix phx.server` moves it.
<Aside type="note">
On a fresh checkout, run `mix deps.get` first. `mix assets.setup` is the `evo_dash` alias that only runs `tailwind.install --if-missing` and `esbuild.install --if-missing` — it needs dependencies present. `mix assets.deploy` (`tailwind --minify`, `esbuild --minify`, `phx.digest`) is only needed for a production release such as the desktop build below.
</Aside>
{/* 连接 MCP 客户端 */}
### Connect an MCP client (optional)
{/* 同一个 Phoenix 服务器还提供本地 MCP 端点,无需第二个监听端口。 */}
The same Phoenix server — in the dev server and in released builds alike — exposes a local MCP endpoint at `/mcp`, so a coding agent can drive Genesis through its own tools. It is part of the running server: no second listener, no separate daemon, and it stays disabled until a credential file exists:
- Create `mcp-token` in the Genesis configuration directory (per-OS locations: [config.toml Reference](/config/config-file)) with at least 32 random URL-safe characters and no whitespace, mode `0600` on POSIX.
- Connect over Streamable HTTP with `Authorization: Bearer <token>`.
- Call `genesis_check` first, then the task tools (`genesis_start_task`, `genesis_get_task`, `genesis_list_tasks`, …).
{/* 端点只接受回环地址的请求,令牌在每次请求时读取。 */}
Requests are accepted only from loopback (peer address and `Host` both `127.0.0.1`/`::1`), with a same-origin `Origin` when one is sent, `POST` only, `Content-Type: application/json`, an `Accept` header covering `application/json` and `text/event-stream`, and a body of at most 1 MiB. Protocol versions `2025-11-25` and `2025-06-18` are supported. The token is read per request, so creating it needs no restart. The endpoint is deliberately local-only: it does not expose a remote project to a cloud agent.
{/* 额外的开发任务 */}
## Development tasks
| Command | What it runs |
|---------|--------------|
| `mix test` | Both umbrella suites in one VM (`apps/evo_git`, `apps/evo_dash`); the CI matrix runs them per app so they run in parallel |
| `cd apps/<app> && mix test` | One app's suite — passing an app path from the root (`mix test apps/evo_git`) silently runs no tests |
| `mix precommit` | The `evo_dash` alias: `compile --warning-as-errors`, `deps.unlock --unused`, `format`, `test` |
| `mix format --check-formatted` | The root `.formatter.exs` declares `subdirectories: ["apps/*"]`, so one check covers the whole umbrella |
| `MIX_ENV=test mix compile --warnings-as-errors` | The CI compile-warnings gate |
| `mix bench.io` | Filesystem and git I/O benchmark — see below |
{/* 文件系统与 git I/O 基准测试 */}
### Benchmark filesystem and git I/O
{/* mix bench.io 测量代理实际执行的 I/O 路径。 */}
`mix bench.io` (v0.14 and later) measures the I/O paths agents actually exercise — worktree add/remove, file reads and writes, `git status` / `add` / `commit` — over a throwaway synthetic repository. It measures only and never boots the Genesis runtime (no store, task registry, or scheduler), so it is safe in any working copy; the bench root is removed afterwards unless `--keep` is passed.
```bash
mix bench.io # 5 counted cycles in the system temp dir
mix bench.io --dir /mnt/nvme -n 10 --files 500 --writes 50
mix bench.io --json > bench.json # JSON report only, for regression tracking
```
| Flag | Meaning |
|------|---------|
| `--dir PATH` | Where the bench root is created (default: system temp dir) — this decides filesystem locality, so compare results on the same mount only |
| `--iterations N`, `-n` | Counted cycles (default: 5) |
| `--warmup N` | Discarded cycles before the counted ones (default: 1) |
| `--files N` / `--writes N` / `--reads N` | Seed files (200), files written (20) and files read (20) per cycle |
| `--file-size BYTES` | Payload size per written file (default: 4096) |
| `--fsync` | `:file.sync` every written file, to measure durable writes |
| `--json` / `--keep` / `--label STRING` | JSON-only report, keep the bench root, label recorded in the report |
`mix bench.io --help` prints the full flag list; invalid values are rejected before anything is written to disk.
{/* 在本地构建并测试 Tauri 桌面应用 */}
## Build and test the Tauri desktop app locally
The desktop app is a Tauri v2 shell: it launches the Elixir `genesis_desktop` release as a child process, waits for it to be ready, and opens the dashboard in a native WebView. Building it locally needs a Rust toolchain and the Tauri CLI in addition to the prerequisites above.
The canonical manual sequence below is the one the Nix dev shell prints in its `shellHook`; the same steps apply on any distro with the [Linux runtime dependencies](#linux-runtime-dependencies) installed.
<Steps>
<Step>
### Fetch Elixir dependencies
Run `mix deps.get` at the repository root.
</Step>
<Step>
### Build and digest the frontend assets
Run `mix assets.setup && mix assets.deploy`.
</Step>
<Step>
### Install the Tauri CLI
Run `cargo install tauri-cli --version "^2.0"` — first time only. `tauri-cli` is not packaged in nixpkgs; CI installs the pinned npm CLI instead.
</Step>
<Step>
### Bundle vendor binaries
Run `./nix/bundle-vendor.sh` — it downloads ripgrep (15.2.0) and copies the system `git` into `apps/evo_git/priv/vendor/<platform>/`. Its defaults detect the Linux host; `--target` and `--vendor-platform` name another triple.
</Step>
<Step>
### Build the Elixir release
Run `MIX_ENV=prod mix release genesis_desktop` (add `--overwrite` when rebuilding over an existing release).
</Step>
<Step>
### Place the release directory where Tauri expects it
Run `rm -rf desktop/src-tauri/resources/genesis-backend && cp -a _build/prod/rel/genesis_desktop desktop/src-tauri/resources/genesis-backend`.
</Step>
<Step>
### Build the Tauri desktop app
Run `cd desktop/src-tauri && cargo tauri build`.
</Step>
</Steps>
{/* 已知问题:Tauri 构建要求资源目录预先存在 */}
<Aside type="caution">
**Known gotcha:** `tauri.conf.json` lists `resources/genesis-backend` under `bundle.resources`, and `tauri-build` resolves that path when `build.rs` runs — if the directory is missing the build fails with `resource path 'resources/genesis-backend' doesn't exist`. This is why step 6 must precede step 7. The directory is gitignored (the parent keeps only a `.gitkeep`); for a bare `cargo check` without a full release build, `mkdir -p desktop/src-tauri/resources/genesis-backend` is enough.
</Aside>
{/* Linux 运行时依赖 */}
### Linux runtime dependencies
At runtime the Tauri binary dlopens WebKitGTK, libayatana-appindicator, and librsvg, so on minimal systems they must be reachable. The Nix package wrapper handles `LD_LIBRARY_PATH` for you; for manual builds install the distro equivalents of `libwebkit2gtk-4.1-dev`, `librsvg2-dev`, `libayatana-appindicator3-dev`, `libssl-dev`, `libxdo-dev`, and `libdbus-1-dev`.
{/* 发布版还会加载 wx,用于原生目录选择器。 */}
The `genesis_desktop` release also loads `wx` (it is not a dependency of any app, so `mix.exs` lists it explicitly) for the dashboard's native directory picker — on Debian/Ubuntu that needs the wxWidgets GTK runtime, e.g. `libwxgtk3.2-1t64`. Without it the picker falls back to manual path entry.
{/* 开发模式流程与测试 */}
### Dev-mode flow and tests
What the desktop shell does at v0.15.0:
- The shell contains **no Elixir code — only Rust**. It resolves a backend port once at startup (`PORT` is honored only when it parses, is non-zero, and is currently free; otherwise a random free ephemeral port is picked — never a fixed default), then spawns `<resources>/genesis-backend/bin/genesis_desktop start` (`genesis_desktop.bat` on Windows) as a child process with `PORT=<resolved>`, `PHX_IP=127.0.0.1` (override with `EVOGIT_BIND`, e.g. `0.0.0.0`), `PHX_SERVER=true`, a local `SECRET_KEY_BASE`, `RELEASE_DISTRIBUTION=none`, `EVOGIT_DESKTOP=1`, and `EVOGIT_LIFETIME_PORT` when the lifetime listener could bind.
- The same resolved port drives the WebView URL and every readiness probe (the WebView always dials the IPv4 loopback literal `127.0.0.1`). First boot gets up to 90 seconds, and a loading page is shown while it waits. A backend watchdog restarts a crashed child with backoff, shows an error page while it is down, and reloads the dashboard on recovery; the lifetime pipe makes an orphaned backend exit if the shell dies.
- Closing the window hides the app to the system tray. The tray menu is **Show Window**, a separator, then **Quit Genesis**; on Windows and macOS a tray-icon left-click also reopens the window. Quit (and macOS Cmd+Q) asks the dashboard for confirmation when the backend is healthy and the dashboard is loaded, and otherwise kills the backend and exits. The shell logs its side of all this to `<data dir>/logs/shell.log`.
- There is **no documented hot-reload flow**: `beforeDevCommand`/`beforeBuildCommand` in `tauri.conf.json` are empty strings, and nothing in the repository documents `cargo tauri dev`. The documented dev/test path is the full sequence above — release, copy into `desktop/src-tauri/resources/genesis-backend/`, then `cd desktop/src-tauri && cargo tauri build`.
- A dev/test-only Docker image lives at `desktop/scripts/docker-dev/` — it builds the `genesis` release from a tagged revision fetched from GitHub on `elixir:otp-29` and serves the dashboard on port `9999`; see its README.
- **Tests:** `mix test` covers the Elixir side. The Rust unit tests for launcher-path resolution (`src/sidecar_path.rs`) and port resolution / watchdog decisions (`src/main.rs`, `src/backend_watchdog.rs`) run with `cargo test` from `desktop/src-tauri`. No `cargo clippy` invocation is documented.
{/* NixOS 开发环境 */}
## NixOS dev shell
`nix develop github:EMI-Group/genesis` (or just `nix develop` inside a checkout) provides Erlang/OTP 29, Elixir 1.20, the Rust toolchain (`cargo`, `rustc`, `rustfmt`, `clippy`), the build essentials (`gnumake`, `gcc`, `file`, `curl`, `ripgrep`, `git`), and all the Tauri native dependencies: `webkitgtk_4_1`, `gtk3`, `glib`, `glib-networking`, `librsvg`, `libayatana-appindicator`, `libsoup_3`, `openssl`, `xdo`, plus the runtime helpers `dconf`, `hicolor-icon-theme`, and `mesa` — with `pkg-config` in `nativeBuildInputs`, which is required so the Rust build can locate the WebKit/GTK libraries via their `*.pc` files.
The shell's `shellHook` exports three variables on Linux:
- `GIO_EXTRA_MODULES` — the glib-networking and dconf GIO modules, so GLib/GIO finds them at runtime (TLS support for WebKit HTTP requests and the GSettings backend).
- `WEBKIT_DISABLE_DMABUF_RENDERER=1` — a workaround for WebKit rendering issues under certain compositors.
- `__EGL_VENDOR_LIBRARY_DIRS` — points EGL at the flake's own `mesa`, because the host's vendor list starts with `/run/opengl-driver/...` and a host mesa built against a newer glibc fails to load inside the shell (`Could not create default EGL display`).
Inside the shell, the same 7-step flow above applies. Alternatively, `nix build .#desktop` builds the fully packaged app, `nix run .#desktop` runs it, and `nix run` builds and runs the CLI. `nix run .#desktop-smoke` is a manual, release-time smoke test that boots the packaged app and asserts the dashboard serves and shuts down cleanly. See also the [NixOS section of the Linux installation page](/getting-started/installation/linux).
{/* 构建 macOS 桌面应用 */}
## Build the macOS desktop app
For a signed, notarized `.app` (or `.dmg`) locally, use the helpers under `desktop/scripts/`. They package the Elixir `genesis_desktop` release into a Tauri shell.
### macOS prerequisites
- Xcode Command Line Tools (`xcode-select --install`)
- Rust (`rustup`) and the Tauri CLI: `cargo install tauri-cli --version "^2.0" --locked`
- Elixir 1.20.4 / OTP 29 (see [Prerequisites](#prerequisites))
- An Apple Developer ID Application certificate in your keychain, plus notarization credentials (App Store Connect API key or Apple ID)
{/* 配置签名与公证 */}
### Configure signing
```bash
cp desktop/scripts/.env.macos.example desktop/scripts/.env.macos
# Edit desktop/scripts/.env.macos — APPLE_SIGNING_IDENTITY plus notarization credentials
```
`desktop/scripts/.env.macos` is gitignored — do not commit secrets. The template defines two credential routes, and the script enforces that exactly one is complete: the App Store Connect API key (`APPLE_SIGNING_IDENTITY`, `APPLE_API_ISSUER`, `APPLE_API_KEY`, `APPLE_API_KEY_PATH`) or the Apple ID route (`APPLE_ID`, `APPLE_PASSWORD`, `APPLE_TEAM_ID`).
### Build
```bash
./desktop/scripts/build-macos-local.sh # no arguments: --bundles app
./desktop/scripts/build-macos-local.sh --bundles dmg
./desktop/scripts/build-macos-local.sh --bundles app,dmg
```
The script runs the Elixir side of the flow — `mix deps.get`, `mix assets.setup`, `mix assets.deploy`, `MIX_ENV=prod mix release genesis_desktop --overwrite` — copies the release into `desktop/src-tauri/resources/genesis-backend`, codesigns the nested Mach-O binaries (including the BEAM JIT entitlement), then runs `cargo tauri build`. With `dmg` in the bundle list it submits the DMG to Apple, staples the ticket, and verifies the signatures, notarization tickets, and Gatekeeper assessments before returning successfully. It does not bundle vendor binaries — the macOS CI job has its own per-platform vendor step.
Output:
- `.app`: `desktop/src-tauri/target/release/bundle/macos/`
- `.dmg`: `desktop/src-tauri/target/release/bundle/dmg/`
<Aside type="note">
Notarization contacts Apple and can take several minutes with little log output while `notarytool` waits.
</Aside>
{/* 辅助脚本 */}
The helper scripts live in `desktop/scripts/`: `build-macos-local.sh`, `sign-macos-nested.sh`, `notarize-macos-dmg.sh`, and `verify-macos-artifacts.sh`, plus `macos-beam.entitlements.plist` (the BEAM JIT entitlement).
{/* CI 所需的仓库密钥 */}
### CI (GitHub Actions)
The `build-macos-arm64` job in `.github/workflows/build-desktop.yml` imports the Developer ID certificate, signs the nested runtime with `sign-macos-nested.sh`, lets Tauri sign and notarize the app, then notarizes the DMG, staples the app, and verifies both artifacts before uploading them. Required repository secrets:
| Secret | Value |
|--------|-------|
| `APPLE_CERTIFICATE` | base64 of Developer ID Application `.p12` (`openssl base64 -A -in cert.p12`) |
| `APPLE_CERTIFICATE_PASSWORD` | password used when exporting the `.p12` |
| `APPLE_SIGNING_IDENTITY` | e.g. `Developer ID Application: Org (TEAMID)` |
| `APPLE_API_ISSUER` | App Store Connect Issuer ID |
| `APPLE_API_KEY` | App Store Connect Key ID |
| `APPLE_API_KEY_P8_BASE64` | base64 of `AuthKey_<KEYID>.p8` (`openssl base64 -A -in AuthKey_XXX.p8`) |
| `TAURI_SIGNING_PRIVATE_KEY` | minisign private key for the Tauri auto-updater artifacts (the job disables updater artifacts when it is missing) |
| `TAURI_SIGNING_PRIVATE_KEY_PASSWORD` | password for that key |
<Aside type="tip">
{/* 分发打包属于另一个流程,请参阅打包指南。 */}
Distribution packaging — the Linux/BSD packages and the `genesis_server` tarball — is a separate workflow, documented in the [packaging guide](/developer/packaging).
</Aside>