ai-toolkit-layer
Recipe card from the charly-ai-toolkit plugin (Images — the deployable catalog).
ai-toolkit-layer — the candy’s internals
Section titled “ai-toolkit-layer — the candy’s internals”How the ai-toolkit candy is built. Read /charly-image:layer first for the general candy
authoring rules; this file records only what is specific to this candy.
MUST be invoked when editing the ai-toolkit candy, its pixi env, or the build/probe steps.
Why the pin is a COMMIT, not a tag
Section titled “Why the pin is a COMMIT, not a tag”git ls-remote --tags https://github.com/ostris/ai-toolkit.git returns no tags at all.
The only pinnable ref upstream offers is a commit, so AI_TOOLKIT_REF is a full sha and the
build asserts git rev-parse HEAD equals it — a typo’d sha would otherwise leave the clone on
the default branch and the image would ship whatever main happened to be that day.
Why there is a pixi.toml AND a venv
Section titled “Why there is a pixi.toml AND a venv”They own different things, and neither is redundant:
pixi.tomlowns the Python MINOR VERSION (==3.12.*). ai-toolkit requires >=3.10 and recommends 3.12; the Arch host python is newer than the wheels torch publishes.- The venv owns ai-toolkit’s dependency set, built from the pinned commit’s own
requirements.txt. That file pins a git revision of diffusers (git+https://github.com/ huggingface/diffusers.git@c943837…) alongsidetorchao,transformers,peftandlycoris-loraversions that upstream solves together and re-solves on its own cadence. Re-expressing that set in[pypi-dependencies]would fork upstream’s solved set and drift.
This follows the org precedent set by pod-unsloth-studio, which bootstraps the Unsloth Studio
runtime venv at image-build time for the same reason: the upstream app owns its environment.
Why the venv is at <root>/venv specifically
Section titled “Why the venv is at <root>/venv specifically”The UI worker resolves its interpreter itself — ui/cron/pythonPath.ts looks for
<TOOLKIT_ROOT>/venv/bin/python and then <TOOLKIT_ROOT>/.venv/bin/python, falling back to
python3 on PATH. Building the venv at /opt/ai-toolkit/venv means the GUI-launched jobs get
the pinned venv without any PATH surgery.
Application in the image, state in the volume
Section titled “Application in the image, state in the volume”ai-toolkit has no --base-directory flag (ComfyUI does), and it writes config/,
output/ and datasets/ relative to its own root. So the volume is spliced in by symlink,
created in the start scripts at RUNTIME because the volume only exists once the container
starts:
/opt/ai-toolkit/{config,output,datasets} -> $HOME/ai-toolkit/{config,output,datasets}The app tree is chowned to the image user so the UI can write its own runtime state, and
upstream’s config/ examples are copied to /opt/ai-toolkit/config.examples at build time
before the symlink replaces the live config/ — otherwise the examples would vanish on first
boot and every volume wipe.
Two services, not one wrapper
Section titled “Two services, not one wrapper”The UI server (dist/cron/fileServer.js) and its job worker (dist/cron/worker.js) are
declared as separate service: entries with different priorities. Upstream starts both through
concurrently; supervising the wrapper would leave the two real PIDs as untracked
grandchildren, so a dead worker would look “running”.
The Z-Image canary check
Section titled “The Z-Image canary check”ai-toolkit-diffusers-zimage imports ZImagePipeline from the venv. That single probe is the
contract every Z-Image job depends on, and it is a property of the diffusers revision
ai-toolkit pins — not of anything this candy installs. If upstream moves the git pin to a
revision without Z-Image support, the build fails here instead of at the first training job.
Node.js
Section titled “Node.js”The UI is Next.js + a worker + a file server; it is built at image time (npm ci && npm run build) so the supervised launch is immediate and never depends on network access at start. The
layer-nodejs candy supplies Node >= 20.

