Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Plugin manifest

mochi-plugin.toml sits at the root of a plugin and says what it is, what it runs and what it offers. mochid reads it when it starts and on mochi reload; mochi plugins install reads it before installing, to show you. A key the manifest doesn’t know is an error, so typos don’t go unnoticed.

A complete one, from the pomodoro example:

# An example plugin: a focus timer. `mochi ipc pomodoro start` starts 25
# minutes of focus; a bubble counts down, and the island says when it's
# time for a break.

[plugin]
id = "pomodoro"
name = "Pomodoro"
version = "0.1.0"
description = "A focus timer: a bubble counts down, the island says when to rest"
authors = ["Mochi"]
api = 1

[backend]
exec = "bin/pomodoro"
# Its own target directory, so it builds the same inside the Mochi
# repository and in a repository of its own.
build = "cargo build --release --locked --target-dir target && install -Dm755 target/release/pomodoro bin/pomodoro"

[release]
asset = "pomodoro-{version}-{arch}-linux.tar.gz"

[bubbles]
area = "center-right"

[uses]
# With `pause_media`, a focus session pauses what's playing.
state = ["media"]

[[actions]]
name = "start"
description = "Start a focus session"
args = [{ name = "minutes", description = "How long, instead of focus_minutes", kind = "int", optional = true }]

[[actions]]
name = "break"
description = "Start a break"
args = [{ name = "minutes", description = "How long, instead of break_minutes", kind = "int", optional = true }]

[[actions]]
name = "pause"
description = "Pause or resume the timer"

[[actions]]
name = "stop"
description = "Stop the timer"

[[actions]]
name = "status"
description = "Print what the timer is doing"

[[contributions]]
target = "control-center"
kind = "card"
id = "timer"
view = "Card"
title = "Focus"
icon = "clock"
order = 60
options = { span = 1, rows = 1 }

[plugin]

Key
idrequiredIts name in config.toml, [module.<id>], mochi ipc <id> and Daemon.state("<id>"). Lowercase letters, digits, - and _, starting with a letter. It must match the id in plugins.toml, and can’t be a builtin module’s.
namerequiredWhat mochi plugins shows.
versionrequiredThe plugin’s own version, any text. plugins.lock records it, and {version} in a release asset’s name is it.
apirequiredThe protocol version the backend speaks: 1. mochid refuses a plugin with another.
descriptionOne line about it.
authorsA list of names.
homepageA URL.

[backend]

Leave it out for a plugin of views only, like one that only replaces a builtin view.

Key
execrequiredThe program mochid starts, relative to the plugin’s directory.
argsIts arguments.
buildA shell command that builds exec from source. mochi plugins install runs it with sh in the plugin’s directory for git: and path: sources, with MOCHI_PLUGIN_DIR set; never for git-release:, nor when Nix builds the plugin instead, see Building with Nix.
needsPrograms the backend runs, by command name, like ["python3", "ffmpeg"]. When Nix builds the plugin, they go on the backend’s PATH; otherwise install lists the missing ones and mochid warns about them when the plugin starts.
kindHow Nix builds the backend, when the plugin’s files don’t tell: rust, node, python, go or files. See below.

The backend starts in the plugin’s directory, with the socket to mochid as file descriptor 3. See the plugin protocol.

Building with Nix

Mochi can build a plugin with Nix, so people on NixOS, or without the plugin’s build tools, can use it: home-manager’s programs.mochi.plugins.<id>.src, and mochi plugins install when Nix is installed but the build’s tools or the needs aren’t. You write no Nix and no hashes: the build follows the lock file the plugin already has, found from its files, or from kind:

kindFound fromWhat Nix does
rustCargo.lockBuilds it with cargo, git dependencies included.
nodepackage-lock.jsonInstalls the dependencies, and runs npm run build when package.json has one.
gogo.modBuilds it with the dependencies in vendor/. Without vendor/ Nix would need a hash, so commit it (go mod vendor) or publish releases.
pythonpyproject.toml or requirements.txtRuns the backend with a Python that has its dependencies, from nixpkgs’ Python packages.
filesexec already thereUses the plugin as it is: a script, or a release archive with a built binary, which gets patched to find NixOS’s libraries.

In every case the backend ends up at exec, with the needs on its PATH and #!/usr/bin/env lines pointing at them. For compiled languages without a lock file Nix can read, like Java, publish releases: a release archive works as src too.

[release]

For git-release: sources.

Key
assetrequiredThe release asset’s file name. {id}, {version}, {tag} and {arch} are filled in; {arch} is x86_64 or aarch64.

The asset is a tar archive, compressed or not, holding the plugin as it should be installed, built exec included: at the archive’s root, or in its only directory.

[views]

KeyDefault
dir"qml"Where the views are, relative to the plugin’s directory.
overrides[]Builtin views it replaces, as "<module>/<view>". The plugin’s <dir>/overrides/<module>/<view>.qml takes the place of the module’s <view>.qml while both are enabled.

[uses]

KeyDefault
state[]Modules whose published state the backend receives, as state messages: once at the start, then on every change, and null when the module stops. A module that isn’t enabled sends nothing.

[bubbles]

Where the plugin’s bubbles go unless the user moves them. Settings › Bubbles shows the plugin there before its first bubble appears; without this table, the plugin shows up there only once it has shown one. Say the same area, group and order the backend’s show_bubble gives.

KeyDefault
arearequiredleft, center-left, center, center-right or right.
groupnoneShares a pill with the bubbles of the same group, like the builtin status.
order0Lower goes further left.
widefalseIt has a wide view with text, so the editor offers the “With text” switch.
[bubbles]
area = "right"

[[actions]]

One table per action mochi ipc <id> <action> runs. mochid checks the words typed against the arguments before the backend sees them, and mochi ipc <id> lists the actions with their help.

Key
namerequiredOne word.
descriptionrequiredOne line, for mochi ipc’s list.
argsA list of arguments, in order.

An argument:

KeyDefault
namerequiredThe name the backend reads it by.
description""One line.
kind"string"string, int, float, bool (true/false, on/off, yes/no) or choice.
choices[]The words a choice takes.
optionalfalseMay be left out; only trailing arguments can be optional.
restfalseTakes every remaining word, joined with spaces; only the last argument.
sourcenoneWhere its values come from, so the settings panel offers them in a menu when an option runs this action: output, app, desktop-id, player, control-center-page, audio-output and the others the builtin modules use.

The backend gets the arguments as an object: {"minutes": 25, "label": "Write"}. A left-out optional argument isn’t there.

[[contributions]]

What the plugin offers other modules, like a card or a page for the control center. The view gets the plugin’s published state as its payload.

Key
targetrequiredThe module it’s for, like control-center, or mochi for the shell itself.
kindrequiredWhat it is to the target: the control center takes card and page, the launcher provider, and the settings section, a view drawn on the module’s own page above its options. The shell, mochi, takes preload: a view it compiles while idle after starting, so the first time it shows doesn’t wait for that. A panel the plugin opens on the island is worth it; { offered = ["card"] } compiles the views other modules offer the plugin as those kinds with it.
idrequiredUnique among the plugin’s contributions.
viewThe view’s file name, without .qml. Kinds without a view, like a launcher provider, leave it out.
titlerequiredIts heading.
iconA Mochi symbol, like clock, or an icon theme name.
order0Lower comes first.
optionsAnything else the target reads, like { span = 2, rows = 1 } for a control center card two columns wide and one row tall. A card with rows gets a view sized to fill them, about 45 pixels tall for one row and 153 for two; without it, the control center measures the view. A control center card opens its plugin’s page when clicked; { page = "<id>" } picks which, when there are several. A launcher provider takes prefix, search and pick: see Launcher providers.

[settings]

How the settings panel shows the options in settings.toml. Each option’s kind and default come from its # key = value line there, and its description from the comment above the line. A [settings.<key>] table adds what the line can’t say. An option in a table is named with dots: [settings."cpu.notice"].

Key
choicesThe values it takes: the panel shows them to pick from.
min, maxA number’s range. With both, the panel shows a slider.
colorfalseA #rrggbb or #aarrggbb color, with a picker.
fontfalseA font family, picked from the fonts installed.
optionalfalseIt may be left unset.
descriptionIn place of the comment in settings.toml.
[settings.units]
choices = ["metric", "imperial"]

[settings.refresh_minutes]
min = 5
max = 120

An option without a table shows as its default’s kind: a switch, a number, a text field or a list. A table by default, like a map of names, is edited as TOML.

settings.toml

Not part of the manifest, but next to it by convention: the plugin’s [module.<id>] section with every setting commented out at its default, for users to copy into config.toml. The backend gets the section in hello, and the settings panel shows each setting from it.