Purpose layers: merge /etc payload into usr/etc instead of nesting it

A purpose asset package (or any package shipping usr/etc) made 'mv etc usr/etc'
move one tree inside the other, so the composed root /etc appeared and the
finalizer lost /etc/pacman.conf: 'cp: cannot stat /job/core/etc/pacman.conf'.
This is why plasma-meta and the KDE keyboard defaults could not be composed.

- Merge the two trees when both exist, and assert the invariant that the layer
  payload has no root /etc and keeps usr/etc/pacman.conf.
- Do the same defense in depth after composition and before the final mv.
- Apply the identical fix to the Container Runner layer.
This commit is contained in:
Archipelago 2026-11-13 23:06:05 +03:00
parent ea2e9eb94e
commit 82829ca470
2 changed files with 54 additions and 2 deletions

View file

@ -87,7 +87,15 @@ 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"
mv "$stage/etc" "$stage/usr/etc"
# 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.
@ -99,6 +107,15 @@ cp /job/core-base/usr/lib/archipelago/mkinitcpio-core.conf "$pkg/runtime/usr/lib
@@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 \
@ -112,7 +129,15 @@ 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.
@ -135,6 +160,7 @@ arch-chroot /job/core pacman --config /dev/null --dbpath /usr/lib/archipelago/pa
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
ostree --repo=/job/repo commit --fsync=0 -b core --tree=dir=/job/composed \

View file

@ -87,7 +87,15 @@ 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"
mv "$stage/etc" "$stage/usr/etc"
# 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.
@ -99,6 +107,15 @@ cp /job/core-base/usr/lib/archipelago/mkinitcpio-core.conf "$pkg/runtime/usr/lib
@@GNOME_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_layer=$(ostree --repo=/job/repo commit --fsync=0 -b layers/purpose/desktop/gnome --tree=dir=/job/purpose-layer \
@ -112,7 +129,15 @@ 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-gnome /job/core/etc/os-release
@@GNOME_FINALIZE@@
# Force-copy checkout timestamps are host-local; deployments use OSTree's epoch.
@ -134,6 +159,7 @@ arch-chroot /job/core pacman --config /dev/null --dbpath /usr/lib/archipelago/pa
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
ostree --repo=/job/repo commit --fsync=0 -b core --tree=dir=/job/composed \