Skip to main content
Rugix Bakery 0.9.6 is here: Build rules for custom image pipelines and verified boot for EFI and Raspberry Pi. Read the release post.
Documentation

Layers

Layers are defined by layer configuration files <layer name>.toml in the layers directory. As described in Build Model, a layer is built by executing recipes. For a given layer, the respective layer configuration file specifies the recipes to be executed as well as an optional parent layer that should be used as a base. Here is an example taken from the Debian template:

layers/customized.toml
#:schema https://raw.githubusercontent.com/rugix/rugix/refs/tags/v0.8.0/schemas/rugix-bakery-layer.schema.json

parent = "core/debian-bookworm"

recipes = [
    # Setup Debian for booting via Grub.
    "core/debian-grub-setup",
    # Set a static hostname.
    "core/set-hostname",
    # Persist `/root`.
    "core/persist-root-home",
    # Setup and enable SSH.
    "core/ssh",
    # Enable discovery of the system in the local network.
    "rugix-extra/avahi",
    # Setup the network.
    "setup-network",
    # Install a static website.
    "hello-world",
]

This file defines a layer, named customized, that is based on the layer core/debian-bookworm, a general-purpose layer to build Debian-based systems shipped with Rugix Bakery. The configuration file then specifies a bunch of recipes to set up and customize the system, for instance, setting up a bootloader integration with Grub and providing a network configuration.

In addition to project-specific layers and recipes defined in the project directory, you can use layers and recipes provided by repositories. In case of the example, these repositories are core and rugix-extra. We will explain repositories in detail later. The built-in core layer reference lists available base layers, their architecture variants, source images, and configured recipes.

Root Layers

If you do not want to use a parent layer, you can also start from scratch by omitting the parent setting and specifying root = true. For example, here is a layer configuration that bootstraps Debian using the core/debian-bootstrap recipe:

reproducible-debian.toml
#:schema https://raw.githubusercontent.com/rugix/rugix/refs/tags/v0.8.0/schemas/rugix-bakery-layer.schema.json

root = true

recipes = [
    "core/debian-bootstrap",
]

[parameters."core/debian-bootstrap"]
suite = "bookworm"
snapshot = "20240501T024440Z"

By setting the snapshot parameter of the core/debian-bootstrap recipe (more on parameters later), the resulting layer will be based on a particular Debian snapshot, thereby leading to a semi-reproducible1 build.

Importing Layers

Rugix Bakery can import layers from external sources. To this end, you can specify a URL.

Here is an example for importing a layer from a Raspberry Pi OS (Bookworm) image:

raspios-bookworm.toml
#:schema https://raw.githubusercontent.com/rugix/rugix/refs/tags/v0.8.0/schemas/rugix-bakery-layer.schema.json

name = "Raspberry Pi OS (Bookworm)"
url = "https://downloads.raspberrypi.com/raspios_lite_arm64/images/raspios_lite_arm64-2024-03-15/2024-03-15-raspios-bookworm-arm64-lite.img.xz"

Rugix Bakery can download images and TAR archives from HTTP URLs and create layers from them. This is useful if one wants to take an existing system image as a basis, e.g., when building a customized variant of Raspberry Pi OS. In addition to HTTP URLs, file URLs starting with file:// are also supported. These URLs are resolved relative to the project directory.

Note that imported layers must not specify any recipes. Customizations are applied by using them as a parent.

Excluding Recipes

Recipes may depend on other recipes and as such will pull in their dependencies automatically when specified in the recipes list of a layer. To avoid that, e.g., when you want to replace some recipe with a local variant, you can exclude certain recipes from a layer. To this end, you can provide a list of recipes to exclude via the exclude property.

Recipe Artifact Inputs

A recipe can install artifacts produced by a build rule, such as an application compiled in a tooling environment. The recipe declares named inputs. The layer can bind each input to an artifact, and recipes can also supply default bindings and their own prerequisite rules. For example:

recipes/install-app/recipe.toml
[inputs.application]
kind = "file"

A run or install step reads those inputs through RECIPE_INPUTS_DIR:

recipes/install-app/steps/00-run.sh
#!/bin/sh
set -eu
install -D -m 0755 "$RECIPE_INPUTS_DIR/application" "$RUGIX_ROOT_DIR/usr/bin/application"

The layer defines the prerequisite rule and connects its output to the recipe:

layers/device.toml
parent = "core/debian-bookworm"
recipes = ["install-app"]

[rules.build-application]
uses = "vendor/build-app"
inputs.source = { path = "application" }
parameters.architecture = { parameter = "architecture" }

[inputs.install-app]
application = { rule = { node = "build-application", output = "binary" } }

Here, vendor/build-app declares a source directory input and an architecture parameter, and exports a binary file. The application source directory is relative to the repository containing the layer. Rugix Bakery supplies the layer’s target architecture as the architecture parameter available to its prerequisite rules.

Layers, prerequisite rules, and image assembly run in one dependency graph. Rugix Bakery builds prerequisite artifacts before running the layer’s recipes. Recipe inputs are read-only and isolated per recipe. Their contents and metadata participate in layer caching. Bindings apply to recipes executed by this layer; a parent builds its own inputs and recipes separately.

The inputs table uses recipe references as keys, just like parameters. For a repository recipe, use a table such as [inputs."vendor/install-app"]. Recipes accept file and directory inputs. Missing bindings, unknown inputs, inactive recipes, and incompatible kinds fail before execution.

Bindings support the same file, rule output, selection, and tree forms as rule inputs. An omitted binding forwards an available enclosing input of the same name, then falls back to a recipe’s input-defaults binding. Explicit layer bindings take precedence over both. Rules defined by a layer can also consume its parent’s rootfs, boot, config, artifacts, and bsp directory artifacts through { input = "rootfs" }, for example. A root layer has no parent artifacts. Cycles between layers and rules are rejected.

Mixins support the same rules and inputs tables. Their parent artifacts come from the preceding layer or mixin.

Inspect and Document Definitions

Discover definitions without building them:

./run-bakery layers list
./run-bakery layers inspect core/debian-trixie --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 layer configuration files:

LayerConfigobject

Layer configuration.

namestring
descriptionstring
categorystring
urlstring
parentstring
rootboolean
recipesarray<string>
valuestring
excludearray<string>
valuestring
rulesobject
valueRuleInvocation

An invocation of a repository-defined rule.

usesRuleReferencerequired

A rule name or the implementation of an enclosing rule parameter.

option 1string
option 2object
rule-parameterstringrequired
inputsobject
valueArtifactSource

An artifact reference within a composition.

option 1object
inputstringrequired
option 2object
pathstringrequired
option 3object
ruleRuleOutputSourcerequired

Reference to a node output.

nodestringrequired
outputstringrequired
option 4object
selectArtifactSelectionrequired

A path within a directory artifact. Symlinks must resolve inside that directory.

sourceArtifactSource (cycle)required
pathstringrequired
kindArtifactKindrequired

Filesystem object accepted by an input or produced by an output.

  • file
  • directory
option 5object
treeobjectrequired
valueArtifactSource (cycle)
parametersobject
valueParameterBinding

A literal parameter value or a reference to an enclosing parameter.

option 1object
parameterstringrequired
option 2any of
option 1string
option 2boolean
option 3integer | string (int64)int64
  • pattern: ^-?[0-9]+$
option 4number | string
  • pattern: ^(NaN|[+-]?Infinity)$
secretsobject
valueArtifactSource

An artifact reference within a composition.

option 1object
inputstringrequired
option 2object
pathstringrequired
option 3object
ruleRuleOutputSourcerequired

Reference to a node output.

nodestringrequired
outputstringrequired
option 4object
selectArtifactSelectionrequired

A path within a directory artifact. Symlinks must resolve inside that directory.

sourceArtifactSource (cycle)required
pathstringrequired
kindArtifactKindrequired

Filesystem object accepted by an input or produced by an output.

  • file
  • directory
option 5object
treeobjectrequired
valueArtifactSource (cycle)
rulesobject
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.

usesRuleReference

A rule name or the implementation of an enclosing rule parameter.

option 1string
option 2object
rule-parameterstringrequired
inputsobject
valueArtifactSource

An artifact reference within a composition.

option 1object
inputstringrequired
option 2object
pathstringrequired
option 3object
ruleRuleOutputSourcerequired

Reference to a node output.

nodestringrequired
outputstringrequired
option 4object
selectArtifactSelectionrequired

A path within a directory artifact. Symlinks must resolve inside that directory.

sourceArtifactSource (cycle)required
pathstringrequired
kindArtifactKindrequired

Filesystem object accepted by an input or produced by an output.

  • file
  • directory
option 5object
treeobjectrequired
valueArtifactSource (cycle)
parametersobject
valueParameterBinding

A literal parameter value or a reference to an enclosing parameter.

option 1object
parameterstringrequired
option 2any of
option 1string
option 2boolean
option 3integer | string (int64)int64
  • pattern: ^-?[0-9]+$
option 4number | string
  • pattern: ^(NaN|[+-]?Infinity)$
secretsobject
valueArtifactSource

An artifact reference within a composition.

option 1object
inputstringrequired
option 2object
pathstringrequired
option 3object
ruleRuleOutputSourcerequired

Reference to a node output.

nodestringrequired
outputstringrequired
option 4object
selectArtifactSelectionrequired

A path within a directory artifact. Symlinks must resolve inside that directory.

sourceArtifactSource (cycle)required
pathstringrequired
kindArtifactKindrequired

Filesystem object accepted by an input or produced by an output.

  • file
  • directory
option 5object
treeobjectrequired
valueArtifactSource (cycle)
rulesobject
valueRuleBinding (cycle)
inputsobject
valueobject
valueArtifactSource

An artifact reference within a composition.

option 1object
inputstringrequired
option 2object
pathstringrequired
option 3object
ruleRuleOutputSourcerequired

Reference to a node output.

nodestringrequired
outputstringrequired
option 4object
selectArtifactSelectionrequired

A path within a directory artifact. Symlinks must resolve inside that directory.

sourceArtifactSource (cycle)required
pathstringrequired
kindArtifactKindrequired

Filesystem object accepted by an input or produced by an output.

  • file
  • directory
option 5object
treeobjectrequired
valueArtifactSource (cycle)
parametersobject
valueobject
valueParameterValue

Value of a parameter.

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.

Footnotes

  1. Reproducing a layer requires fixed distribution inputs and deterministic recipes. Image assembly has additional controls for timestamps and generated identifiers; see Reproducible Builds. ↩