Skip to content

Packaging plugins

withPlugins accepts plugins from pkgs.piBoltPlugins or derivations built elsewhere with buildPiBoltPlugin.

Consume a plugin that ships its own package

Section titled “Consume a plugin that ships its own package”

The payload reads only plugin.piBolt from a plugin derivation, so a plugin repository can build itself and export the result as its own flake package. That is the shape to prefer when it exists: the plugin’s repository owns its source, version, patches and npm dependencies, and its update step moves them together.

let
# pi-extensions is a flake input of the consuming configuration.
plugins = pi-extensions.packages.${pkgs.stdenv.hostPlatform.system};
in
pkgs.pi-bolt.withPlugins (_: [ plugins.herdsman plugins.tool-renderer ])

Both forms set the compiled selection; it replaces the payload’s own plugins rather than extending them. withPlugins takes the selector so a scope can be read per plugin, and pkgs.pi-bolt.override { plugins = [ plugins.herdsman ]; } sets the same list directly.

pi-extensions is a working example: one package per plugin, each built in its own repository, so its source pins, patches and npm dependencies move there rather than in the consumer’s tree.

The rest of this page is for a plugin that ships no Nix package: you supply the recipe.

{ pkgs }:
let
greeting = pkgs.piBoltPlugins.buildPiBoltPlugin {
pname = "greeting";
src = ./greeting;
entry = "index.ts";
};
in
pkgs.pi-bolt.withPlugins (_: [ greeting ])

The source must contain index.ts with the extension factory as its default export. Keep the normal Pi package.json in the source for resources and dependency metadata. entry is required, so this builder does not describe resource-only packages; those can be ordinary Pi package entries in settings.

The plugin-set example is runnable and includes an npm dependency, settings and a launcher. The builder reference lists all arguments.

Replace src with a normal Nix fetcher:

src = pkgs.fetchurl {
url = "https://registry.npmjs.org/pi-loop-police/-/pi-loop-police-1.14.1.tgz";
hash = "sha512-...";
};
entry = "extensions/loop-police.ts";

Supply npm dependencies with a pluginLock or packageLock.

The scope’s fetcher takes the registry URL and naming for you:

src = pkgs.piBoltPlugins.fetchNpmPackage {
pname = "pi-loop-police";
version = "1.14.1";
hash = "sha512-...";
};
entry = "extensions/loop-police.ts";

hash is the package’s dist.integrity from the registry (npm view pi-loop-police@1.14.1 dist.integrity). The fetched tree is the package itself, so entry paths match the published package; see the reference.

patches = [ ./fix-startup.patch ];
postPatch = ''
substituteInPlace config.ts --replace-fail 'DEBUG = true' 'DEBUG = false'
'';

Both run at the plugin root, so patch paths are a/config.ts, not a/src/config.ts.

runtimeInputs = [ pkgs.git ]; adds executables the plugin needs. Dependencies’ tools are included too.

Use dependencies = [ otherPlugin ]; for another buildPiBoltPlugin derivation imported by this plugin. Give that dependency its packageName when importing it by npm package name. It is staged once; list it in withPlugins too only if its extension factory should also be registered.

To publish a catalogue, extend the existing scope:

final: prev: {
piBoltPlugins = prev.piBoltPlugins.overrideScope (pfinal: _pprev: {
greeting = pfinal.callPackage ./greeting.nix { };
});
}

Apply this overlay after pi-bolt-nix.overlays.default. No catalogue membership is required to pass a plugin to withPlugins.

Use a plugin in payload.select { plugins = [ runtimePlugin ]; } when it is not in the payload’s compiled set. Pi loads it as an ordinary store package. Its npm dependencies must still be available to Pi; a compile-time pluginLock does not install a runtime plugin’s dependencies. Use packageLock on the plugin, or supply a prepared nodeModules tree.

For a temporary invocation, pi -e <entry-file> loads the extension directly; plugin.extensionPath gives its store entry. Do not prepend -e to a command that must dispatch subcommands: pi-bolt -e <path> doctor treats doctor as a prompt. Use settings for persistent configuration and launchers for tool paths.