Building from source
Requirements:
Clone the Mitos GitHub repository into a directory of your choice. The
examples in this documentation assume installation into either ~/src/ on
Linux and macOS, or %userprofile%\src\ on Windows.
- The Rust toolchain, version 1.97.1 or newer
- The Git version control system
- A C++14 compatible compiler to build the tree-sitter grammars, for example GCC or Clang
If you are using the musl-libc standard library instead of glibc the following environment variable must be set during the build to ensure tree-sitter grammars can be loaded correctly:
export RUSTFLAGS="-C target-feature=-crt-static"
-
Clone the repository:
git clone https://github.com/mitos-editor/mitos cd mitos -
Build and install:
cargo xtask installThis installs
ms(ms.exeon Windows) with its themes, syntax highlighting, and dictionaries. The default installation directory is~/.cargo/bin. Add it to yourPATHif needed.If you set
CARGO_INSTALL_ROOTorCARGO_HOME, Mitos uses that directory’sbin/folder instead, preferringCARGO_INSTALL_ROOTwhen both are set. To choose another installation directory or build profile:cargo xtask install --root ./mitos-install --profile optThis example installs into
./mitos-install/bin. Run the install command again after updating the repository to upgrade Mitos. Keep custom themes and queries in your configuration directory so they are preserved when upgrading.If installation stops because
bin/runtime/belongs to another installation, choose another--rootor move that runtime before trying again.
cargo xtask install explicitly fetches and compiles the configured grammars
before building and installing the editor.
To build without installing, prepare the grammars once, then build the executable:
cargo run --locked --package grammar-build --bin grammar-fetch
cargo run --locked --package grammar-build --bin grammar-build
cargo build --release --locked
The executable is written to target/release/ms. Ordinary cargo build,
cargo check, and cargo test commands do not fetch or compile grammars.
Repeat the explicit grammar commands after changing grammar sources or pins.
Set up the runtime files as described below.
When cross-compiling, pass -- --target <target-triple> to the grammar-build
command and --target <target-triple> to cargo build. The host runs the grammar
builder using the target’s C/C++ compiler.
💡 Tree-sitter grammars can be fetched and compiled if not pre-packaged. Fetch grammars with
ms --grammar fetchand compile them withms --grammar build. Installed commands write them to theruntimedirectory within the user’s Mitos data directory (more details below).
💡 If you only want to build some grammars, see
use-grammars
Configuring Mitos’s runtime files
cargo xtask install sets up the runtime for you. Follow these steps if you
build without installing, or want to use themes and queries directly from the
source directory while developing Mitos.
Linux and macOS
The runtime directory is one below the Mitos source, so either export a
MITOS_RUNTIME environment variable to point to that directory and add it to
your ~/.bashrc or equivalent:
export MITOS_RUNTIME=~/src/mitos/runtime
Or, create a symbolic link in the data directory if it does not already exist:
mitos_data_dir="${XDG_DATA_HOME:-$HOME/.local/share}/mitos"
mkdir -p "$mitos_data_dir"
ln -s "$PWD/runtime" "$mitos_data_dir/runtime"
Run this from the repository root. Review an existing runtime directory before replacing it, since it may contain your own queries or dictionaries.
Windows
Either set the MITOS_RUNTIME environment variable to point to the runtime files using the Windows setting (search for
Edit environment variables for your account) or use the setx command in
Cmd:
setx MITOS_RUNTIME "%userprofile%\src\mitos\runtime"
💡
%userprofile%resolves to your user directory likeC:\Users\Your-Name\for example.
Or, create a symlink in %appdata%\mitos\ that links to the source code directory:
| Method | Command |
|---|---|
| PowerShell | New-Item -ItemType Junction -Target "$Env:USERPROFILE\src\mitos\runtime" -Path "$Env:AppData\mitos\runtime" |
| Cmd | cd %appdata%\mitos mklink /D runtime "%userprofile%\src\mitos\runtime" |
💡 On Windows, creating a symbolic link may require running PowerShell or Cmd as an administrator.
Multiple runtime directories
When Mitos finds multiple runtime directories it will search through them for files in the following order:
- The workspace’s
runtime/directory when running through Cargo. runtime/subdirectory of OS-dependent mitos user config directory.$MITOS_RUNTIMEruntime/subdirectory of the user data directory:$XDG_DATA_HOME/mitos/runtime(normally~/.local/share/mitos/runtime) on Linux and macOS. On Windows, the data and config runtime directories are both%AppData%\mitos\runtime.- Distribution-specific fallback directory (set at build time with
MITOS_DEFAULT_RUNTIME). runtime/subdirectory of path to Mitos executable.
This order also sets the priority for selecting which file will be used if multiple runtime directories have files with the same name.
For manual runtime installation, use the data runtime directory. The source
installer places the runtime beside the executable. Keep personal query
or dictionary overrides in the config runtime directory, which takes priority.
Custom themes can also live in the config directory’s themes/ folder.
ms --grammar fetch and ms --grammar build write grammar sources and compiled
grammars into the user data directory’s runtime/ subdirectory. When run through
Cargo, they write into the current source checkout’s runtime/ instead. MITOS_RUNTIME changes where assets are read, not
where these commands write.
Migrating an existing config runtime
Existing config runtimes remain supported and take priority over the data runtime. Mitos does not move or delete them automatically.
On Linux and macOS, you can move installed runtime assets from
~/.config/mitos/runtime to ~/.local/share/mitos/runtime, or change an existing
runtime symlink to live there. Use the corresponding directories if you set
XDG_CONFIG_HOME or XDG_DATA_HOME. Review both locations first and keep personal
overrides in the config runtime. On Windows, the config and data runtime paths
are the same, so no move is needed.
If an older grammar remains in the config runtime, it will override a newly
built grammar in the data runtime. Move or remove that older installed grammar
when switching to the data runtime. Run ms --health to inspect runtime paths
and grammar availability after migrating.
Note to packagers
If you are making a package of Mitos for end users, to provide a good out of
the box experience, you should set the MITOS_DEFAULT_RUNTIME environment
variable at build time (before invoking cargo build) to a directory which
will store the final runtime files after installation. For example, say you want
to package the runtime into /usr/lib/mitos/runtime.
Since Mitos 0.2.0, cargo build no longer fetches or compiles grammars. When
updating an older package recipe, add both explicit grammar commands before
copying the runtime. A runtime with queries but no compiled grammars cannot
provide syntax highlighting, even if the query columns in ms --health show
checkmarks.
The rough steps a build script could follow are:
export MITOS_DEFAULT_RUNTIME=/usr/lib/mitos/runtime- Fetch and compile grammars with the explicit commands above.
cargo build --profile opt --lockedcp -r runtime $BUILD_DIR/usr/lib/mitos/cp target/opt/ms $BUILD_DIR/usr/bin/ms
This way the resulting ms binary will always look for its runtime directory in
/usr/lib/mitos/runtime for files not provided by the user’s config runtime,
MITOS_RUNTIME, or data runtime.
Validating the installation
To make sure everything is set up as expected you should run the Mitos health check:
ms --health
The command reports runtime, clipboard, language-server, and grammar status.
Configure the desktop shortcut
If your desktop environment supports the
XDG desktop menu
you can configure Mitos to show up in the application menu by copying the
provided .desktop file:
mkdir -p ~/.local/share/applications ~/.local/share/icons/hicolor/scalable/apps
cp contrib/Mitos.desktop ~/.local/share/applications
cp book/theme/favicon.svg ~/.local/share/icons/hicolor/scalable/apps/Mitos.svg
It is recommended to convert the links in the .desktop file to absolute paths to avoid potential problems:
sed -i -e "s|Exec=ms %F|Exec=$(readlink -f ~/.cargo/bin/ms) %F|g" \
~/.local/share/applications/Mitos.desktop
To use another terminal than the system default, you can modify the .desktop
file. For example, to use kitty:
sed -i "s|Exec=ms %F|Exec=kitty ms %F|g" ~/.local/share/applications/Mitos.desktop
sed -i "s|Terminal=true|Terminal=false|g" ~/.local/share/applications/Mitos.desktop
Building the Debian package
If the .deb file provided on the release page uses a libc version higher
than that used by your Debian, Ubuntu, or Mint system, you can build the package
from source to match your system’s dependencies.
Install cargo-deb, the tool used for building the .deb file:
cargo install cargo-deb
After cloning and entering the Mitos repository, fetch and compile grammars with
the explicit commands above. Then build the release binary and package it into a
.deb file in a single step:
cargo deb -- --locked
The default uses the release profile. To package an already built
target/release/ms, run cargo deb --no-build.
The package is written to target/debian/. It includes the executable, runtime,
shell completions, desktop entry, and launcher.
Using Mitos as a Nix flake input
With flakes enabled, add Mitos to your flake inputs and use its default package.
The stable branch points to the latest release. To follow unreleased changes,
use github:mitos-editor/mitos/main instead. To pin one release, use its tag,
such as github:mitos-editor/mitos/v0.2.1.
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
mitos.url = "github:mitos-editor/mitos/stable";
mitos.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { nixpkgs, ... } @ inputs:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in {
devShells.${system}.default = pkgs.mkShell {
packages = [ inputs.mitos.packages.${system}.default ];
};
};
}
Replace system with your target platform. The same package can be included in
Home Manager’s home.packages or NixOS’s environment.systemPackages.