# Container Runner purpose layer; runs inside the isolated Arch builder. # Composes a server Purpose from the cycle's immutable Core; no desktop stack. test -f /core-input/evidence/databases.sha256 test -d /core-input/repo rmdir /job/core pacman -S --needed --noconfirm python ostree --repo=/job/repo init --mode=archive core_layer=$(cat /job/core-layer.commit) ostree --repo=/job/repo pull-local /core-input/repo "$core_layer" ostree --repo=/job/repo refs --create=layers/core "$core_layer" ostree --repo=/job/repo checkout --force-copy --subpath=payload "$core_layer" /job/core-base snapshot=$(cat /job/core-base/usr/lib/archipelago/snapshot) printf '%s\n' "$core_layer" > /job/evidence/reused-core.commit cp -a /core-input/evidence/*.db /job/evidence/ cp -a /core-input/package-repo /job/package-repo cp -a /core-input/private-package-cache /job/private-package-cache pacman-key --add /core-input/evidence/package-signer.asc pacman-key --lsign-key "$(cat /core-input/evidence/package-signer.txt)" cat >> /etc/pacman.conf <<'CORE_PACKAGE_REPOSITORY' [archipelago] SigLevel = Required Server = file:///job/package-repo CORE_PACKAGE_REPOSITORY pacman -Sy --noconfirm # Preserve the exact Core repository universe; never refresh target sync databases. cp -a --reflink=auto /job/core-base /job/purpose-stage stage=/job/purpose-stage mv "$stage/usr/etc" "$stage/etc" mkdir -p "$stage/var/lib" "$stage/dev" "$stage/proc" "$stage/sys" "$stage/run" "$stage/tmp" mv "$stage/usr/lib/archipelago/package-db" "$stage/var/lib/pacman" sed -i '/^DBPath = /d' "$stage/etc/pacman.conf" test -f "$stage/var/lib/pacman/sync/multilib.db" test -f "$stage/etc/pacman.d/archipelago-repos/base.conf" printf '[multilib]\nInclude = /etc/pacman.d/mirrorlist\n' > "$stage/etc/pacman.d/archipelago-repos/multilib.conf" cp -a /etc/pacman.d/gnupg "$stage/etc/pacman.d/" mkdir -p "$stage/etc/pacman.d/hooks" ln -sf /dev/null "$stage/etc/pacman.d/hooks/90-mkinitcpio-install.hook" rm "$stage/etc/resolv.conf" cp -L /etc/resolv.conf "$stage/etc/resolv.conf" cp /etc/pacman.d/mirrorlist "$stage/etc/pacman.d/mirrorlist" # Core intentionally contains factory accounts, reconciled by sysusers on boot. # This isolated build root is not booted; provision its package-manager identity # before pacman enables the standard alpm download sandbox. Factory accounts are # restored below before capturing the Purpose payload. arch-chroot "$stage" systemd-sysusers printf 'ARCHIPELAGO_PHASE\tpackages\n' mapfile -t purpose_packages < /job/container-runner-packages.txt mkdir -p "$stage/var/cache/pacman/pkg" # libalpm CheckSpace needs a mountpoint visible as / inside the chroot. Bind the # disposable root and shared verified archive cache instead of disabling checks. mount --bind "$stage" "$stage" trap 'umount "$stage/var/cache/pacman/pkg" 2>/dev/null || true; umount "$stage" 2>/dev/null || true' EXIT mount --bind /var/cache/pacman/pkg "$stage/var/cache/pacman/pkg" # Local repository packages are part of the Core snapshot too. Expose its exact # signed bytes at the file:// URL used by the preserved target pacman configuration. test ! -e "$stage/job" mkdir -p "$stage/job/package-repo" cp -a /job/package-repo/. "$stage/job/package-repo/" # Same-version private builds can have different bytes and signing keys. Match # Core's cache ordering so stale shared-cache signatures cannot shadow this run. cp -a /job/private-package-cache "$stage/job/private-package-cache" sed -i '/\[options\]/a CacheDir = /job/private-package-cache\nCacheDir = /var/cache/pacman/pkg' "$stage/etc/pacman.conf" arch-chroot "$stage" pacman -S --needed --noconfirm -- "${purpose_packages[@]}" 2>&1 | tee /job/evidence/purpose-transaction.log rm -rf "$stage/job/package-repo" "$stage/job/private-package-cache" rmdir "$stage/job" umount "$stage/var/cache/pacman/pkg" umount "$stage" trap - EXIT if grep -Ei 'error:|==> ERROR:' /job/evidence/purpose-transaction.log; then echo 'Required Purpose transaction action failed' >&2; exit 1 fi rm "$stage/etc/pacman.d/hooks/90-mkinitcpio-install.hook" cp -a /job/core-base/usr/etc/pacman.d/hooks/. "$stage/etc/pacman.d/hooks/" rm "$stage/etc/resolv.conf" cp -a /job/core-base/usr/etc/resolv.conf "$stage/etc/resolv.conf" for database in passwd shadow group gshadow; do cp -a "/job/core-base/usr/etc/$database" "$stage/etc/$database" # Shadow utilities also write backup databases containing staging identities. rm -f "$stage/etc/$database-" if [[ -e /job/core-base/usr/etc/$database- ]]; then cp -a "/job/core-base/usr/etc/$database-" "$stage/etc/$database-" fi done cp -a /job/core-base/usr/etc/pacman.conf "$stage/etc/pacman.conf" cp -a /job/core-base/usr/etc/pacman.d/mirrorlist "$stage/etc/pacman.d/mirrorlist" rm -rf "$stage/etc/pacman.d/gnupg" rm -f "$stage/etc/.pwd.lock" mv "$stage/var/lib/pacman" "$stage/usr/lib/archipelago/package-db" # The layer payload stores machine configuration at /usr/etc (Core's layout). # A plain rename nests the trees when a package already created usr/etc, which # would push every Core default one level down instead of merging the two. if [[ -d $stage/usr/etc ]]; then cp -a "$stage/etc/." "$stage/usr/etc/" rm -rf "$stage/etc" else mv "$stage/etc" "$stage/usr/etc" fi for db in /job/evidence/*.db; do cmp "$db" "$stage/usr/lib/archipelago/package-db/sync/$(basename "$db")"; done # Distribution integration is a separately indexed Purpose contribution. Preserve # Core package bytes and use distinct Purpose configuration paths. pkg=/job/purpose-assets mkdir -p "$pkg/runtime/usr/lib/archipelago/defaults" "$pkg/runtime/usr/lib/systemd/system" \ "$pkg/runtime/usr/lib/tmpfiles.d" "$pkg/runtime/usr/lib/systemd/system-preset" cp /job/core-base/usr/lib/archipelago/defaults/os-release "$pkg/runtime/usr/lib/archipelago/defaults/" cp /job/core-base/usr/lib/archipelago/mkinitcpio-core.conf "$pkg/runtime/usr/lib/archipelago/" @@CONTAINER_RUNNER_ASSETS@@ rm "$pkg/runtime/usr/lib/archipelago/defaults/os-release" "$pkg/runtime/usr/lib/archipelago/mkinitcpio-core.conf" cp -a "$pkg/runtime/." "$stage/" # Purpose assets are package payload too. Anything they ship under /etc belongs # to the layer's /usr/etc; a root /etc here would collide with the composed # machine configuration and make finalization lose pacman.conf (D-110 follow-up). if [[ -d $stage/etc ]]; then cp -a "$stage/etc/." "$stage/usr/etc/" rm -rf "$stage/etc" fi test ! -e "$stage/etc" test -f "$stage/usr/etc/pacman.conf" printf 'ARCHIPELAGO_PHASE\tcompose\n' python /job/layer-delta.py capture /job/core-base "$stage" /job/purpose-layer purpose/server/container-runner purpose_layer=$(ostree --repo=/job/repo commit --fsync=0 -b layers/purpose/server/container-runner --tree=dir=/job/purpose-layer \ --add-metadata-string=archipelago.snapshot="$snapshot") printf '%s\n' "$purpose_layer" > /job/evidence/purpose-layer.commit # Retain the original transaction output until commit checkout and composition # have both validated the payload. A failed copy must not destroy its source. ostree --repo=/job/repo checkout --force-copy "$purpose_layer" /job/purpose-input python /job/layer-delta.py compose /job/core-base /job/purpose-input /job/composed printf 'ARCHIPELAGO_PHASE\tfinalize\n' rm -rf /job/purpose-stage /job/purpose-layer /job/purpose-input # All work below operates on the composition, never the immutable input layers. mv /job/composed /job/core # Defense in depth: a composed root /etc (a payload that bypassed the layer # normalization) is merged, never nested. `mv` into an existing directory would # quietly bury the Core defaults as /etc/etc and lose pacman.conf. if [[ -d /job/core/etc ]]; then cp -a "/job/core/etc/." /job/core/usr/etc/ rm -rf /job/core/etc fi mv /job/core/usr/etc /job/core/etc test -f /job/core/etc/pacman.conf cp /job/core/usr/lib/archipelago/defaults/os-release-container-runner /job/core/etc/os-release @@CONTAINER_RUNNER_FINALIZE@@ # Force-copy checkout timestamps are host-local; deployments use OSTree's epoch. # Match that representation before checking the package's reproducible mtree. find /job/core/usr -exec touch -h -d @0 '{}' + # A staging root has factory accounts and no machine keyring. Query only the local # package DB, retaining the exact same integrity/permissions check as on the host. cp -a /job/core/etc/pacman.conf /job/finalize-pacman.conf printf '[options]\nDBPath = /usr/lib/archipelago/package-db/\n' > /job/core/etc/pacman.conf arch-chroot /job/core archipelago self-check mv /job/finalize-pacman.conf /job/core/etc/pacman.conf arch-chroot /job/core /bin/bash -euxc 'k=$(basename /usr/lib/modules/*); depmod "$k"; mkinitcpio -c /usr/lib/archipelago/mkinitcpio-container-runner.conf -k "$k" -g "/usr/lib/modules/$k/initramfs.img"; ldconfig; systemd-hwdb update --usr' arch-chroot /job/core /bin/bash -euc 'k=$(basename /usr/lib/modules/*); lsinitcpio "/usr/lib/modules/$k/initramfs.img"' > /job/evidence/container-runner-initramfs-files.txt test -x /job/core/usr/bin/podman test -x /job/core/usr/bin/toolbox test -f /job/core/etc/containers/toolbox.conf grep -q 'quay.io/toolbx/arch-toolbox:latest' /job/core/etc/containers/toolbox.conf test -f /job/core/usr/lib/systemd/system/cockpit.socket test -f /job/core/usr/lib/systemd/system/tailscaled.service # Inventory is a read-only local DB query: do not initialize repository trust or # the download sandbox in a finalized root containing factory accounts. arch-chroot /job/core pacman --config /dev/null --dbpath /usr/lib/archipelago/package-db -Q > /job/evidence/core-packages.txt cp /job/evidence/core-packages.txt /job/core/usr/lib/archipelago/packages.txt (cd /job/core; sha256sum usr/share/libalpm/hooks/*.hook) > /job/core/usr/lib/archipelago/hook-policy/hooks.sha256 find /job/core/usr/lib/archipelago/package-db/local -name install -exec sha256sum '{}' + > /job/core/usr/lib/archipelago/hook-policy/scriptlets.sha256 test ! -e /job/core/usr/etc mv /job/core/etc /job/core/usr/etc mv /job/core /job/composed # Clients only receive commit metadata before they decide to update. Measure the # composed tree once, then record both sizes in the published commit so the # software centers can show them without downloading the image. image=$(ostree --repo=/job/repo commit --fsync=0 --orphan --tree=dir=/job/composed) read -r image_transfer image_installed < <(python3 /job/image-size.py /job/repo "$image") [[ $image_transfer =~ ^[0-9]+$ && $image_installed =~ ^[0-9]+$ ]] ostree --repo=/job/repo commit --fsync=0 -b core --tree=dir=/job/composed \ --add-metadata-string=archipelago.snapshot="$snapshot" \ --add-metadata-string=archipelago.layer-core="$core_layer" \ --add-metadata-string=archipelago.layer-purpose="$purpose_layer" \ --add-metadata-string=archipelago.image-size="$image_transfer" \ --add-metadata-string=archipelago.image-installed-size="$image_installed" ostree --repo=/job/repo pull-local /core-input/repo test-marker test "$(ostree --repo=/core-input/repo rev-parse "$core_layer")" = "$core_layer" printf 'Core reused: %s\nPurpose: %s\n' "$core_layer" "$purpose_layer" > /job/evidence/composition.txt # Both trees are now reproducible from retained commits. Release scratch space # before archiso creates its live root, squashfs and ISO concurrently. rm -rf /job/composed /job/core-base