Skip to content

Take an image build's platform from its manifest, and ignore root's environment - #546

Merged
maralcbr merged 3 commits into
quattro-upstreamfrom
mac/24-image-target
Sep 25, 2026
Merged

maralcbr merged 3 commits into
quattro-upstreamfrom
mac/24-image-target

Conversation

@maralcbr

Copy link
Copy Markdown
Member

Ticket 24. An Apple image built on a non-Apple host got generic-aarch64 from omarchy-hw-platform, because as root it reads only the live device tree. The Apple initramfs, services and packages then went missing, and the platform guard (#539) would refuse the Apple packages.

What changed

  • The manifest names an image's platform. While a root is being built, omarchy-hw-platform prints the platform in the root-owned image-target manifest from Defer image hardware setup to the Mac's first boot #528 (/var/lib/omarchy/image/target). It never reads the build host's device tree.

  • How a build is told from a booted system. A root counts as booted only when systemd runs it as PID 1. The detector treats it as a build when any of these is visible:

    • there is no /run/systemd/system (arch-chroot, pacstrap and the image builder each give the root its own /run);
    • PID 1's root is a different one (a chroot on the build host);
    • PID 1 is not systemd (a PID-namespace build, even with the host's /run bound in).

    Anything the caller cannot see counts as booted: PID 1's root for a normal user, or PID 1 hidden by hidepid. So a booted Mac, Snapdragon, VM or x86 machine always answers from its hardware, even when a stale or broken manifest is left behind.

  • A bad manifest stops a build instead of guessing. Each of these fails the detector, which stops mkinitcpio and the guard:

    • the file or its directory is not owned by root, or is writable by others;
    • the manifest is a symlink or not a regular file;
    • it has the wrong format or an unknown platform;
    • its platform contradicts the CPU.

    The manifest is parsed by the same rules as install/helpers/image-target.sh. The detector reads it itself, so a copy of the detector shipped in another package still works.

  • Root's environment cannot change the answer. The detector and both Apple predicates now run as bash -p. As root, the detector restarts under env -i with a fixed PATH, the same way Lifecycle dispatch interface, wired into owner provisioning #540's dispatcher and Add the package platform tag and a pacman platform guard #539's guard do. Exported functions, BASH_ENV, PATH and the fixture roots therefore have no effect on what root gets. This closes the exported-function hole found in ticket 17. The predicates also stop looking anything up in PATH.

  • First boot asks the hardware after retiring the manifest. omarchy-provision-hardware now calls the detector only after it has retired the manifest, so its log line always shows the real hardware.

  • Callers need no change. 00-omarchy-hooks.conf, the systemd-oomd step in enable-services.sh, omarchy-pkg-defaults, the Build the Apple initramfs drop-ins on the HOOKS baseline, Apple only #544 drop-ins and the Add the package platform tag and a pacman platform guard #539 guard all go through the detector.

For the stacked work

  • Add the package platform tag and a pacman platform guard #539: the guard's own build check and manifest reader agree with this change. In its "booted" branch the guard calls its copy of the detector, which now also reads the manifest in PID-namespace builds. Once both are merged, the guard can rely on the detector alone. Its doc line saying nspawn and PID-namespace builds count as booted will then be out of date.
  • Image builder (ticket 23): omarchy-hw-platform no longer relies on the builder's fake /sys/firmware device tree. Other probes still read that tree. The builder must write the manifest before the first transaction that runs mkinitcpio or the guard, and must give the root its own /run. The old OMARCHY_PROC_ROOT probe in configured_phases.py on the installer's main branch does nothing for root and can be removed.

Tests

  • New test, test/shell.d/image-target-platform-test.sh, with fixtures for:
    • builds on an x86 host (emulated aarch64) and on a generic aarch64 host, both in a chroot;
    • a PID-namespace build, with and without the host's /run;
    • a build without /proc;
    • a generic image built on a Mac;
    • booted Mac, Snapdragon, x86 and VM systems with a stale manifest, and a booted system seen by a normal user or through hidepid;
    • no manifest, and a retired manifest;
    • every kind of invalid manifest, including one owned by another user;
    • the consumers: the Apple predicate, the HOOKS baseline, systemd-oomd and the default package set.
  • Probes that need user, mount and PID namespaces (skipped where unshare is blocked, as in CI):
    • root with hostile fixture roots, PATH, BASH_ENV and exported uname, mapfile, stat and dirname functions, with and without --clean-environment;
    • root reading the manifest at the live path while the build process is PID 1;
    • a booted root (PID 1 is systemd) ignoring the manifest;
    • a manifest owned by another user.
  • First boot: image-deferred-hardware-test.sh gains a case where an image boots on other hardware.
  • Checks against the old code: the old detector fails the hostile-environment and build cases, and the old first-boot order fails the new case.
  • What was run:
    • the full runtime suite as non-root in an x86 Arch container matching CI: 304 of 307 pass. The failures were hermes-remove (a known failure), update-lock (also fails on the base branch in this container) and snapshot-restore (passes when rerun alone);
    • every test that uses the detector, plus the omarchy-mac package suite, rerun on the final commit;
    • the namespace probes in privileged x86 and native arm64 containers;
    • shellcheck on the changed scripts.

Second review, two rounds: it found no blockers. All verified findings are fixed: PID 1 must be systemd for a root to count as booted, hidden state never counts as a build, the probes are no longer vacuous on a Mac, and the detector restarts from BASH_SOURCE. One limit is documented: a caller in a private PID namespace looks like a build, so a test keeps PrivatePIDs= out of the units. Fable re-check owed (initramfs selection).

…ironment out of the detector

While a root is being built rather than booted, omarchy-hw-platform prints the
platform the root-owned image-target manifest names instead of reading the build
host's device tree, so an Apple image built on any host gets the Apple initramfs,
services and packages. A booted system, one systemd runs from PID 1's root,
always answers from its hardware, even with a stale manifest.

The detector and the Apple predicates run in bash's privileged mode, and root
restarts the detector in an empty environment, so exported functions, BASH_ENV,
PATH and fixture roots cannot pick the platform for a privileged caller.
…hat cannot be seen

A PID namespace build with the host's /run bound in showed systemd's runtime
directory and PID 1 in the root, so it passed for a booted system. PID 1 must
also be systemd. What a caller cannot see, PID 1's root or PID 1 behind
hidepid, no longer makes a build, so a booted system always answers from its
hardware. The probes pick a target the live hardware would not give, so they
also hold on a Mac.
…rivate PID namespaces

bash run on a script found through PATH sets $0 to the bare name, which the
restarted shell's fixed PATH may not find; BASH_SOURCE holds the path. A
caller in a private PID namespace looks like a build, so the docs say so and a
test keeps PrivatePIDs= out of the units. The live probe skips on a noexec
temporary directory.
@maralcbr
maralcbr merged commit 1d24f65 into quattro-upstream Sep 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant