Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236# --- Targets --------------------------------------------------------------## make build + test (the default).# make build build the shipped image (target package) and export it# to out/: a single static init at out/usr/bin/init.# make test build the superset test image (target test): the build# stage plus a hash-locked qemu system emulator, the# published hash-locked kernel, the hash-locked OVMF# firmware, and the boot-acceptance gate -- which runs# in-container at build time (see scripts/boot-gate.sh).# make kernel fetch the published hash-locked kernel# (stagex/user-linux-server) to out/kernel/bzImage and# verify its sha256 (a host-side utility; the gate's# kernel lives in the test image).# make kernel-subset materialize third_party/linux-subset: the ~13 kernel# files the build/test suite reads, copied from the# pinned kernel submodule (third_party/linux) with a# per-file blob-identity check against the submodule, and# a MANIFEST (sha256 per file). Idempotent; the docker# build context carries this subset, never the 1.8G tree.# make kernel-provenance assert the kernel gitlink the nit repo records# equals KERNEL_PIN (the tag v7.2.4 commit).# make boot-test re-run the in-container boot gate standalone against# the last built test image.# make verify build the formal-verification target: Kani 0.68.0# proves nit's pure logic in a hash-locked container and# the final step asserts all 24 harnesses verified.## The boot gate runs fully in the container, under the published hash-locked# qemu, booting via OVMF/UEFI. The published musl qemu builds (10.1.1 and# 11.0.0) hang at "Booting from ROM.." on the SeaBIOS->kernel hand-off in a# container (TCG and KVM alike), while the OVMF path boots deterministically;# the container environment itself is exonerated (a glibc qemu 10.0.11 boots# the same kernel in-container via SeaBIOS). See README "Boot acceptance in# the container" for the matrix and proof. Every input is hash-locked (see# the Containerfile pins and the KERNEL_REF / KERNEL_SHA below).
# The pinned kernel source tree: the gitlink commit recorded in the nit repo# for third_party/linux (tag v7.2.4). `kernel-provenance` asserts the# recorded gitlink equals this; `kernel-subset` materializes the ~13 files# the build/test suite reads from the tree into third_party/linux-subset.KERNEL_PIN=5015d0d945b3d3f2b038d2667880d5762f7d9437
# The kernel files the build/test suite reads (build.rs: the two .tbl tables;# tests/kernel_source.rs: the uapi headers UAPI_CONSTS names). Kept in sync# with those two files; the container's MANIFEST check is the downstream gate.SUBSET_FILES= \ arch/x86/entry/syscalls/syscall_64.tbl \ scripts/syscall.tbl \ include/uapi/asm-generic/errno-base.h \ include/uapi/asm-generic/errno.h \ include/uapi/asm-generic/fcntl.h \ include/uapi/asm-generic/ioctls.h \ include/uapi/linux/capability.h \ include/uapi/linux/fcntl.h \ include/uapi/linux/loop.h \ include/uapi/linux/mount.h \ include/uapi/linux/prctl.h \ include/uapi/linux/stat.h \ include/uapi/linux/time.h
# The published kernel: image digest pinned per the stagex publish, and the# bzImage content pinned to its sha256 so a re-pull that ever changes the# bytes fails the gate instead of silently booting a different kernel.KERNEL_REF=stagex/user-linux-server@sha256:2b705d74e9106825caba985811c15fd0387c13c06991a44fad435456339e3201KERNEL_SHA=00e009c113cbf74c5874b7900b8eee4bb51fd7222611f7ad5c6810da77b35e26
.PHONY: defaultdefault: build test
# --- Lean build (the shipped image) ----------------------------------------## `build` builds the shipped image from Containerfile (target package):# pallet-rust base, the style+lint gate, the live ABI gate, the nolibc build,# and the self-containment gate; the `scratch` package stage ships only# /usr/bin/init. Nothing test-infrastructure enters the shipped image.
.PHONY: buildbuild: kernel-subset docker build \ --tag local/nit \ --target package \ --progress=plain \ --output type=local,rewrite-timestamp=true,dest=out \ -f Containerfile \ .
# --- Test suite -------------------------------------------------------------## `test` builds the superset test image (target test): the full build stage# (style+lint gate, live ABI gate, nolibc build, self-containment gate) plus a# hash-locked qemu system emulator, the published hash-locked kernel, and the# hash-locked OVMF firmware. The boot-acceptance gate (scripts/boot-gate.sh)# runs inside the build as its final step: it boots the exact shipped init as# PID 1 under the in-container qemu via OVMF and asserts the boot-to-execve# hand-off, so the test image cannot exist without a verified boot. `make# boot-test` re-runs that same gate standalone against the built image.
.PHONY: testtest: kernel-subset docker build \ --tag local/nit-test \ --target test \ --progress=plain \ -f Containerfile \ .
# --- QEMU boot acceptance ----------------------------------------------------## `kernel` fetches the published hash-locked kernel (stagex/user-linux-server,# digest-pinned) to out/kernel/bzImage and verifies the bzImage content# against KERNEL_SHA. Both pins are the gate: the digest locks which image the# bytes came from, the sha locks the bytes themselves. It is a host-side# utility (e.g. for ad-hoc host boots); the in-container gate carries its own# copy in the test image.## `boot-test` re-runs the in-container boot gate (scripts/boot-gate.sh)# standalone against the last built local/nit-test: the same boot, the same# assertion, outside the build. `test` already ran it at build time.## `verify` builds the verify target: a standalone stage (not the shipped or# test images) that runs Kani 0.68.0 formal verification of nit's pure logic# (verification/kani/tests/proofs.rs) in a hash-locked container. Every# input is pinned (the Kani distro bundle, the three rust nightly-2026-08-21# components, the cargo-kani shim, and the six-deb C preprocessor closure# goto-cc needs), and the final build step asserts all 24 harnesses# verified, so the image cannot exist without a green proof.
.PHONY: verify verify-verusverify: kernel-subset docker build \ --tag local/nit-verify \ --target verify \ --progress=plain \ -f Containerfile \ .
verify-verus: kernel-subset docker build \ --tag local/nit-verify-verus \ --target verify-verus \ --progress=plain \ -f Containerfile \ .
.PHONY: kernelkernel: @mkdir -p out/kernel @if [ -f out/kernel/bzImage ] && [ "$$(sha256sum out/kernel/bzImage | cut -d' ' -f1)" = "$(KERNEL_SHA)" ]; then \ echo "kernel: out/kernel/bzImage ok ($$(sha256sum out/kernel/bzImage | cut -c1-12))"; \ else \ echo "kernel: fetching $(KERNEL_REF)"; \ docker pull $(KERNEL_REF); \ cid=$$(docker create $(KERNEL_REF)); \ docker cp $$cid:/bzImage out/kernel/bzImage; \ docker rm $$cid >/dev/null; \ actual=$$(sha256sum out/kernel/bzImage | cut -d' ' -f1); \ if [ "$$actual" != "$(KERNEL_SHA)" ]; then \ echo "kernel: FAIL: sha256 $$actual != $(KERNEL_SHA)"; exit 1; \ fi; \ echo "kernel: out/kernel/bzImage verified ($$(sha256sum out/kernel/bzImage | cut -c1-12))"; \ fi
# --- Kernel source subset (the docker context carries this, not the tree) ----## `kernel-subset` materializes third_party/linux-subset: the ~13 files the# build/test suite actually reads, copied layout-preserving from the pinned# kernel tree (third_party/linux). Each copied file is checked for blob# identity against the submodule's object store (git rev-parse HEAD:<rel> vs# git hash-object), so a subset that ever diverges from the pinned tree fails# here, and a MANIFEST (sha256 per file) is written for the container's# in-image check (the Containerfile's manifest step). Idempotent: the subset# is removed and rebuilt on every run. The 1.8G tree never enters the docker# build context (.dockerignore excludes it); this ~13-file subset is what# rides the `ADD . /src` layer.## `kernel-provenance` asserts the gitlink the nit repo records for# third_party/linux equals KERNEL_PIN (tag v7.2.4). In a normal clone the# authoritative command is `git ls-files -s third_party/linux`; in a worktree# where third_party/linux is an embedded clone the same command still returns# the gitlink (it reads the index, not the submodule), so this works in both# -- but if a setup ever records it differently, derive the pin from# `git submodule status third_party/linux` instead (the commit field)..PHONY: kernel-subsetkernel-subset: @set -e; \ if [ ! -d third_party/linux/.git ] && [ ! -f third_party/linux/.git ]; then \ echo "kernel-subset: FAIL: third_party/linux is not a git checkout\n\The kernel submodule is not initialized. Run:\n\ git submodule update --init"; exit 1; \ fi; \ if [ "$$(git -C third_party/linux rev-parse HEAD)" != "$(KERNEL_PIN)" ]; then \ echo "kernel-subset: FAIL: third_party/linux is at $$(git -C third_party/linux rev-parse HEAD), expected $(KERNEL_PIN)\n\Run: git submodule update --init"; exit 1; \ fi; \ rm -rf third_party/linux-subset; \ for f in $(SUBSET_FILES); do \ if [ ! -f third_party/linux/$$f ]; then \ echo "kernel-subset: FAIL: third_party/linux/$$f missing"; exit 1; \ fi; \ mkdir -p "third_party/linux-subset/$$(dirname $$f)"; \ cp third_party/linux/$$f third_party/linux-subset/$$f; \ if [ "$$(git -C third_party/linux rev-parse HEAD:$$f)" != "$$(git hash-object third_party/linux-subset/$$f)" ]; then \ echo "kernel-subset: FAIL: third_party/linux-subset/$$f is not byte-identical to the pinned kernel blob"; exit 1; \ fi; \ done; \ { \ echo "# third_party/linux-subset MANIFEST (generated by make kernel-subset)"; \ echo "# KERNEL_PIN=$(KERNEL_PIN) (tag v7.2.4)"; \ ( cd third_party/linux-subset; sha256sum $(SUBSET_FILES) ); \ } > third_party/linux-subset/MANIFEST; \ echo "kernel-subset: $$(cd third_party/linux-subset; find . -type f ! -name MANIFEST | wc -l) files, MANIFEST written"
.PHONY: kernel-provenancekernel-provenance: @gitlink=$$(git ls-files -s third_party/linux | awk '{print $$2}'); \ if [ -z "$$gitlink" ]; then \ gitlink=$$(git submodule status third_party/linux 2>/dev/null | awk '{print $$1}' | sed 's/^[+~-]//'); \ fi; \ if [ -z "$$gitlink" ]; then \ echo "kernel-provenance: FAIL: no gitlink recorded for third_party/linux\n\The kernel submodule is not initialized. Run:\n\ git submodule update --init"; exit 1; \ fi; \ if [ "$$gitlink" != "$(KERNEL_PIN)" ]; then \ echo "kernel-provenance: FAIL: gitlink $$gitlink != KERNEL_PIN $(KERNEL_PIN)"; exit 1; \ fi; \ echo "kernel-provenance: gitlink $(KERNEL_PIN) (tag v7.2.4) ok"
.PHONY: boot-testboot-test: @if ! docker image inspect local/nit-test >/dev/null 2>&1; then \ echo "boot-test: local/nit-test not present; run 'make test' first"; exit 1; \ fi; \ docker run --rm --entrypoint /bin/sh local/nit-test -c '/usr/local/bin/nit-boot-gate'