Files
w3cjandClaude Opus 5.5 9348a1e518 refactor(assets): one prelude for the build scripts' architecture, libc and pins
assets/prelude.sh gives each of devvm's scripts that a build runs with
bash $devvm_arch (arm64 or amd64), $devvm_libc (musl where apk is, else
gnu) and devvm_sha TOOL (the script's TOOL_sha256_<arch>_musl on musl
where it pins one, else TOOL_sha256_<arch>). It replaces the arch and sha
helpers in layers/base.sh, layers/nix.sh, features/cli-tools.sh,
shared-tools/build.sh and oci/build.sh, and the Alpine checks in
docker.sh, desktop.sh and fzf.sh. Each script that reads it checks it
came first (: "${devvm_arch:?}").

image.OwnScript reads devvm's own scripts with the prelude before them:
base.sh, apt.sh, built-in layers (LayerData) and features (featureStep),
shared-tools/build.sh (the tools build and ToolFile's key) and the
conversion's oci/build.sh (Lima's convertSteps, written into the
conversion's own temp folder). Users' layers and features get none.
keyHash.own goes, its one caller now hashing OwnScript's bytes.

Image keys change: every image and every shared tool image rebuilds.

Tests: testdata/script/prelude.txtar pins which pin devvm_sha picks from
each script on arm64 (aarch64 and arm64) and amd64, gnu and musl, and
refuses another architecture and a missing pin; oci.txtar sources the
prelude first and checks build.sh stops without it; TestOwnScript,
TestPreludeUsers (only scripts that get the prelude use it, each checks
its variables), key rows for the prelude in build and tool keys, and
recipe expectations with the prelude before devvm's scripts only.
e2e's nix copy as a user layer starts with the prelude.

Docs: internals/images.md (the scripts' prelude, keys), contributing
(owner, agreement test), maintaining, assets/oci/README.md, AGENTS.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 15:57:21 -07:00

26 lines
1.4 KiB
Bash

#!/bin/bash
# devvm's prelude, which comes first in each of devvm's own scripts that an image's build runs with
# bash: layers/base.sh and apt.sh, the built-in layers and features, shared-tools/build.sh and
# oci/build.sh. devvm puts it before the script on the script's standard input (oci/build.sh: in the
# conversion's copy), and the image's key hashes the two together. It sets no shell options and runs
# only uname and command -v. Each script that uses it checks that it came first:
# : "${devvm_arch:?}" "${devvm_libc:?}"
# What it gives the script:
# $devvm_arch this machine's architecture as devvm's pins name it: arm64 or amd64
# $devvm_libc its C library: musl on Alpine (it has apk), gnu elsewhere
# devvm_sha TOOL TOOL's pinned SHA-256 for this machine, from the script's own pins:
# TOOL_sha256_<arch>_musl on musl where the script pins one, else TOOL_sha256_<arch>
case $(uname -m) in
aarch64 | arm64) devvm_arch=arm64 ;;
x86_64 | amd64) devvm_arch=amd64 ;;
*) echo "devvm: devvm's downloads have no build for $(uname -m)" >&2; exit 1 ;;
esac
if command -v apk >/dev/null 2>&1; then devvm_libc=musl; else devvm_libc=gnu; fi
devvm_sha() {
local v=${1}_sha256_$devvm_arch m
m=${v}_musl
if [[ $devvm_libc == musl && -n ${!m:-} ]]; then v=$m; fi
[[ -n ${!v:-} ]] || { echo "devvm: this script pins no $v" >&2; return 1; }
echo "${!v}"
}