Development
This page is for contributors. It covers how to build and test the project locally, the CI/CD pipeline, what ships inside the default workspace image, and the coding conventions the codebase follows.
Prerequisites
- Go 1.26+
- Docker Engine, for building workspace images
- macOS on Apple Silicon or Linux (amd64, experimental arm64) with KVM, for running workspace VMs
Building and testing
# Build the binary
go build ./cmd/jailoc
# Embed jailoc-guest, the VM init, and jailoc-listener-broker, the proxy listener
# (release builds do this automatically)
go generate ./internal/guestbin ./internal/brokerbin
go build ./cmd/jailoc
# Build dist/jailoc for this host with jailoc-guest, the listener broker and
# the VM runtime embedded, like a release binary (Taskfile.yml). The runtime is
# built once from the pinned go-microvm and libkrun by scripts/vm-runtime/ and
# rebuilt when go.mod's go-microvm revision or the scripts change. Needs
# go-task and podman or docker; macOS also needs the Xcode command line tools,
# Rust and curl (see the script headers).
task
# Verify all packages compile (pre-commit)
go build ./...
# Run unit tests
go test ./...
# Run the VM integration tests (needs KVM or macOS, a go-microvm runner and host Docker)
JAILOC_VM_RUNNER=/path/to/go-microvm-runner JAILOC_VM_LIBDIR=/path/to/libs \
go test -tags vmintegration -v -timeout 45m ./internal/vmintegration/
# Lint
go vet ./...
golangci-lint run
# Build jailoc together with its VM runtime (Linux only)
nix build .#jailoc
Build the documentation with uv and Python 3.12; uv.lock pins the exact docs dependency versions CI uses:
export UV_PYTHON_DOWNLOADS=never UV_PROJECT_ENVIRONMENT=/tmp/jailoc-docs-venv
uv sync --locked --no-install-project --no-build --python 3.12
uv run --no-sync zensical build --clean --strict
CI/CD pipeline
The pipeline runs on GitHub Actions. Most workflows trigger on every branch and pull request; release workflows are gated on version tags (v*).
| Workflow | Trigger | Purpose |
|---|---|---|
| CI | Pushes and pull requests to main |
Unit tests (go test), golangci-lint, a check that the embedded TUI plugin matches its source, and a strict docs build (zensical build --strict) |
| Release | Tags matching v* — runs on push with v* ref |
GoReleaser uploads static binaries to the draft GitHub Release with changelog, the workflow attests every asset, publishes the release and then updates the Homebrew cask in seznam/homebrew-tap |
| Docs | Release Please creates a release | Builds documentation with Zensical (zensical build --strict) when a release is created, then deploys to GitHub Pages after the GoReleaser job succeeds |
| Pre-release | Manual (workflow_dispatch) with a ref and a version such as 1.20.0-rc.1 |
Tags the ref and publishes GoReleaser binaries as a GitHub pre-release; no docs deploy, no release-please involvement |
| VM Integration | PRs and pushes to main touching VM code, manual |
Builds the go-microvm runner and libkrun from the pinned revision and boots real workspace VMs on a GitHub-hosted x64 Linux runner with KVM (go test -tags vmintegration ./internal/vmintegration/) |
| Nix | Pushes and pull requests to main |
Formatting check (nix fmt) and nix flake check --all-systems, plus nix build .#jailoc and nix run . -- --help on x86_64 and aarch64 Linux runners |
| Nix vendorHash | go.mod/go.sum pushes to main, Dependabot PRs, manual |
Recomputes the vendorHash in nix/jailoc.nix and publishes it, see Dependabot Nix vendorHash |
| VM runtime | Called by the release workflows; pull requests touching scripts/vm-runtime/ |
Builds the VM runtime (go-microvm runner, libkrun from source at the commit pinned in scripts/vm-runtime/libkrun-source.sh, with cargo-auditable and a musl guest init (build-init.sh), libkrunfw; Linux in go-microvm's builder image pinned by digest in scripts/vm-runtime/builder-image.sh) for darwin/arm64, linux/amd64 and linux/arm64, the libkrunfw corresponding source (build-runtime-source.sh) and the runtime license notices (build-runtime-notices.sh, cargo-about for libkrun crates); uploads artifacts only when called by a release |
The release workflows install GoReleaser at the exact version and SHA-256 set in each workflow (GORELEASER_VERSION, GORELEASER_SHA256);
Dependabot does not update them, so bump all three workflows together. GoReleaser runs go generate ./internal/guestbin ./internal/brokerbin before building, so release binaries embed jailoc-guest and jailoc-listener-broker, and refuses to build unless the release workflow has placed all VM runtimes in internal/vm/runtimebin/ and the runtime notices and source in build/vm-runtime/. It builds static binaries (CGO_ENABLED=0) for darwin/arm64, linux/amd64 and linux/arm64, adds THIRD_PARTY_NOTICES (generated by scripts/third-party-notices.sh) to every archive and attaches jailoc_<version>_vm-runtime-source.tar and SPDX SBOMs (syft) of the archives and VM runtimes to the draft release. The release job then attests build provenance for every file in checksums.txt and only after that publishes the release. The repository has immutable releases enabled, so a published release's assets and tag can't change;
if any step fails, the release stays a draft and the Re-release workflow (release.yml) can finish it from the same tag. GoReleaser renders Casks/jailoc.rb without pushing it;
for stable releases a separate homebrew-tap job pushes it to seznam/homebrew-tap over SSH after the release is published, with the HOMEBREW_TAP_DEPLOY_KEY secret (the private half of a write-enabled deploy key on the tap). The secret lives in the homebrew-tap environment, which only main and v* tags can deploy to and which only the tap job uses;
pre-releases skip the tap. Configs live in .goreleaser.yml and .github/workflows/.
Nix package
| File | Responsibility |
|---|---|
flake.nix |
Systems, formatter (alejandra), apps and dev shells; imports nix/ for the packages |
nix/default.nix |
Dependency map: wires the runtime recipes together and passes the VM runtime to nix/jailoc.nix on Linux |
nix/jailoc.nix |
jailoc itself: embedded jailoc-guest, vendorHash, runtime paths as link-time variables |
nix/runtime/sources.nix |
Upstream pins and hashes for go-microvm, libkrun, libkrunfw and the Linux kernel; checks the go-microvm pin against go.mod |
nix/runtime/libkrun-init.nix |
Static musl guest init (init.krun) that libkrun embeds |
nix/runtime/libkrunfw.nix |
libkrunfw with its bundled Linux kernel, built offline from the pinned kernel tarball |
nix/runtime/libkrun.nix |
libkrun with jailoc's patches and the musl init, linked against libkrunfw |
nix/runtime/go-microvm-runner.nix |
go-microvm runner linked against jailoc's libkrun; checks go-microvm's versions.env against sources.nix |
jailoc receives the runtime through two link-time variables,
internal/cmd.defaultVMRunner and internal/cmd.defaultVMLibDir. A configured
[vm] runner / lib_dir wins over these package defaults, and the package
defaults win over the embedded runtime. Build a single runtime component for
debugging with nix build .#jailoc.runtime.<component>, where <component> is
one of libkrunInit, libkrunfwJailoc, libkrunJailoc or goMicrovmRunner.
Bump procedure:
- go-microvm revision (the
replaceline ingo.mod): updategoMicrovmRevand its hash innix/runtime/sources.nix, and thevendorHashinnix/runtime/go-microvm-runner.nix. Evaluation fails with a message naming both files untilsources.nixmatchesgo.mod. - libkrun or libkrunfw version (go-microvm's
versions.env): update the versions and hashes innix/runtime/sources.nixand the Cargo vendor hash innix/runtime/libkrun.nix. The runner build fails whileversions.envandsources.nixdisagree. - libkrun patches:
nix/default.nixapplies every*.patchinscripts/vm-runtime/libkrun-patches/in lexical order, the same set the release build uses. No Nix change is needed.
macOS
The Nix package builds the VM runtime for Linux only; on aarch64-darwin it ships jailoc without a runtime. An aarch64-darwin runtime needs:
- A
nix/runtime/libkrunfw-darwin.nixrecipe (not present in the repository) that buildslibkrunfw.5.dylibfrom upstream'slibkrunfw-prebuilt-aarch64.tgzrelease asset, which containskernel.cand aMakefile. The v5.6.2 asset's sha256 isadef6739cc3bda2a1b57f04c08ccbfdf206a6c831d76b32de1beddc0e7984e86.scripts/vm-runtime/build-runtime-darwin.shtakes the same approach for release builds. - In
nix/default.nix:pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic.stdenvfornix/runtime/libkrun-init.nixon that platform (the guest init is a Linux binary even when built on a macOS host; nixpkgs'libkrun-efipackage does the same), the darwin libkrunfw recipe, and avmRuntimevalue for darwin. - In
nix/runtime/libkrun.nix: an offline build (the upstream darwinMakefiledownloads a Debian sysroot unlessSYSROOT_LINUXis set or the prerequisite is removed),fixDarwinDylibNames, and no libkrunfw link via RUSTFLAGS. On darwin libkrun openslibkrunfw.5.dylibthrough the runner'sDYLD_LIBRARY_PATH, not as a build-time dependency. - In
nix/runtime/go-microvm-runner.nix: removing the-L/opt/homebrew/lib -L/usr/local/liband matching include flags from the darwin cgo directives inkrun/context.go, so an unsandboxed darwin builder never links a Homebrew libkrun; signing the runner inpostFixupwithdarwin.sigtoolandcodesign --entitlements <go-microvm source>/assets/entitlements.plist -f -s -;dontStrip = true, because stripping removes the entitlements; and anotool -Llinkage check. - A
macos-15build job in.github/workflows/nix.yml. CI proves only the build, signature and linkage: GitHub's macOS runners can't run nested Hypervisor.framework VMs, so booting a VM needs a real Apple Silicon Mac.
Dependabot Nix vendorHash
nix-vendor-hash.yml handles go.mod/go.sum changes pushed to main, manual runs, and same-repository PRs targeting main authored by Dependabot. The PR gate checks the author, not the actor, so maintainer-triggered updates also qualify.
calculatechecks out the exact source commit with read-only repository permissions. It runsnix-updateand, whennix/jailoc.nixchanges, formats, checks, builds, and runs the package. It passes only the updatedvendorHashstring as a job output. The job uses no Nix cache: its output feeds a job with write permissions, and without a cache there is no cache-poisoning path into it. Its timeout covers a cold build of the VM runtime.publishchecks out the same commit on a fresh runner with write permissions. It validates the hash format and replaces the singlevendorHashassignment without running Nix or repository scripts. It commits onlynix/jailoc.nixto the Dependabot branch, or opens the maintenance PR againstmainfor push/manual runs. The Dependabot push uses--force-with-leaseagainst the original PR head SHA, so it is rejected if the branch advanced or was deleted whilecalculateran.
Nix build sandboxing does not isolate the entire job: nix run executes the application outside the build sandbox. Separate runners prevent that execution from modifying the publication environment or capturing its write token. The workflow definition itself can still be modified in a PR; the same-repository Dependabot gate is not an absolute trust boundary. Publication uses GITHUB_TOKEN; the Dependabot branch commit includes [dependabot skip], allowing Dependabot to rebase and replace it.
After the token-generated push, a contributor with write access must select Approve workflows to run on the PR to start the resulting approval-required pull_request CI runs. See approving workflow runs. GITHUB_TOKEN pushes do not trigger push workflows.
Default image contents
The embedded base image is defined in internal/embed/assets/Dockerfile. Its contents are listed in Default Image Contents.
Project conventions
Module
github.com/seznam/jailoc
Commit format
type(scope): description
Valid types: feat, fix, docs, chore, refactor, test. Use imperative mood in the description.
Error handling
Always wrap errors with context. Never return a bare err.
// correct
return fmt.Errorf("resolve workspace: %w", err)
// wrong
return err
There are no custom error types in this codebase. fmt.Errorf wrapping is the only pattern used. There is no logging library either: fmt.Printf handles user-facing output, and errors propagate up the call stack.
File organization
One file per package concern: docker.go, workspace.go, config.go. When a concern grows large enough to split, create a new file with a descriptive name (e.g. fetch.go for HTTP fetching inside the docker package). All packages live under internal/ — nothing is exported.
Testing
Unit tests live beside their source files as *_test.go. VM integration tests live in internal/vmintegration/ and require the vmintegration build tag. Tests use t.Parallel() and a table-driven style with t.Run. There are no mocks, fixtures, or testdata directories.
Developing inside a jailoc workspace
dev/Dockerfile.jailoc is a workspace overlay that extends the default image with the Go toolchain, gopls, and golangci-lint. It lets you develop jailoc inside a jailoc workspace.
Add to ~/.config/jailoc/config.toml:
[workspaces.jailoc]
paths = ["/path/to/jailoc"]
dockerfile = "https://raw.githubusercontent.com/seznam/jailoc/main/dev/Dockerfile.jailoc"
Then run jailoc up jailoc. The standard build and test commands work inside the VM unchanged. The Docker integration tests (-tags integration) also need enable_docker = true; the VM integration tests cannot run inside a workspace VM.