Packaging and Releasing
Single-page view · as markdown
Packaging
Pekit / Packaging and Releasing
A package says what it contains, not how a format stores it. You write
packages with the package definition type, beside the builds they ship.
The workspace's packagers turn each into a file of their format, such as a
Peios package, and publish it into a store.
Before you start #
- The ppk library, and a
ppkprogram to register as its tool. See Libraries. - A target that builds what you want to ship.
Describe a package #
In a build file beside the build it ships, such as package.gcsl next to
build.gcsl, declare the package:
let version = "1.0-1"
def package dev.example.greet() {
version = version
files = {"bin/greet" = build app()}
}
def package dev.example.greet-dev() {
let g = build greet()
version = version
files = {"include" = g.headers; "lib/libgreet.a" = g.archive}
}
The definition's path is the package's name. Each of its files is placed
at its path under /usr: a file at its path, a list of files under it by
their names, and a directory's tree under it. Files in one directory see
each other's declarations, so build app() needs no import.
Give a package its metadata #
A package can carry more than its files. pekit keeps any other field of a
package's body and never reads it, so each packager defines the fields it
takes. The ppk packager reads a field named ppk, and records what it holds
in the package's manifest:
def package dev.example.greet-dev() {
let g = build greet()
version = version
files = {"include" = g.headers; "lib/libgreet.a" = g.archive}
ppk = {
description = "The greet library, for developers"
license = "MIT"
license_class = "free"
homepage = "https://example.com/greet"
dependencies = {"dev.example.greet" = "= {version}"}
}
}
ppk has two kinds of field:
- Single values, each a string:
description,homepage,license,license_class, andsource_license. - Tables, each a record of strings:
dependencies: the packages this one needs, each with a version constraint.requires: the capabilities it needs, such assh, each with a constraint.provides: the capabilities it offers, each with a version.claims: links it owns outside its files, each an absolute path and the link's target, such as"/usr/bin/sh" = "dash".descriptors: files and directories of the package that get a security descriptor of their own, each a path asfilesgives it and the descriptor in hexadecimal.
An empty string means any version, or no version. ppk checks every value as
ppk pack does, and finds an ELF program's libraries and their floors
itself, so don't write those. A field ppk has no form for is an error
naming it, so a misspelt field never goes missing quietly. A package
without ppk is packed with no metadata, as before.
A signed file, such as firmware, takes its signature from a file beside it
named with .peios.sig added. Place the signature in files like any other
file, or in the directory you place. ppk pack records it in the signed
file's entry and doesn't pack it as a file:
def package dev.example.firmware() {
version = "1.0-1"
files = {
"lib/firmware/acme/fw.bin" = file("fw.bin")
"lib/firmware/acme/fw.bin.peios.sig" = file("fw.bin.peios.sig")
}
ppk = {descriptors = {"lib/firmware/acme" = "0100048014000000..."}}
}
The descriptor is shortened here. What ppk requires of a descriptor or a
signature is under SECURITY METADATA in ppk(1).
Register the packager #
-
In
workspace.gcsl, register theppktool as a toolchain, and the ppk packager inpekitconf.packagers:import * from "github.com/gcslib/ppk" import * from toolchain def Toolchain::Ppk workspace_ppk() { let tools = dir("tools") host_platform = ^host_platform platform = {} provides = {root = tools; runtime = dir("/"); ppk = tools.file("ppk")} } pekitconf = { toolchains = [Toolchain::C system_c, Toolchain::Ppk workspace_ppk] packagers = [packager()] }This keeps the
ppkprogram attools/ppkin the workspace. A relative path is relative to the file it's written in, sodir("tools")inworkspace.gcslistoolsat the workspace's root. -
Pack every package below the current directory:
Check the result #
pekit packs each package with each packager, and prints where each went:
packed example/dev.example.greet with ppk
pekit-out/example/dev.example.greet/pack/artifacts
packed example/dev.example.greet-dev with ppk
pekit-out/example/dev.example.greet-dev/pack/artifacts
6 steps run, 0 found in the store
Name packages to pack only those, as pekit build names targets:
pekit package dev.example.greet, or pekit package 'pkgs/**'.
What reruns #
Each packing is a step of its own, so a package whose files didn't change
isn't packed again. Changing main.c repacks dev.example.greet and
leaves dev.example.greet-dev alone. Changing the version alone repacks
both and compiles nothing.
The ppk packager packs a package as ppk pack does, for the architecture
of ^platform, into a new directory, so the same files and version always
give the same package.
Pack in a build #
A build can pack packages itself, with the ppk library's pack:
import "github.com/gcslib/ppk"
def build packages() {
greet = ppk.pack(package dev.example.greet())
greet_dev = ppk.pack(package dev.example.greet-dev())
}
ppk.pack gives the artifact directory of one package.
Publish packages #
Copying a package into a store is publishing. It changes things outside the
build, so it's never a step: it happens on each run, in order, after the
packing it needs. pekit publish packs each package it's given, as pekit package does, then publishes it with each packager into the store --to
names:
published example/dev.example.greet with ppk
pekit-out/example/dev.example.greet/pack/artifacts
0 steps run, 5 found in the store
Packing doesn't depend on the store, so publishing what you've packed, or
the same package into a second store, packs nothing again. ppk publishes
into an artifact directory with ppk fetch --no-deps, which copies only the
named package and refuses a version whose contents changed: publish a new
version instead. If one package fails to publish, the packages published
before it stay published.
Publish strictly #
A strict build refuses a target's own effects, and publishing is one. To
publish what a strict build packs, pass --strict to pekit publish:
pekit packs every package strictly, then publishes them, taking every pack from the store. If a package fails to pack strictly, pekit publishes none of its recipe's packages, so that a recipe is published whole or not at all. It publishes the other recipes, says which it held back, and fails:
error: a recipe is not published, since a package of it did not pack strictly: org.gnu.bash
Replace a published version #
ppk refuses to publish a version whose contents changed, because something
might already have fetched the old contents. A repository that nothing has
fetched from yet, such as one being bootstrapped, can need a version
rebuilt and published again. For that, give the ppk packager
replace = true in workspace.gcsl:
pekitconf = {
packagers = [packager(replace = true)]
}
The packager then publishes with ppk fetch --no-deps --replace, and each
line pekit prints names it:
published example/dev.example.greet with ppk --replace
Write a packager #
Each packager is a packaging.Packager, from GCSL's standard packaging
module. It has a name, a pack function of a package to the directory it
packed it into, and a publish function of a package, that directory, and a
store. A library for another format gives a packager of its own, and a
workspace lists it in pekitconf.packagers beside ppk's.
Signing Kernel Modules
Pekit / Packaging and Releasing
A kernel that enforces module signatures loads a module only if it carries a signature by a key the kernel trusts. The modsig library signs a tree of modules after they are built, in a step of its own. It's the only step given the key, so no build command sees it. Signing the same modules with the same key always gives the same bytes, so a package of signed modules stays reproducible.
Before you start #
- The modsig library, which builds its signing program with the rust library. See Libraries.
- The Rust and C toolchains registered in
workspace.gcsl. See Building Rust. - A target that builds a directory of modules, each compressed with zstd
and named
.ko.zst. - A PEM file holding an ML-DSA-65 private key, with its seed, followed by its certificate, which the kernel trusts. Keep it outside the workspace, and out of version control.
Sign the modules #
-
Tell pekit where the key is. Name a file in the environment, which keeps the path out of your workspace:
Or give it a keychain entry named
module-signing. See Using Secrets. -
In the package, give
modsig.signthe directory of modules:import "github.com/gcslib/modsig" def package dev.example.modules() { version = "1.0-1" files = {"lib/modules" = modsig.sign(build modules())} } -
Pack it:
Check the result #
Decompress a module from the package, and modinfo shows who signed it:
|
sig_id: PKCS#7
signer: example module signing key
What it changes #
modsig.sign gives a copy of the directory. In that copy, each .ko.zst is
decompressed, signed, and compressed again at zstd's level 19. Everything
else is copied unchanged, so run depmod before or after signing, as you
prefer.
The step fails, and says why, if:
- a module is a
.ko,.ko.gz, or.ko.xz. The signature has to be inside the compression, and only zstd's is supported. - a module is signed already.
- the directory holds no module.
- the key file holds no seed, or the certificate isn't the private key's.
How a signature is made #
Each signature is deterministic pure ML-DSA-65 over the whole module, with
an empty context string and no signed attributes, in a PKCS#7 message
appended to the module. The kernel's sign-file can't produce this with
OpenSSL 3, which adds a signing time and randomises each signature.
A signed module's bytes also depend on zstd. The library's Cargo.lock pins
the version, so updating it changes every package that holds signed modules.
How the key and the store work together #
The signing step is an ordinary step given a secret, so Using Secrets describes how pekit protects the key. For signing, that means:
- The directory you give
modsig.sign, and every step that made it, stays unsigned in the store. Changing the key signs again without rebuilding them. - The signed copy is kept in the store, under the key's identity. It holds no secret.
- Another machine signs for itself, because a secret's identity differs between machines. It packs for itself too, and gets the same package.
pekit releaseuses thereleaseprofile's key. Signing twice gives the same bytes, so the release's reproducibility check passes.
Signing Firmware
Pekit / Packaging and Releasing
The Peios kernel loads device firmware only if the file carries a signature
by a key in the kernel's trusted computing base. A file that isn't ELF
carries its signature in its security.peios.sig attribute, which a package
can't hold. So the package carries the signature as a file beside the one it
signs, <file>.peios.sig, and the package's consumer sets the attribute from
it. The pipsig library makes those files after the build, in a step of its
own. It's the only step given the key, so no build command sees it. Signing
the same files with the same key always gives the same bytes, so the package
stays reproducible.
For the format of the signature and what the kernel checks, see Signature Format and Files the Kernel Loads. For how a package carries one, see Payload Entries.
Before you start #
- The pipsig library, which builds its signing program with the rust library. See Libraries.
- The Rust and C toolchains registered in
workspace.gcsl. See Building Rust. - A target that builds a directory holding the files to sign.
- A PEM file holding an ML-DSA-65 private key with its seed, such as
openssl genpkey -algorithm ML-DSA-65writes, whose public key the kernel trusts. Keep it outside the workspace, and out of version control.
Sign the files #
-
Tell pekit where the key is. Name a file in the environment, which keeps the path out of your workspace:
Or give it a keychain entry named
tcb-signing. See Using Secrets. -
In the package, give
pipsig.signthe directory and the patterns of the files to sign:import "github.com/gcslib/pipsig" def package dev.example.firmware() { version = "1.0-1" files = {"." = pipsig.sign(build firmware(), take = ["usr/lib/firmware/**"])} } -
Pack it:
Check the result #
Each file the patterns take has its signature beside it, of 3310 bytes:
3310 usr/lib/firmware/example.bin.zst.peios.sig
What it changes #
pipsig.sign gives a copy of the directory. In that copy, each regular file
the patterns take has a signature beside it, with mode 0644. Everything
else, the files themselves included, is copied unchanged.
A pattern is matched against the whole of a path in the directory. **
matches any characters, * matches any characters but /, and every other
character matches itself. So usr/lib/firmware/** takes every file under
usr/lib/firmware, and */usr/lib/firmware/** takes those of each directory
the tree holds.
A link that a pattern takes isn't signed. The kernel checks the file a link names, so that file's signature serves the link.
The step fails, and says why, if:
- a file it takes is ELF. An ELF file carries its signature in a section instead.
- a file it takes is a signature, or already has one beside it.
- a pattern takes no file, or
takeis empty. - the tree holds something that is neither a file, a directory nor a link.
- the key file holds no seed, or its expanded key isn't its seed's.
How a signature is made #
Each signature is a version byte, 1, followed by a deterministic pure
ML-DSA-65 signature, with an empty context string, of the SHA-256 of the
whole file as it is on disk. A compressed file is signed as it is
compressed, since the kernel checks the file before it decompresses it.
How the key and the store work together #
The signing step is an ordinary step given a secret, so Using Secrets describes how pekit protects the key. For signing, that means:
- The directory you give
pipsig.sign, and every step that made it, stays unsigned in the store. Changing the key signs again without rebuilding them. - The signed copy is kept in the store, under the key's identity. It holds no secret.
- Another machine signs for itself, because a secret's identity differs between machines. It packs for itself too, and gets the same package.
pekit releaseuses thereleaseprofile's key. Signing twice gives the same bytes, so the release's reproducibility check passes.
Recording Corresponding Source
Pekit / Packaging and Releasing
A package that ships a binary often has to come with its corresponding
source: everything the binary was built from, as the GPL asks of anyone
who distributes a GPL program, say. pekit works that out for you. It
records what each recipe's packages are built from in pekit.sources, a
file at the workspace's root, beside pekit.lock. A package of a recipe's
source is then built from that record alone, so it's the same wherever
it's built, and a change to a recipe's source shows in review.
What a recipe's source is #
A recipe is a directory of package definitions, such as org.gnu.bash.
Its source is everything a build of all its packages used, except tools:
- each file its build fetched, by URL and SHA-256;
- each git commit its build fetched, by repository and commit;
- each file and directory of the workspace that its code read, that its
steps were given, or that its packages hold, by its path in the
workspace. The GCSL code itself is among them, with
workspace.gcslandpekit.lock, which loading the workspace takes; - each library whose code it ran. A library that
pekit.lockpins is recorded whole, by its import path and its directory, since a build restores a pinned library whole. One the lock doesn't pin is recorded by the files of its code alone.
A tool isn't source:
- What a registered toolchain is made from: its definition's fetches, and everything fetched to make it, such as the source of a tool it compiles.
- A fetch or a
fetch_gitmarkedtool = true(see Fetching Files). - A path that leads out of the workspace, such as a link to a repository of packages that build roots are taken from.
Packing isn't part of a recipe's source either: pekit builds a recipe's packages without packing them to record it, so a packager's own program isn't counted.
Nor is what the package of the source holds. A package whose own code reads
pekit.sources is built from the record, so pekit counts its code but not
what it reads, fetches or holds. Otherwise a file the record once named
would stay recorded after the recipe stopped using it, or even after it was
deleted, since the package of the source holds it.
Before you start #
- A workspace whose packages build strictly, if the workspace requires
--strict. See Hermetic and Strict Builds. - Every tool your builds fetch outside a toolchain marked
tool = true.
Record the sources #
-
Run
pekit sourceswith the packages whose recipes to record, or none to record every recipe below this directory:pekit builds each recipe's packages on their own, every package of the recipe whichever you named, and records what each build used, with the names of the recipe's packages:
recorded org.gnu.bash: 21 fetched, 0 git, 15 files, 9 directories -
Review
pekit.sources, and commit it with the change that made it.
A recipe's record replaces what was recorded of it. Recipes you didn't name keep theirs.
Keep it current #
Run pekit sources again whenever a recipe's source changes: a new
version, a new patch, a build that reads another file, or a new package. A
strict publish or a release checks the record of each recipe it
publishes, and publishes nothing if one isn't what the recipe's build uses
and the packages it has:
error: nothing is published, since `pekit.sources` does not record what org.gnu.bash is built from: run `pekit sources --strict` for it, and review the change
A workspace with no pekit.sources publishes without the check.
Check the result #
Each recipe in pekit.sources lists its packages, its fetched files,
its git commits, the libraries whose code it ran, and the workspace's
files and dirs it read, each sorted:
A directory stands for everything in it. A package of the source fetches each file again by its digest, which the store answers, and takes the commits and the workspace's files as they are.
A build from a package of the source restores every library that its
pekit.lock pins, and fetches any that it lacks. So give the package a
lock that pins only the recipe's libraries, beside their directories.
It then builds with no network, from the store's tools and what the
package holds.
Releasing
Pekit / Packaging and Releasing
pekit release makes a release of one package. It builds the package as a
release should be built, publishes it, and tags the commit it was built
from. Everything a release depends on is pinned, so anyone with the commit
can build the same bytes.
Before you start #
- A workspace in a git repository, with every change committed.
- Every library pinned in
pekit.lock. See Pinning Libraries. - Steps that use only pinned toolchains, since a release is a strict build.
- The release profile's secrets in the keychain, if the package needs any. See Using Secrets.
- A packager registered in
pekitconf.packagers. See Packaging.
Release a package #
-
Commit everything, and check that
git statusis clean. -
Release the package into its store:
Check the result #
pekit reports what it published and the tag it added:
published dev.example.greet@1.0-1 with ppk into /srv/artifacts
tagged dev.example.greet@1.0-1 at 4834d15186dbf67463ca1410d67bc578faca1f4e
git tag lists the new tag. Push it to share the release.
What a release is built from #
A release is built from a commit, never from your working tree. The
workspace must match the repository's HEAD: every file committed, and
nothing changed or added, except the build's own pekit-out/ and .gcsl/.
If any file differs, pekit names it and stops.
pekit then exports the workspace's tree at HEAD into a directory of its
own, and builds there. So a file that git ignores never reaches a release.
How a release is built #
A release builds as pekit build --strict --check-reproducible would, with
the keychain's release profile:
- No host tools. Its steps run their programs from pinned toolchains, and a target's own code only fetches, unpacks, asks the keychain, and reads the workspace and the build's outputs. See Hermetic and Strict Builds.
- Pinned libraries. Its libraries are exactly those
pekit.lockpins. - Reproducible steps. Every step runs a second time, and a step that gives other outputs from the same inputs fails the release.
- Release secrets. Secrets come from the
releaseprofile, so a release signs with its own keys.
Publishing and tagging #
Once the package is built and checked, pekit publishes it with each of the
workspace's packagers into the store --to names. Then it tags HEAD as
NAME@VERSION, the package's name and version: dev.example.greet@1.0-1.
The tag is a lightweight tag, so it needs no git identity.
A version is released from one commit. If its tag is on another commit, pekit refuses before publishing anything: give the new release a version of its own. Releasing again from the commit that has the tag publishes the same package again, and adds no tag. pekit only ever adds tags. It never moves or deletes one.
Building and Booting an Image
Pekit / Packaging and Releasing
A bootable ISO is an ordinary build. The peiso library makes one from
packages with the peiso tool, and the qemu library boots one in QEMU, in
a test or for you to use.
Before you start #
- The peiso, ppk, and qemu libraries. See Libraries.
- The
peiso,mkirf, andmkukiprograms, andppk, to register as toolchains. - On the host:
mkfs.vfat, mtools, andxorriso, which peiso runs, and QEMU with OVMF's firmware for booting.
Register the tools #
The libraries ask the toolchain module for their tools. The qemu
library's system_qemu is the host's qemu-system-x86_64 and OVMF's
firmware. peiso, mkirf, and mkuki aren't published, so register the
ones you have, as ppk is registered in Packaging:
def Toolchain::Peiso workspace_peiso() {
let tools = dir("tools")
host_platform = ^host_platform
platform = {}
provides = {
root = tools
runtime = dir("/")
peiso = tools.file("peiso")
mkirf = tools.file("mkirf")
mkuki = tools.file("mkuki")
}
}
Build the image #
-
In a build file, call
peiso.isowith the kernel the ISO boots and the packages it carries:import "github.com/gcslib/peiso" import "github.com/gcslib/ppk" def build iso() { = peiso.iso( kernel = { package = ppk.from_repository(dir("repository"), "dev.peios.kernel", "0.25.0-indev-1") cmdline = "console=ttyS0" }, packages = [ {package = ppk.from_repository(dir("repository"), "net.busybox.busybox", "1.37.0-1"); initramfs = true}, {package = package dev.example.motd()}, ], ) }Each package is a package definition, which the library packs with ppk, or a package ppk has packed already, such as one from a repository.
-
Build it:
Check the result #
pekit prints the ISO's path. The ISO is one step, given its packages, so changing the kernel's command line rebuilds the ISO and no package. Changing one package rebuilds that package and the ISO.
Choose where each package goes #
Each package says whether the live system holds it, liveboot, which it does
unless you say otherwise, and whether the initramfs does, initramfs. The
initramfs and liveboot arguments of peiso.iso replace what each holds
outside /usr, as peiso's own specification does. Each holds symbolic links,
each {at; to}, with a target starting : in usr, and empty directories.
Take packages from a repository #
ppk.from_repository(repo, name, version) takes a package that isn't built
here from an artifact directory in the workspace, by its name and version,
for the platform being built for. It's a step keyed by the repository's
contents, so what it gives is exactly what the repository holds. The
repository has to be a directory of the workspace; the ppk library doesn't
fetch one over the network. It uses ppk fetch --no-deps to take only the
named package. Callers that need its dependencies resolve the closure
themselves.
Boot the image in a test #
qemu.boot(iso, until) boots an ISO under UEFI, with no network and its
console on its first serial port, until a line holding until appears. It
gives what the machine printed, with status 0 if the line appeared. In a
test, ask for KVM so that the machine runs at speed:
import "github.com/gcslib/qemu"
#[device("kvm")]
#[timeout(5m)]
def test boots(iso: File = build iso()) {
let run = qemu.boot(iso, until = "Please press Enter to activate this console.")
assert run.status == 0, run.stdout
}
The test is a step given the ISO, so it boots again only when the ISO changes. Without KVM, QEMU emulates the machine, slowly but the same.
Boot the image yourself #
qemu.launcher(iso) builds a program that boots the ISO with your
terminal, so that pekit run can run it:
def build boot() { = qemu.launcher(build iso()) }