Recipes
As part of the build process, recipes perform the actual work, creating and modifying build outputs. Each recipe consists of a sequence of steps to be executed. Recipes are defined by directories in the recipes directory. Each recipe gets its own directory with a recipe configuration file recipe.toml and a steps subdirectory defining the individual steps to be executed. The configuration file may specify a description, a priority, ordering constraints, dependencies of the recipe, and parameters.
Here is the configuration of the core/ssh recipe as an example:
#:schema https://raw.githubusercontent.com/rugix/rugix-bakery/main/schemas/rugix-bakery-recipe.schema.json
description = "Enable SSH and persist host keys."
priority = 80000
dependencies = ["pkg-update"]
[parameters]
root_authorized_keys = { default = "", description = "Public keys authorized for root." }The ssh recipe depends on the pkg-update recipe1 from Rugix Bakery’s core repository. The pkg-update recipe will update the package lists of the distribution (Debian or Alpine), which is required to be able to install SSH. It will also later remove the package lists from the build, as they are unnecessary at runtime. The configuration further defines a parameter, root_authorized_keys, with an empty default value. The steps of the recipe use this parameter to install public keys for SSH access.
The core recipe reference lists the built-in recipes, their dependencies, parameters, and examples.
Execution Order
The recipes of a layer or mixin run one after another. By default, recipes run in the order of their priority, from highest to lowest. Priorities default to 0 and can be negative. Recipes with equal priorities run in a stable order by repository and name.
Dependencies do not affect the order. Without ordering constraints, which are described below, a dependency with a lower priority runs after the recipe that depends on it. For example, core/pkg-update depends on core/pkg-cleanup, which has a low priority, so that it removes the package lists after other recipes have installed their packages.
To run a recipe after or before specific other recipes, regardless of their priorities, use after and before:
after = ["install-app", "core/rugix-ctrl"]
before = ["core/pkg-cleanup"]This recipe runs after install-app and core/rugix-ctrl and before core/pkg-cleanup. A constraint only applies when the named recipe runs in the same layer or mixin. It does not add the named recipe; use dependencies for that. Names resolve like dependencies. Rugix Bakery reports an error if a name does not refer to a recipe or if constraints form a cycle.
Constraints take precedence over priorities. Of the recipes whose constraints are satisfied, the one with the highest priority runs next.
Parameters
The parameters of a recipe are defined in the parameters section of its configuration. Every parameter has a name and an optional default value. Here is an example for how to define parameters with and without default values:
[parameters]
parameter_name = { default = "a default value" }
other_parameter = {} # Required parameter without a default value.
Parameter values are provided by layer configurations in the parameters section. For the details, we refer back to the layers section of this documentation. Every parameter without a default requires a value when the recipe runs. A parameter file, described below, can also supply this value.
Parameter values are exposed to a recipe’s steps (see below) via environment variables of the form RECIPE_PARAM_<PARAM_NAME>. So, in case of our example, RECIPE_PARAM_PARAMETER_NAME and RECIPE_PARAM_OTHER_PARAMETER.
Parameter Files
Use --param-file to override recipe parameters for a build without changing layer configurations. A parameter file configures recipes already used by a build. For example, with core/ssh included in a layer’s recipes list, create a TOML file to provide authorized SSH keys:
["core/ssh"]
root_authorized_keys = "ssh-ed25519 AAAA... user@example"Pass this file when baking an image:
./run-bakery bake system <system> --param-file parameters.toml
Each table names a recipe relative to the project repository. Use core/ssh for the core recipe, <repository>/<recipe> for a recipe from a configured repository, and a bare name for a project recipe. These references keep the same meaning when building layers or applying system mixins (optional layer fragments) from other repositories. An override applies wherever the selected recipe runs during the build.
Parameter-file values take precedence over layer and mixin parameters, which take precedence over recipe defaults. You can pass --param-file more than once; later files override earlier values for the same recipe reference and parameter. Use one reference per recipe across parameter files; different references that resolve to the same recipe are rejected.
Artifact Inputs
A recipe can declare artifacts that its steps consume, such as a compiled
application or generated configuration. Declare each input in inputs as an
object with a required kind and optional description. A layer can supply these artifacts,
or the recipe can define default bindings and prerequisite rules itself.
For example, this installation recipe builds an application by default:
[inputs.application]
kind = "file"
[parameters.profile]
default = "release"
[rules.build-application]
uses = "build-app"
inputs.source = { path = "application" }
parameters.architecture = { parameter = "architecture" }
parameters.profile = { parameter = "profile" }
[input-defaults]
application = { rule = { node = "build-application", output = "binary" } }The application input is a file consumed by the recipe. The build-application
node invokes the build-app rule, and input-defaults.application binds its
binary output to that input. Node names and input names are independent.
In this example, the recipe’s repository also defines a build-app rule.
That rule accepts a source directory, architecture and profile parameters,
and exports a binary file. It can select a tooling environment for compilation.
The application source directory, rule name, and any environment selected by
that rule resolve from their defining repository.
A layer can use the recipe without defining its build graph:
parent = "core/debian-bookworm"
recipes = ["vendor/install-app"]
[parameters."vendor/install-app"]
profile = "debug"Rugix Bakery resolves recipe parameters, builds the required artifacts, then runs the
layer’s recipe steps. Local rules receive the recipe’s effective parameter values,
including layer and parameter-file overrides. A reference to the architecture
parameter uses the target architecture unless the recipe declares its own
parameter with that name.
Steps read artifact inputs through RECIPE_INPUTS_DIR:
#!/bin/sh
set -eu
install -D -m 0755 "$RECIPE_INPUTS_DIR/application" "$RUGIX_ROOT_DIR/usr/bin/application"To install a prebuilt application, add an input binding to the layer:
[inputs."vendor/install-app"]
application = { path = "prebuilt/application" }
This path resolves from the layer’s repository. For this recipe, the binding replaces the default and skips the compiler rule. Rugix Bakery selects each input in this order:
- An explicit layer or mixin binding.
- An enclosing input with the same name, including inputs passed through a layer rule.
- The recipe’s
input-defaultsbinding.
An input without a selected binding fails before execution. Defaults support the
same artifact references as layer bindings.
Local rules can consume other declared recipe inputs, including their overrides
or defaults. They can also read the parent layer’s directory artifacts, such as
rootfs, through input references.
Rule node names are local to each recipe and separate from layer node names. Rugix Bakery plans only rules reachable from the selected bindings and rejects cycles between defaults, rules, and layers. Artifact inputs remain read-only and participate in layer caching.
Steps
Each recipe consists of a sequence of steps to be executed. Each step is defined by a file in the steps directory of a recipe. The names of the files in that directory must start with an integer followed by a - and a step kind. The integer indicates the position of the step in the recipe, e.g., 00 to 99. Currently, Rugix Bakery supports three kinds of steps.
packages
Steps of the kind packages can be used to provide lists of packages to install:
a
list
of
packagesRugix Bakery supports APT (Debian) and APK (Alpine) and will automatically select the correct package manager for a given system. The step filenames can also be suffixed with .apt and .apk to provide different package lists for APT and APK.
run
Steps of the kind run can be used to run scripts on the host/within the build environment:
#!/usr/bin/env bash
echo "This runs on the host system."These scripts are not limited to bash and can have an arbitrary file extension, e.g., .py for Python scripts. They must have a shebang (first line starting with #!) and must have the executable bit set (chmod +x).
Rugix Bakery exposes multiple environment variables that can be used in such scripts. You will find more details below.
You can use run steps to perform all kinds of tasks. For instance, the yocto-build recipe of the Yocto template sets up a temporary Python virtual environment to install KAS and will then run an entire Yocto build via KAS.
install
Steps of the kind install can be used to run scripts inside the system being built:
#!/usr/bin/env bash
echo "This runs via chroot in the system being built."Rugix Bakery will set up a semi-isolated environment (similar to a container) that mimics the system being built. It will then run the script inside that environment as the root user. The same considerations as for run steps apply analogously.
Note that the architecture reported by uname -m during an install step may not match the actual CPU and architecture of the device the system is intended for.
For instance, when building an armhf system based on Rasbperry Pi OS, the architecture reported by uname -m during the build process is armv7l, however, when running the system later on a non-ARMv7 board (e.g., Pi Zero or Pi 1), then the architecture will be armv6l.
We recommend always using the Rugix architecture instead of uname -m.
Environment Variables
Rugix Bakery will expose the following environment variables when running steps:
RUGIX_ARCH: Architecture of the build (arm64orarmhf).RUGIX_ROOT_DIR: Directory of the root filesystem.RUGIX_PROJECT_DIR: Directory of the Rugix Bakery project.RUGIX_REBUILD_IF_CHANGED: File for registering project paths that affect layer caching. Append one project-relative path per line.LAYER_REBUILD_IF_CHANGEDis an alias.RUGIX_LAYER_DIR: Directory of the layer being built.RUGIX_ARTIFACTS_DIR: Artifacts directory (part of the layer).RUGIX_CACHE_DIR: Directory for global caching.RUGIX_CONTEXT_DIR: Build context directory (typically the project directory).RECIPE_INPUTS_DIR: Read-only directory of this recipe’s artifact inputs, available torunandinstallsteps.RECIPE_DIR: Directory of the recipe which is applied.RECIPE_STEP_PATH: Path of the step being executed.
In addition, the recipe parameters are exposed as explained above.
Custom Artifacts
You can place any build artifacts in the artifacts directory pointed to by RUGIX_ARTIFACTS_DIR.
Those will later end up in the build directory of the respective system.
For instance, to generate a simple SBOM with dpkg you may use the following step:
#!/usr/bin/env bash
set -euo pipefail
SBOM_PATH="${RUGIX_ARTIFACTS_DIR}/dpkg-sbom.txt"
SBOM_DIR=$(dirname "${SBOM_PATH}")
if [ ! -d "${SBOM_DIR}" ]; then
mkdir -p "${SBOM_DIR}"
fi
dpkg --list >"${SBOM_PATH}"This provides a very flexible mechanism to generate all kinds of build artifacts and complementary documentation.
Custom Build Environments
For application compilation or other artifact generation, define a build rule with a tooling environment, then pass its outputs to a recipe through artifact inputs. A recipe can select that rule as its default, so a repository can supply the tooling environment, build, and installation behavior together.
A recipe’s run steps use Rugix Bakery’s own tools. If those steps need additional
tools directly, you can create a Docker image based on Rugix Bakery’s image.
For instance, to add Node.js to the build environment you can use the following Dockerfile:
ARG RUGIX_BAKERY_IMAGE=ghcr.io/rugix/rugix-bakery:v0.9
FROM ${RUGIX_BAKERY_IMAGE}
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
RUN apt-get install -y nodejsYou can then use your custom Docker image with ./run-bakery by setting the RUGIX_BAKERY_IMAGE environment variable.
This allows you to build your entire application from source to image in Rugix Bakery.
If the Rugix Bakery project lives in a subdirectory in the repository of your application (which typically is the case with monorepos), then you can inject the root directory of your repository by setting the RUGIX_CONTEXT_DIR environment variable.
Here is an example using both RUGIX_CONTEXT_DIR and RUGIX_BAKERY_IMAGE:
RUGIX_CONTEXT_DIR=".." RUGIX_BAKERY_IMAGE="custom-image" ./run-bakery
As a result, the root directory of your repository will be available as the context directory (see environment variables above).
Register project files used by these steps through
RUGIX_REBUILD_IF_CHANGED so that changes invalidate the
layer cache.
Registered paths must remain within the project directory. Files read from a
separate context directory are not tracked by this mechanism; pass build inputs
through declared artifacts or keep tracked sources in the project directory.
The shared download cache exposed by RUGIX_CACHE_DIR remains available for
downloads and other reusable data.
Reusable repositories should supply artifact-producing rules and tooling environments so their recipes can use the standard Rugix Bakery image.
Inspect and Document Definitions
Discover definitions without building them:
./run-bakery recipes list
./run-bakery recipes inspect core/ssh --json
Inspection shows the selected definition and its documentation. Add --json to export their metadata and adjacent
Markdown. See definition catalogs for
the shared documentation format and reference generator.
Configuration Reference
For reference, here is the complete schema for recipe configuration files:
RecipeConfigobject
Recipe configuration.
Properties
descriptionstring
categorystring
priorityinteger | string (int64)int64
- pattern:
^-?[0-9]+$
beforearray<string>
Items
valuestring
afterarray<string>
Items
valuestring
dependenciesarray<string>
Items
valuestring
inputsobject
Additional properties
valueArtifactInput
An artifact input with optional documentation.
Properties
kindArtifactKindrequired
Filesystem object accepted by an input or produced by an output.
filedirectory
descriptionstring
rulesobject
Additional properties
valueRuleInvocation
An invocation of a repository-defined rule.
Properties
usesRuleReferencerequired
A rule name or the implementation of an enclosing rule parameter.
Any of
option 1string
option 2object
Properties
rule-parameterstringrequired
inputsobject
Additional properties
valueArtifactSource
An artifact reference within a composition.
One of
option 1object
Properties
inputstringrequired
option 2object
Properties
pathstringrequired
option 3object
Properties
ruleRuleOutputSourcerequired
Reference to a node output.
Properties
nodestringrequired
outputstringrequired
option 4object
Properties
selectArtifactSelectionrequired
A path within a directory artifact. Symlinks must resolve inside that directory.
Properties
sourceArtifactSource (cycle)required
pathstringrequired
kindArtifactKindrequired
Filesystem object accepted by an input or produced by an output.
filedirectory
option 5object
Properties
treeobjectrequired
Additional properties
valueArtifactSource (cycle)
parametersobject
Additional properties
valueParameterBinding
A literal parameter value or a reference to an enclosing parameter.
Any of
option 1object
Properties
parameterstringrequired
option 2any of
Any of
option 1string
option 2boolean
option 3integer | string (int64)int64
- pattern:
^-?[0-9]+$
option 4number | string
- pattern:
^(NaN|[+-]?Infinity)$
secretsobject
Additional properties
valueArtifactSource
An artifact reference within a composition.
One of
option 1object
Properties
inputstringrequired
option 2object
Properties
pathstringrequired
option 3object
Properties
ruleRuleOutputSourcerequired
Reference to a node output.
Properties
nodestringrequired
outputstringrequired
option 4object
Properties
selectArtifactSelectionrequired
A path within a directory artifact. Symlinks must resolve inside that directory.
Properties
sourceArtifactSource (cycle)required
pathstringrequired
kindArtifactKindrequired
Filesystem object accepted by an input or produced by an output.
filedirectory
option 5object
Properties
treeobjectrequired
Additional properties
valueArtifactSource (cycle)
rulesobject
Additional properties
valueRuleBinding
An implementation bound to a rule parameter. Bindings resolve in the scope that contains them. The graph supplies the interface inputs and parameters, which a binding must not bind.
Properties
usesRuleReference
A rule name or the implementation of an enclosing rule parameter.
Any of
option 1string
option 2object
Properties
rule-parameterstringrequired
inputsobject
Additional properties
valueArtifactSource
An artifact reference within a composition.
One of
option 1object
Properties
inputstringrequired
option 2object
Properties
pathstringrequired
option 3object
Properties
ruleRuleOutputSourcerequired
Reference to a node output.
Properties
nodestringrequired
outputstringrequired
option 4object
Properties
selectArtifactSelectionrequired
A path within a directory artifact. Symlinks must resolve inside that directory.
Properties
sourceArtifactSource (cycle)required
pathstringrequired
kindArtifactKindrequired
Filesystem object accepted by an input or produced by an output.
filedirectory
option 5object
Properties
treeobjectrequired
Additional properties
valueArtifactSource (cycle)
parametersobject
Additional properties
valueParameterBinding
A literal parameter value or a reference to an enclosing parameter.
Any of
option 1object
Properties
parameterstringrequired
option 2any of
Any of
option 1string
option 2boolean
option 3integer | string (int64)int64
- pattern:
^-?[0-9]+$
option 4number | string
- pattern:
^(NaN|[+-]?Infinity)$
secretsobject
Additional properties
valueArtifactSource
An artifact reference within a composition.
One of
option 1object
Properties
inputstringrequired
option 2object
Properties
pathstringrequired
option 3object
Properties
ruleRuleOutputSourcerequired
Reference to a node output.
Properties
nodestringrequired
outputstringrequired
option 4object
Properties
selectArtifactSelectionrequired
A path within a directory artifact. Symlinks must resolve inside that directory.
Properties
sourceArtifactSource (cycle)required
pathstringrequired
kindArtifactKindrequired
Filesystem object accepted by an input or produced by an output.
filedirectory
option 5object
Properties
treeobjectrequired
Additional properties
valueArtifactSource (cycle)
rulesobject
Additional properties
valueRuleBinding (cycle)
input-defaultsobject
Additional properties
valueArtifactSource
An artifact reference within a composition.
One of
option 1object
Properties
inputstringrequired
option 2object
Properties
pathstringrequired
option 3object
Properties
ruleRuleOutputSourcerequired
Reference to a node output.
Properties
nodestringrequired
outputstringrequired
option 4object
Properties
selectArtifactSelectionrequired
A path within a directory artifact. Symlinks must resolve inside that directory.
Properties
sourceArtifactSource (cycle)required
pathstringrequired
kindArtifactKindrequired
Filesystem object accepted by an input or produced by an output.
filedirectory
option 5object
Properties
treeobjectrequired
Additional properties
valueArtifactSource (cycle)
parametersobject
Additional properties
valueParameterDef
Recipe parameter definition.
Properties
descriptionstring
defaultParameterValue
Value of a parameter.
Any of
option 1string
option 2boolean
option 3integer | string (int64)int64
- pattern:
^-?[0-9]+$
option 4number | string
- pattern:
^(NaN|[+-]?Infinity)$
You will find the most recent version of this schema on GitHub.