# Toolchains with mise

IDEs and coding agents run whatever their users work with: node, python, go,
uv, gh, a language server, in the version each project wants. The runtime has
few of those, and packaging them one by one never catches up.
[`org.flatpark.Mise`](../../registry/org.flatpark.Mise/flatpark.yml) is a
[shared extension](extensions.md#shared-extensions) that gives an app
[mise](https://mise.jdx.dev/) instead. Users install tools with it themselves,
for the app or per project, as they would on the host, and the tools run
inside the app's sandbox.

- **Each app has its own.** Tools, settings and caches live in the app's
  `~/.var/app/<app-id>/`. Only the mise binary is shared; nothing an app
  installs reaches another app. A project's `mise.toml` is in the project, so
  every app that opens it picks the same versions.
- **It installs with the app.** Flatpak installs the extension with the first
  app that declares it; the others use the same copy.
- **It adds no permission.** Downloads use the app's own network access, and
  tools run with the app's permissions. An app without `--share=network`
  can't install anything.
- **It can carry a tool the app calls, too.** OpenIDEA gets the uv it
  installs Python language servers with from mise, as a
  [suggested tool](#suggested-tools), instead of a pinned download the
  package keeps up to date. The user gets it with one `mise install`, as they
  would install uv themselves next to OpenIDEA outside Flatpak, and the
  feature stops when they switch mise off: say both on the app's page. A tool
  the app can't start without stays in the package. So does a tool the app
  calls when it has no terminal of its own: its users have no natural place
  to run `mise install`, and the tool would never arrive.
- **Apps without a terminal can have it too.** Users then install tools
  from the host (`flatpak run --command=mise <app-id> …`) or from Parkland.
  An agent that runs shell commands is its own terminal: it can run
  `mise use -g <tool>` itself once it knows to, so say on its page that users
  can tell it so in their instructions (AGENTS.md or the app's own).

## Using it

Declare the extension point, create its directory, and put mise first in
`PATH`:

```yaml
finish-args:
  - --share=network
  - --env=PATH=/app/lib/flatpark-mise/bin:/var/data/mise/shims:/app/bin:/usr/bin
add-extensions:
  org.flatpark.Mise:
    directory: lib/flatpark-mise
    version: '1'
modules:
  - name: app
    buildsystem: simple
    build-commands:
      - mkdir -p /app/lib/flatpark-mise
      # ...
```

- `/app/lib/flatpark-mise/bin` holds `mise`, a wrapper that sets mise up for
  the sandbox and runs the real binary. mise's shims are symlinks to the mise
  that made them, so every tool call goes through the wrapper too.
- `/var/data/mise/shims` is where mise puts the app's tools (`/var/data` is the
  app's `~/.var/app/<app-id>/data` inside the sandbox). It comes before
  `/app/bin` and `/usr/bin`, so a version the user picked wins over the
  runtime's and the package's.
- Keep `/app/bin` and `/usr/bin`, and add the app's own entries if it had a
  `PATH` of its own. The PATH is set in `finish-args`, not in a launcher: it
  then reaches every process, including `flatpak run --command=…`.
- The same rules as for any shared extension apply: no `no-autodownload`, no
  `autodelete: true`, and the `mkdir` is required.

Say so on the app's page, with the commands to switch it off and on (as in
[OpenIDEA's metainfo](../../registry/ai.l0ng.openidea/ai.l0ng.openidea.metainfo.xml)).

## What users do

[Tools inside an app with mise](../users/mise.md) is the users' page: using
mise in the app and from the host, projects (folder access, `mise trust`,
`mise install` per app), the `FLATPARK_MISE=off` switch, and what mise can't
do. Link it from the app's page rather than repeating it.

mise installs tools, not the system libraries and headers that building
some code needs (the distribution's `-dev` packages). An IDE or agent whose
users build native code belongs on the Sdk
([development tools](formats/README.md#development-tools)), which has a
compiler, `pkg-config` and many headers; toolchains that come as Sdk
extensions are loaded with the
[shared SDK extension launcher](../../registry/_shared/sdk-extension-launcher.sh).

## Suggested tools

A package can suggest tools in `/app/share/flatpark/mise/config.toml`, an
ordinary mise config. The first time mise runs in the app, the wrapper copies
it into the app's own mise config, as `conf.d/flatpark.toml` under
`~/.var/app/<app-id>/config/mise/`, and leaves a marker so that it never does
again. From then on the tools are the user's, like any other: `mise install`
installs them, `mise use -g <tool>@<version>` changes one, `mise unuse -g
<tool>` removes it, and a removed tool doesn't come back. A later change to
the suggestions reaches only users who haven't run mise yet.

```yaml
      - install -Dm644 mise.toml /app/share/flatpark/mise/config.toml
```

Nothing is installed before the user runs mise: say on the app's page that
`mise install` gets the suggested tools. Suggest only what the app calls or
most of its users want; anything else is one `mise use` away. OpenIDEA's
[`mise.toml`](../../registry/ai.l0ng.openidea/mise.toml) is the example.

## A guide on the first start

The extension ships a short guide for users,
`/app/lib/flatpark-mise/share/doc/mise.md`: mise in the app, projects, the
switch, what it doesn't do, and a link to the full page. An editor or IDE
opens it once, on its first start, the way Flathub's VS Code opens its
Flatpak notes. The launcher does it, since only it knows how the editor opens
a file:

- skip it when the guide isn't there or `FLATPARK_MISE` is off;
- leave a marker in `$XDG_CONFIG_HOME` (`flatpark-mise-guide-shown`), so that
  it opens once;
- open it the editor's way: an extra path argument for an editor that takes
  one at launch, or its command-line client once the app is up.
  [OpenIDEA's launcher](../../registry/ai.l0ng.openidea/openidea-wrapper)
  waits for the app's socket, then runs `openidea --cli <guide>`.

The guide changes with the extension, without rebuilding the apps. An app
without an editor has no such step; its page links to
[the users' page](../users/mise.md).

## For agents

### What the audit checks

`audit-descriptor.mjs` (G8, constants in `scripts/flatpark-mise.mjs`) fails an
app that declares `org.flatpark.Mise`, or whose `PATH` names
`/app/lib/flatpark-mise`, when:

- it doesn't declare the extension point, or declares it with a `version`
  other than `1` or a `directory` other than `lib/flatpark-mise`;
- the point has `autodelete: true` or `no-autodownload: true`;
- no build command does `mkdir -p /app/lib/flatpark-mise`;
- `finish-args` set no `PATH`, or one that doesn't start with
  `/app/lib/flatpark-mise/bin`, lacks `/var/data/mise/shims`, drops `/app/bin`
  or `/usr/bin`, or puts either before the shims.

### The wrapper

`registry/org.flatpark.Mise/mise-wrapper.sh` is the extension's `bin/mise`,
next to the real binary in `extra/bin/mise`. With `FLATPARK_MISE=off` it
hands a tool's call to the next command of that name on `PATH` past mise's
own directories and stops. Otherwise it drops the variables a mise on
the host leaves in the environment (`flatpak run` passes them in: shell-hook
state, directories pointing at the host's installs, `GOROOT`), points mise's
data at `/var/data/mise` (the folder `PATH` names), copies the package's
suggested tools once into the app's mise config, turns self-update off and
disables
the asdf and vfox backends, which run plugin scripts; a value the user sets
with `flatpak override --env` is kept. Then it runs the binary with
`exec -a "$0"`, so a shim call reaches mise under the tool's name. A fix to it
ships with the extension, without rebuilding the apps.