@sealant/os-integration-buildkit
@sealant/os-integration-buildkit
Purpose
@sealant/os-integration-buildkit is the concrete OS integration that compiles a normalized
WorkspaceBlueprint into build artifacts using Docker BuildKit.
It currently ships executors for fedora, arch, and nix target OS families.
Why this package exists
- Translate composition-level contracts into concrete image build plans.
- Keep BuildKit-specific implementation details outside core composition.
- Produce reproducible artifacts for later registry publishing and runtime launch.
Execution model
The package implements one concrete executor class (BuildkitDistroOsExecutor) with two phases:
supports(input)validates whether the executor can compile the blueprint.compile(input)renders a BuildKit context, runs Docker BuildKit, and emits standardized executor artifacts.
High-level flow:
- Parse/validate input via
parseBuildkitOsExecutorCompileInput(...). - Gate with
getBuildkitExecutorSupport(...). - Map blueprint to
ResolvedImagePlan. - Render build context files (
Containerfile,entrypoint.sh, JSON metadata). - Run
docker buildanddocker save. - Return a normalized
BuildkitOsExecutorCompileResult.
Module map (exact responsibilities)
src/buildkit-executor.ts- process execution (
defaultCommandRunner) - distro catalog (
distroDefinitions) - support gate (
getBuildkitExecutorSupport) - package resolution (
resolvePackages) - blueprint -> resolved plan mapping (
mapBlueprintToResolvedImagePlan) - renderers for Containerfile, entrypoint, dotfiles step, lifecycle steps
- build context writing (
writeBuildContext) - docker invocation (
buildImageTarball) - executor class and public factory/helpers
- process execution (
src/index.ts- public exports only
Public surface
BuildkitDistroOsExecutorcreateBuildkitOsExecutor(osFamily, options)mapBlueprintToBuildkitImagePlan(blueprint, osFamily)BuildkitCommandRunnerBuildkitCommandResultBuildkitCommandOptionsBuildkitOsExecutorOptions
Exports are defined in packages/os-integration-buildkit/src/index.ts.
Supported OS families
fedoraarchnix
Distro definitions
distroDefinitions drives almost all distro-specific behavior.
| OS family | Base image | Package manager | Bash path | SSHD path |
|---|---|---|---|---|
fedora | fedora:41 | dnf | /bin/bash | /usr/sbin/sshd |
arch | archlinux:latest | pacman | /bin/bash | /usr/sbin/sshd |
nix | nixos/nix:latest | nix | /root/.nix-profile/bin/bash | /root/.nix-profile/bin/sshd |
The same structure also includes:
- package id mappings (
packageMap) - mandatory internal packages (certs, ssh, shell/core tooling)
- shell binary paths for
bash,zsh,fish
Support gate (supports)
supports(...) and compile(...) both use the same gate logic.
The executor rejects with normalized support failures when:
- target OS family is neither
autonor this executor's family (unsupported-os) - harness id is not registered in
@sealant/ai-harness-integrations(unsupported-harness) - any package request includes a version pin (
unsupported-package) - any input source purpose is not
dotfiles(unsupported-runtime-requirement) - more than one dotfiles source is provided (
unsupported-runtime-requirement)
Blueprint to image plan mapping
mapBlueprintToBuildkitImagePlan(...) returns a ResolvedImagePlan that is fully concrete for
rendering.
Package resolution rules
Package requests are assembled in this order:
- user-requested
blueprint.tooling.packages - harness-required packages from
harnessIntegration.installPackages - default shell package when non-bash shell is selected
- dotfiles helper packages when dotfiles apply is enabled
- always add
git - add
chezmoiand/orstowbased on manager (autoadds both)
- always add
Each request resolves via distro packageMap if present; otherwise it falls back to passthrough
(installPackages: [request.id]).
Duplicate install packages are removed later by normalizeInstallPackages(...) before rendering the
install command.
Secret and dotfiles planning rules
blueprint.sources.workspace.authRef-> runtime secretworkspace_git_key- dotfiles
authRefwith prefixgithub-installation-repository:<id>- dotfiles are marked
applyAt: runtime - no build secret mount is emitted
githubInstallationRepositoryIdis recorded in plan
- dotfiles are marked
- dotfiles
authRefwithout that prefix- dotfiles are marked
applyAt: build - build secret
dotfiles_git_keyis emitted - dotfiles plan contains
authSecretId: dotfiles_git_key
- dotfiles are marked
Build context rendering
writeBuildContext(...) creates a temp directory like sealant-buildkit-<os>-* and writes:
Containerfileentrypoint.shresolved-image-plan.jsonbuildkit-spec.json
It also calculates:
- image tarball output path:
workspace-image.tar - image name:
sealant-workspace-<os>-<harness> - image reference tag:
<image-name>:<harness>
Containerfile generation
renderContainerfile(...) emits:
- base image (
FROM ...) - distro package install step
dnf: upgrade + install + cleanpacman: sync/update + install + cache cleannix:nix profile addwith flake refs
- harness install step from integration metadata
- nix rewrites
npm install -g ...tonpm install -g --prefix /usr/local ...
- nix rewrites
- default shell setup
- nix:
ENV SHELL=... - others:
usermod -s ... root
- nix:
- entrypoint copy + permissions
- optional build-time dotfiles apply step when
dotfiles.applyAt === "build"
Entrypoint generation
renderWorkspaceEntrypoint(...) is the runtime control script. It does all of the following:
- bootstraps runtime directories and base env (
HOME,USER,PATH) - fixes glibc loader symlink for nix images when missing (
/lib64/ld-linux-x86-64.so.2) - configures workspace clone auth from env
- SSH key path via
SEALANT_WORKSPACE_AUTH_KEY_BASE64 - HTTP askpass via
SEALANT_WORKSPACE_HTTP_TOKEN
- SSH key path via
- conditionally configures and starts SSHD when
SEALANT_ENABLE_SSHis truthy- authorized keys from file or
SEALANT_SSH_AUTHORIZED_KEYS_BASE64 - generates host key if missing
- creates forced shell wrapper at
/usr/local/bin/workspace-ssh-shell
- authorized keys from file or
- clones workspace repository when
.gitis absent - clears clone auth material after clone (
cleanup_workspace_clone_auth) - optionally applies dotfiles at runtime when plan requires runtime apply
- runs lifecycle setup and startup steps from blueprint
- executes foreground command in this precedence:
SEALANT_FOREGROUND_COMMANDoverride- blueprint startup command (if
foreground.kind === "command") - harness launch command in selected default shell
Docker execution
buildImageTarball(...) runs exactly two commands:
docker build --file <Containerfile> ... --tag <image-ref> <context-dir>docker save --output <workspace-image.tar> <image-ref>
Build-time secrets are passed as Docker BuildKit --secret flags from spec.secrets.
The default command runner (defaultCommandRunner) also:
- sets
DOCKER_BUILDKIT=1 - captures stdout/stderr
- throws
buildkit-command-failedon non-zero exit or signal
Compile output contract
compile(...) returns a parsed BuildkitOsExecutorCompileResult with:
- executor identity (
id,osFamily) - artifacts
oci-imagetarball (loader: docker-load)- metadata JSON for resolved image plan
- metadata JSON for buildkit spec
- metadata notes and default artifact name
buildkitextension object containing fullimagePlanandspec
This result is the bridge used by downstream registry/runtime orchestration.
Runtime environment variables consumed by entrypoint
Primary runtime controls read by generated entrypoint.sh:
SEALANT_ENABLE_SSH,SEALANT_SSH_PORTSEALANT_SSH_AUTHORIZED_KEYS_FILE,SEALANT_SSH_AUTHORIZED_KEYS_BASE64SEALANT_WORKSPACE_AUTH_KEY_BASE64SEALANT_WORKSPACE_HTTP_TOKEN,SEALANT_WORKSPACE_HTTP_USERNAMESEALANT_DOTFILES_HTTP_TOKEN,SEALANT_DOTFILES_HTTP_USERNAME(runtime dotfiles only)SEALANT_FOREGROUND_COMMANDSEALANT_OCI_RUNTIME(special shell handling forrunsc)
Current constraints and non-goals
- only one dotfiles input source is supported
- non-dotfiles input purposes are rejected
- package version pinning is rejected
- package id compatibility is mostly best-effort (unknown ids pass through)
- build spec is generated for local build output (
push: false) and tarball export
Cross-package dependency
- Depends on
@sealant/ai-harness-integrationsfor harness install/launch contracts. - Depends on
@sealant/workspace-compositionfor schemas/contracts and compile result types.
Internal dependencies
- Internal package dependencies:
@sealant/ai-harness-integrations@sealant/workspace-composition
- External runtime dependencies:
- Docker CLI and daemon (for build/save)
- Node.js child process and fs APIs
Scripts
pnpm --filter @sealant/os-integration-buildkit lintpnpm --filter @sealant/os-integration-buildkit testpnpm --filter @sealant/os-integration-buildkit typecheck