From b9de9915563b82b7be677842a095b019eea10cc4 Mon Sep 17 00:00:00 2001 From: Axel Fontaine Date: Wed, 12 Aug 2026 10:37:03 +0200 Subject: [PATCH 1/4] Register QEMU binfmt interpreters with OCF so sudo works under emulation qemu-user-static-binfmt ships FP flags by default. Docker cross-arch builds run emulated-architecture containers via QEMU, and setuid binaries like sudo only keep their privilege escalation under binfmt_misc emulation when the C (credentials) flag is set; O (open-binary) lets the interpreter run against a container whose rootfs differs from the host's. Override with OCF, derived from the package's own registrations, and add a migration for existing installs. Co-Authored-By: Claude Sonnet 5 --- install/config/all.sh | 1 + install/config/binfmt.sh | 10 ++++++++++ migrations/1786521494.sh | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 install/config/binfmt.sh create mode 100644 migrations/1786521494.sh diff --git a/install/config/all.sh b/install/config/all.sh index a221a39896d9..a763b2008ee3 100644 --- a/install/config/all.sh +++ b/install/config/all.sh @@ -6,6 +6,7 @@ run_logged "$OMARCHY_INSTALL/config/fix-powerprofilesctl-shebang.sh" run_logged "$OMARCHY_INSTALL/config/ssh-command-path.sh" run_logged "$OMARCHY_INSTALL/config/ssh-keepalive.sh" run_logged "$OMARCHY_INSTALL/config/docker.sh" +run_logged "$OMARCHY_INSTALL/config/binfmt.sh" run_logged "$OMARCHY_INSTALL/config/snapper.sh" run_logged "$OMARCHY_INSTALL/config/enable-services.sh" run_logged "$OMARCHY_INSTALL/config/firewall.sh" diff --git a/install/config/binfmt.sh b/install/config/binfmt.sh new file mode 100644 index 000000000000..e170f3f95214 --- /dev/null +++ b/install/config/binfmt.sh @@ -0,0 +1,10 @@ +# qemu-user-static-binfmt registers its interpreters with flags FP. Docker +# buildx cross-arch builds run emulated-architecture containers where setuid +# binaries (e.g. sudo) need the C flag to keep their credentials under QEMU, +# and O so the interpreter works against a container whose rootfs differs +# from the host's. Override with OCF, derived from the package's own +# registrations so any architectures it adds stay covered. +mkdir -p /etc/binfmt.d +for conf in /usr/lib/binfmt.d/qemu-*-static.conf; do + sed -E 's/:[A-Za-z]*$/:OCF/' "$conf" >"/etc/binfmt.d/$(basename "$conf")" +done diff --git a/migrations/1786521494.sh b/migrations/1786521494.sh new file mode 100644 index 000000000000..aa7d03730c12 --- /dev/null +++ b/migrations/1786521494.sh @@ -0,0 +1,19 @@ +echo "Fix QEMU binfmt registration so sudo works in emulated Docker cross-arch builds" + +OMARCHY_PATH="${OMARCHY_PATH:-/usr/share/omarchy}" +binfmt_config_script="$OMARCHY_PATH/install/config/binfmt.sh" + +as_root() { + if (( EUID == 0 )); then + "$@" + else + sudo "$@" + fi +} + +[[ -f $binfmt_config_script ]] || exit 0 + +grep -q ':OCF$' /etc/binfmt.d/qemu-aarch64-static.conf 2>/dev/null && exit 0 + +as_root bash -euo pipefail "$binfmt_config_script" +as_root systemctl restart systemd-binfmt.service From 6a5e34627fa6e5b1e0793b5aeb7247f1069c84c5 Mon Sep 17 00:00:00 2001 From: Axel Fontaine Date: Wed, 12 Aug 2026 16:47:38 +0200 Subject: [PATCH 2/4] Test the QEMU binfmt OCF fix and check every registered arch, not just aarch64 Add OMARCHY_BINFMT_SOURCE_DIR/OMARCHY_BINFMT_DIR overrides to the config script and migration so both can be tested without touching /etc or /usr/lib. Writing the test surfaced a real gap: the migration's already-fixed check only grepped qemu-aarch64-static.conf, so a partially-fixed install or an architecture qemu-user-static-binfmt adds later would be missed. It now checks every qemu-*-static.conf the package registers. Co-Authored-By: Claude Sonnet 5 --- install/config/binfmt.sh | 10 +- migrations/1786521494.sh | 14 ++- test/shell.d/binfmt-multiarch-test.sh | 135 ++++++++++++++++++++++++++ 3 files changed, 155 insertions(+), 4 deletions(-) create mode 100755 test/shell.d/binfmt-multiarch-test.sh diff --git a/install/config/binfmt.sh b/install/config/binfmt.sh index e170f3f95214..199cd9dba4b9 100644 --- a/install/config/binfmt.sh +++ b/install/config/binfmt.sh @@ -4,7 +4,11 @@ # and O so the interpreter works against a container whose rootfs differs # from the host's. Override with OCF, derived from the package's own # registrations so any architectures it adds stay covered. -mkdir -p /etc/binfmt.d -for conf in /usr/lib/binfmt.d/qemu-*-static.conf; do - sed -E 's/:[A-Za-z]*$/:OCF/' "$conf" >"/etc/binfmt.d/$(basename "$conf")" +binfmt_source_dir="${OMARCHY_BINFMT_SOURCE_DIR:-/usr/lib/binfmt.d}" +binfmt_dir="${OMARCHY_BINFMT_DIR:-/etc/binfmt.d}" + +mkdir -p "$binfmt_dir" +for conf in "$binfmt_source_dir"/qemu-*-static.conf; do + [[ -e $conf ]] || continue + sed -E 's/:[A-Za-z]*$/:OCF/' "$conf" >"$binfmt_dir/$(basename "$conf")" done diff --git a/migrations/1786521494.sh b/migrations/1786521494.sh index aa7d03730c12..340efb7dd601 100644 --- a/migrations/1786521494.sh +++ b/migrations/1786521494.sh @@ -2,6 +2,8 @@ echo "Fix QEMU binfmt registration so sudo works in emulated Docker cross-arch b OMARCHY_PATH="${OMARCHY_PATH:-/usr/share/omarchy}" binfmt_config_script="$OMARCHY_PATH/install/config/binfmt.sh" +binfmt_source_dir="${OMARCHY_BINFMT_SOURCE_DIR:-/usr/lib/binfmt.d}" +binfmt_dir="${OMARCHY_BINFMT_DIR:-/etc/binfmt.d}" as_root() { if (( EUID == 0 )); then @@ -13,7 +15,17 @@ as_root() { [[ -f $binfmt_config_script ]] || exit 0 -grep -q ':OCF$' /etc/binfmt.d/qemu-aarch64-static.conf 2>/dev/null && exit 0 +# Check every architecture the package itself registers, not just one, so an +# architecture added by a later package update still gets fixed. +needs_fix=0 +for conf in "$binfmt_source_dir"/qemu-*-static.conf; do + [[ -e $conf ]] || continue + grep -q ':OCF$' "$binfmt_dir/$(basename "$conf")" 2>/dev/null || { + needs_fix=1 + break + } +done +(( needs_fix )) || exit 0 as_root bash -euo pipefail "$binfmt_config_script" as_root systemctl restart systemd-binfmt.service diff --git a/test/shell.d/binfmt-multiarch-test.sh b/test/shell.d/binfmt-multiarch-test.sh new file mode 100755 index 000000000000..8440821f6c4f --- /dev/null +++ b/test/shell.d/binfmt-multiarch-test.sh @@ -0,0 +1,135 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +config_script="$ROOT/install/config/binfmt.sh" + +test_tmp=$(mktemp -d) +trap 'rm -rf "$test_tmp"' EXIT + +write_conf() { + # Shaped like the qemu-user-static-binfmt package's own registrations: + # a magic/mask binfmt_misc line ending in the flags field. + printf ':qemu-%s:M::magic:mask:/usr/bin/qemu-%s-static:FP\n' "$1" "$1" >"$2" +} + +# The config script rewrites every qemu-*-static registration the package +# ships, leaving the rest of each line untouched, and skips anything in the +# source directory that isn't a qemu static registration. +source_dir="$test_tmp/lib-binfmt.d" +dest_dir="$test_tmp/etc-binfmt.d" +mkdir -p "$source_dir" +write_conf aarch64 "$source_dir/qemu-aarch64-static.conf" +write_conf arm "$source_dir/qemu-arm-static.conf" +printf 'unrelated\n' >"$source_dir/other.conf" + +OMARCHY_BINFMT_SOURCE_DIR="$source_dir" OMARCHY_BINFMT_DIR="$dest_dir" \ + bash -euo pipefail "$config_script" >/dev/null + +grep -qFx ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:OCF' "$dest_dir/qemu-aarch64-static.conf" || + fail "binfmt config overrides aarch64 flags with OCF" +grep -qFx ':qemu-arm:M::magic:mask:/usr/bin/qemu-arm-static:OCF' "$dest_dir/qemu-arm-static.conf" || + fail "binfmt config overrides arm flags with OCF" +[[ -f $dest_dir/other.conf ]] && fail "binfmt config copies files that aren't qemu static registrations" +pass "binfmt config overrides every qemu static registration with OCF flags" + +# Re-running must stay clean and keep producing OCF. +OMARCHY_BINFMT_SOURCE_DIR="$source_dir" OMARCHY_BINFMT_DIR="$dest_dir" \ + bash -euo pipefail "$config_script" >/dev/null +grep -qFx ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:OCF' "$dest_dir/qemu-aarch64-static.conf" || + fail "binfmt config is idempotent" +pass "binfmt config is idempotent" + +# A dev checkout may run before qemu-user-static-binfmt is installed, so the +# source directory can be empty; the script must not fail on the unmatched +# glob. +empty_source_dir="$test_tmp/empty-lib-binfmt.d" +empty_dest_dir="$test_tmp/empty-etc-binfmt.d" +mkdir -p "$empty_source_dir" +OMARCHY_BINFMT_SOURCE_DIR="$empty_source_dir" OMARCHY_BINFMT_DIR="$empty_dest_dir" \ + bash -euo pipefail "$config_script" >/dev/null || + fail "binfmt config tolerates a source directory with no qemu registrations" +pass "binfmt config tolerates a source directory with no qemu registrations" + +# The migration that fixes existing installs. +migration=$(grep -rl 'Fix QEMU binfmt registration' "$ROOT/migrations" | head -n 1 || true) +[[ -n $migration ]] || fail "binfmt migration exists" + +fake_bin="$test_tmp/bin" +mkdir -p "$fake_bin" + +cat >"$fake_bin/sudo" <<'STUB' +#!/bin/bash +exec "$@" +STUB +chmod +x "$fake_bin/sudo" + +cat >"$fake_bin/systemctl" <<'STUB' +#!/bin/bash +printf 'systemctl %s\n' "$*" >>"$TEST_LOG" +STUB +chmod +x "$fake_bin/systemctl" + +run_migration() { + TEST_LOG="$test_tmp/calls.log" \ + PATH="$fake_bin:$PATH" \ + OMARCHY_PATH="$ROOT" \ + OMARCHY_BINFMT_SOURCE_DIR="$source_dir" \ + OMARCHY_BINFMT_DIR="$1" \ + bash -euo pipefail "$migration" >/dev/null +} + +# An install still carrying the old FP flags gets rewritten and the binfmt +# service restarted to pick it up. +stale_dir="$test_tmp/stale-etc-binfmt.d" +mkdir -p "$stale_dir" +write_conf aarch64 "$stale_dir/qemu-aarch64-static.conf" + +: >"$test_tmp/calls.log" +run_migration "$stale_dir" + +grep -qFx ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:OCF' "$stale_dir/qemu-aarch64-static.conf" || + fail "binfmt migration rewrites a stale registration" +grep -qFx 'systemctl restart systemd-binfmt.service' "$test_tmp/calls.log" || + fail "binfmt migration restarts systemd-binfmt.service" +pass "binfmt migration fixes existing installs and restarts the binfmt service" + +# Already-fixed installs are left alone. +: >"$test_tmp/calls.log" +run_migration "$stale_dir" +[[ ! -s $test_tmp/calls.log ]] || fail "binfmt migration skips already-fixed installs" +pass "binfmt migration is a no-op once the registration already carries OCF" + +# A partially-fixed install (say aarch64 was hand-edited already, or the +# package added an architecture after this migration last ran for this user) +# must still be caught: the check has to look at every architecture the +# package registers, not just one. +partial_dir="$test_tmp/partial-etc-binfmt.d" +mkdir -p "$partial_dir" +printf ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:OCF\n' >"$partial_dir/qemu-aarch64-static.conf" +write_conf arm "$partial_dir/qemu-arm-static.conf" + +: >"$test_tmp/calls.log" +run_migration "$partial_dir" + +grep -qFx ':qemu-arm:M::magic:mask:/usr/bin/qemu-arm-static:OCF' "$partial_dir/qemu-arm-static.conf" || + fail "binfmt migration fixes an architecture still on FP even when another already carries OCF" +grep -qFx 'systemctl restart systemd-binfmt.service' "$test_tmp/calls.log" || + fail "binfmt migration restarts systemd-binfmt.service for a partially-fixed install" +pass "binfmt migration checks every registered architecture, not just one" + +# A dev checkout carries migrations from a release whose install scripts the +# checked-out tree may not have yet, and omarchy-migrate runs under set -e. +: >"$test_tmp/calls.log" +missing_dir="$test_tmp/missing-etc-binfmt.d" +TEST_LOG="$test_tmp/calls.log" \ +PATH="$fake_bin:$PATH" \ +OMARCHY_PATH="$test_tmp/empty" \ +OMARCHY_BINFMT_SOURCE_DIR="$source_dir" \ +OMARCHY_BINFMT_DIR="$missing_dir" \ + bash -euo pipefail "$migration" >/dev/null || + fail "binfmt migration survives a tree without the binfmt config script" +[[ ! -s $test_tmp/calls.log ]] || fail "binfmt migration touches nothing without the binfmt config script" +pass "binfmt migration is a no-op when the binfmt config script is missing" From e0a0f5f63a41a725f056906ef6c4f56baabc28b9 Mon Sep 17 00:00:00 2001 From: Axel Fontaine Date: Mon, 5 Oct 2026 11:34:32 +0200 Subject: [PATCH 3/4] Add O and C to the QEMU binfmt flags instead of replacing them The config script replaced each registration's entire flags field with the literal string OCF, silently dropping the package's P flag (preserve-argv0) and any other flag a later package update might add. That's a system-wide side effect -- this writes to /etc/binfmt.d/, not something Docker-scoped -- beyond what fixing sudo under QEMU needs. Only C is required for that; O lets the interpreter work against a differing rootfs. Measured by @omarchybot on PR #6736: FP alone fails sudo, OCF fixes sudo but changes argv[0] system-wide, POCF fixes sudo and keeps argv[0] correct. Add O and C to whatever flags are already there instead, and update the migration's completion check and the test's expectations to match. Co-Authored-By: Claude Sonnet 5 --- install/config/binfmt.sh | 14 +++++++--- migrations/1786521494.sh | 11 ++++++-- test/shell.d/binfmt-multiarch-test.sh | 38 ++++++++++++++++++--------- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/install/config/binfmt.sh b/install/config/binfmt.sh index 199cd9dba4b9..9089b4e3a6a3 100644 --- a/install/config/binfmt.sh +++ b/install/config/binfmt.sh @@ -2,13 +2,21 @@ # buildx cross-arch builds run emulated-architecture containers where setuid # binaries (e.g. sudo) need the C flag to keep their credentials under QEMU, # and O so the interpreter works against a container whose rootfs differs -# from the host's. Override with OCF, derived from the package's own -# registrations so any architectures it adds stay covered. +# from the host's. Add O and C to whatever flags the package's own +# registrations already carry -- never drop P, which keeps argv[0] as the +# original filename, or any other flag a later package update might add. binfmt_source_dir="${OMARCHY_BINFMT_SOURCE_DIR:-/usr/lib/binfmt.d}" binfmt_dir="${OMARCHY_BINFMT_DIR:-/etc/binfmt.d}" mkdir -p "$binfmt_dir" for conf in "$binfmt_source_dir"/qemu-*-static.conf; do [[ -e $conf ]] || continue - sed -E 's/:[A-Za-z]*$/:OCF/' "$conf" >"$binfmt_dir/$(basename "$conf")" + + line=$(<"$conf") + flags=${line##*:} + for flag in O C; do + [[ $flags == *$flag* ]] || flags+=$flag + done + + printf '%s:%s\n' "${line%:*}" "$flags" >"$binfmt_dir/$(basename "$conf")" done diff --git a/migrations/1786521494.sh b/migrations/1786521494.sh index 340efb7dd601..e54beea0cfbc 100644 --- a/migrations/1786521494.sh +++ b/migrations/1786521494.sh @@ -20,10 +20,17 @@ as_root() { needs_fix=0 for conf in "$binfmt_source_dir"/qemu-*-static.conf; do [[ -e $conf ]] || continue - grep -q ':OCF$' "$binfmt_dir/$(basename "$conf")" 2>/dev/null || { + installed="$binfmt_dir/$(basename "$conf")" + if [[ -r $installed ]]; then + flags=$(<"$installed") + flags=${flags##*:} + else + flags="" + fi + if [[ $flags != *O* || $flags != *C* ]]; then needs_fix=1 break - } + fi done (( needs_fix )) || exit 0 diff --git a/test/shell.d/binfmt-multiarch-test.sh b/test/shell.d/binfmt-multiarch-test.sh index 8440821f6c4f..e4db238d23ab 100755 --- a/test/shell.d/binfmt-multiarch-test.sh +++ b/test/shell.d/binfmt-multiarch-test.sh @@ -28,20 +28,34 @@ printf 'unrelated\n' >"$source_dir/other.conf" OMARCHY_BINFMT_SOURCE_DIR="$source_dir" OMARCHY_BINFMT_DIR="$dest_dir" \ bash -euo pipefail "$config_script" >/dev/null -grep -qFx ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:OCF' "$dest_dir/qemu-aarch64-static.conf" || - fail "binfmt config overrides aarch64 flags with OCF" -grep -qFx ':qemu-arm:M::magic:mask:/usr/bin/qemu-arm-static:OCF' "$dest_dir/qemu-arm-static.conf" || - fail "binfmt config overrides arm flags with OCF" +grep -qFx ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:FPOC' "$dest_dir/qemu-aarch64-static.conf" || + fail "binfmt config adds O and C to aarch64 flags without dropping FP" +grep -qFx ':qemu-arm:M::magic:mask:/usr/bin/qemu-arm-static:FPOC' "$dest_dir/qemu-arm-static.conf" || + fail "binfmt config adds O and C to arm flags without dropping FP" [[ -f $dest_dir/other.conf ]] && fail "binfmt config copies files that aren't qemu static registrations" -pass "binfmt config overrides every qemu static registration with OCF flags" +pass "binfmt config adds O and C to every qemu static registration without dropping existing flags" -# Re-running must stay clean and keep producing OCF. +# Re-running must stay clean and keep producing FPOC, not pile up duplicate +# letters (FPOCOC, ...). OMARCHY_BINFMT_SOURCE_DIR="$source_dir" OMARCHY_BINFMT_DIR="$dest_dir" \ bash -euo pipefail "$config_script" >/dev/null -grep -qFx ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:OCF' "$dest_dir/qemu-aarch64-static.conf" || +grep -qFx ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:FPOC' "$dest_dir/qemu-aarch64-static.conf" || fail "binfmt config is idempotent" pass "binfmt config is idempotent" +# A registration that already carries O and C (just reordered, or with an +# extra flag the package added later) is left untouched rather than +# duplicated. +preset_dir="$test_tmp/preset-etc-binfmt.d" +mkdir -p "$preset_dir" +printf ':qemu-riscv64:M::magic:mask:/usr/bin/qemu-riscv64-static:FPOCX\n' >"$source_dir/qemu-riscv64-static.conf" +OMARCHY_BINFMT_SOURCE_DIR="$source_dir" OMARCHY_BINFMT_DIR="$preset_dir" \ + bash -euo pipefail "$config_script" >/dev/null +grep -qFx ':qemu-riscv64:M::magic:mask:/usr/bin/qemu-riscv64-static:FPOCX' "$preset_dir/qemu-riscv64-static.conf" || + fail "binfmt config leaves a registration that already has O and C untouched" +pass "binfmt config leaves a registration that already has O and C untouched" +rm -f "$source_dir/qemu-riscv64-static.conf" + # A dev checkout may run before qemu-user-static-binfmt is installed, so the # source directory can be empty; the script must not fail on the unmatched # glob. @@ -90,7 +104,7 @@ write_conf aarch64 "$stale_dir/qemu-aarch64-static.conf" : >"$test_tmp/calls.log" run_migration "$stale_dir" -grep -qFx ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:OCF' "$stale_dir/qemu-aarch64-static.conf" || +grep -qFx ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:FPOC' "$stale_dir/qemu-aarch64-static.conf" || fail "binfmt migration rewrites a stale registration" grep -qFx 'systemctl restart systemd-binfmt.service' "$test_tmp/calls.log" || fail "binfmt migration restarts systemd-binfmt.service" @@ -100,7 +114,7 @@ pass "binfmt migration fixes existing installs and restarts the binfmt service" : >"$test_tmp/calls.log" run_migration "$stale_dir" [[ ! -s $test_tmp/calls.log ]] || fail "binfmt migration skips already-fixed installs" -pass "binfmt migration is a no-op once the registration already carries OCF" +pass "binfmt migration is a no-op once the registration already carries O and C" # A partially-fixed install (say aarch64 was hand-edited already, or the # package added an architecture after this migration last ran for this user) @@ -108,14 +122,14 @@ pass "binfmt migration is a no-op once the registration already carries OCF" # package registers, not just one. partial_dir="$test_tmp/partial-etc-binfmt.d" mkdir -p "$partial_dir" -printf ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:OCF\n' >"$partial_dir/qemu-aarch64-static.conf" +printf ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:FPOC\n' >"$partial_dir/qemu-aarch64-static.conf" write_conf arm "$partial_dir/qemu-arm-static.conf" : >"$test_tmp/calls.log" run_migration "$partial_dir" -grep -qFx ':qemu-arm:M::magic:mask:/usr/bin/qemu-arm-static:OCF' "$partial_dir/qemu-arm-static.conf" || - fail "binfmt migration fixes an architecture still on FP even when another already carries OCF" +grep -qFx ':qemu-arm:M::magic:mask:/usr/bin/qemu-arm-static:FPOC' "$partial_dir/qemu-arm-static.conf" || + fail "binfmt migration fixes an architecture still on FP even when another already carries O and C" grep -qFx 'systemctl restart systemd-binfmt.service' "$test_tmp/calls.log" || fail "binfmt migration restarts systemd-binfmt.service for a partially-fixed install" pass "binfmt migration checks every registered architecture, not just one" From 8b1ec1fd06b98f89aa125d2f1e6ebeed63dd48a2 Mon Sep 17 00:00:00 2001 From: Axel Fontaine Date: Tue, 6 Oct 2026 14:55:11 +0200 Subject: [PATCH 4/4] Keep QEMU binfmt overrides in step with qemu updates via a pacman hook Replace the one-time copy into /etc/binfmt.d with omarchy-apply-binfmt, run from a post-transaction hook on the qemu registrations, from system setup and once from the migration. It follows changed, added and removed registrations, only touches overrides it marked as managed, and restarts systemd-binfmt whenever the running registrations still differ. Co-Authored-By: Claude Opus 5.5 --- bin/omarchy-apply-binfmt | 131 +++++++++ default/libalpm/hooks/30-omarchy-binfmt.hook | 14 + docs/update-process.md | 2 + install/config/binfmt.sh | 25 +- migrations/1786521494.sh | 38 --- migrations/1791290450.sh | 3 + test/shell.d/binfmt-multiarch-test.sh | 276 ++++++++++--------- test/shell.d/config-test.sh | 1 + 8 files changed, 304 insertions(+), 186 deletions(-) create mode 100755 bin/omarchy-apply-binfmt create mode 100644 default/libalpm/hooks/30-omarchy-binfmt.hook delete mode 100644 migrations/1786521494.sh create mode 100644 migrations/1791290450.sh diff --git a/bin/omarchy-apply-binfmt b/bin/omarchy-apply-binfmt new file mode 100755 index 000000000000..28361bc20a97 --- /dev/null +++ b/bin/omarchy-apply-binfmt @@ -0,0 +1,131 @@ +#!/bin/bash + +# omarchy:summary=Keep QEMU binfmt registrations usable for setuid binaries in cross-arch containers +# omarchy:group=apply +# omarchy:requires-sudo=true +# omarchy:hidden=true + +# qemu-user-static-binfmt registers its interpreters with flags FP. Setuid +# binaries such as sudo in an emulated-architecture Docker container only keep +# their credentials under binfmt_misc emulation when the registration carries +# C (which implies O, handing the interpreter the binary as an open file). F, +# already set by the package, is what lets the interpreter run inside a +# container whose rootfs differs from the host's. +# +# This writes an /etc/binfmt.d override per package registration with O and C +# added to the package's own flags, so P (argv[0] preserved) and anything a +# later package adds survive. The 30-omarchy-binfmt pacman hook reruns it +# whenever qemu changes its registrations, so overrides follow interpreter, +# magic and mask changes, cover newly added architectures, and go away with +# removed ones. Files without the managed marker belong to the administrator +# and are left alone. +# +# C is machine-wide: QEMU runs a root-owned setuid foreign-architecture binary +# with root's credentials anywhere on the host, not only inside Docker. + +set -euo pipefail + +usage() { + cat <&2; exit 2 ;; +esac + +source_dir="${OMARCHY_BINFMT_SOURCE_DIR:-/usr/lib/binfmt.d}" +dest_dir="${OMARCHY_BINFMT_DIR:-/etc/binfmt.d}" +proc_dir="${OMARCHY_BINFMT_PROC_DIR:-/proc/sys/fs/binfmt_misc}" +marker="# Managed by omarchy-apply-binfmt from $source_dir; local edits are overwritten" + +managed() { + local first_line + [[ -f $1 ]] && IFS= read -r first_line <"$1" && [[ $first_line == "# Managed by omarchy-apply-binfmt "* ]] +} + +sorted_letters() { + grep -o . <<<"$1" | sort | tr -d '\n' +} + +declare -A writes=() +declare -A live_flags=() +removes=() + +for conf in "$source_dir"/qemu-*-static.conf; do + [[ -e $conf ]] || continue + + line=$(grep -m1 -v -e '^[#;]' -e '^$' "$conf" || true) + [[ -n $line ]] || continue + + flags=${line##*:} + for flag in O C; do + [[ $flags == *$flag* ]] || flags+=$flag + done + + target="$dest_dir/$(basename "$conf")" + if [[ -e $target ]] && ! managed "$target"; then + echo "Leaving unmanaged $target alone" >&2 + continue + fi + + content=$(printf '%s\n%s:%s' "$marker" "${line%:*}" "$flags") + if [[ ! -e $target || $(<"$target") != "$content" ]]; then + writes[$target]=$content + fi + + name=${line#:} + live_flags[${name%%:*}]=$flags +done + +for target in "$dest_dir"/qemu-*-static.conf; do + if [[ -e $target && ! -e $source_dir/$(basename "$target") ]] && managed "$target"; then + removes+=("$target") + fi +done + +restart=0 +if (( ${#writes[@]} || ${#removes[@]} )); then + restart=1 +elif [[ -e $proc_dir/status ]]; then + for name in "${!live_flags[@]}"; do + live=$(sed -n 's/^flags: //p' "$proc_dir/$name" 2>/dev/null || true) + if [[ $(sorted_letters "$live") != $(sorted_letters "${live_flags[$name]}") ]]; then + restart=1 + break + fi + done +fi + +if (( check )); then + exit "$restart" +fi + +if (( ${#writes[@]} )); then + mkdir -p "$dest_dir" + for target in "${!writes[@]}"; do + printf '%s\n' "${writes[$target]}" >"$target" + done +fi + +for target in "${removes[@]}"; do + rm -f "$target" +done + +# binfmt_misc is not mounted in the ISO's target chroot; the registrations load +# at first boot there. +if (( restart )) && [[ -e $proc_dir/status ]]; then + systemctl restart systemd-binfmt.service +fi diff --git a/default/libalpm/hooks/30-omarchy-binfmt.hook b/default/libalpm/hooks/30-omarchy-binfmt.hook new file mode 100644 index 000000000000..3c7dbe89252d --- /dev/null +++ b/default/libalpm/hooks/30-omarchy-binfmt.hook @@ -0,0 +1,14 @@ +# Sorts after 25-systemd-binfmt.hook, which reloads the package registrations +# that the overrides written here shadow. +[Trigger] +Type = Path +Operation = Install +Operation = Upgrade +Operation = Remove +Target = usr/lib/binfmt.d/qemu-*-static.conf + +[Action] +Description = Adding O and C to QEMU binfmt registrations... +When = PostTransaction +Depends = omarchy +Exec = /usr/bin/omarchy-apply-binfmt diff --git a/docs/update-process.md b/docs/update-process.md index b5e00925b461..d7801aaa3fa3 100644 --- a/docs/update-process.md +++ b/docs/update-process.md @@ -114,6 +114,8 @@ hook runs `omarchy-hyprland-reload-guard resume`, forces one `hyprctl reload`, and restores the session's previous `misc.disable_autoreload` and `debug.suppress_errors` values. +A post-transaction hook on `usr/lib/binfmt.d/qemu-*-static.conf` runs `omarchy-apply-binfmt`, which regenerates the `/etc/binfmt.d` overrides that add `O` and `C` to the QEMU registrations, so they follow every qemu update, and restarts `systemd-binfmt` when the running registrations differ. It sorts after systemd's own `25-systemd-binfmt.hook`. + ## Path 1: `omarchy update` High-level flow: diff --git a/install/config/binfmt.sh b/install/config/binfmt.sh index 9089b4e3a6a3..01baabfaad8f 100644 --- a/install/config/binfmt.sh +++ b/install/config/binfmt.sh @@ -1,22 +1,3 @@ -# qemu-user-static-binfmt registers its interpreters with flags FP. Docker -# buildx cross-arch builds run emulated-architecture containers where setuid -# binaries (e.g. sudo) need the C flag to keep their credentials under QEMU, -# and O so the interpreter works against a container whose rootfs differs -# from the host's. Add O and C to whatever flags the package's own -# registrations already carry -- never drop P, which keeps argv[0] as the -# original filename, or any other flag a later package update might add. -binfmt_source_dir="${OMARCHY_BINFMT_SOURCE_DIR:-/usr/lib/binfmt.d}" -binfmt_dir="${OMARCHY_BINFMT_DIR:-/etc/binfmt.d}" - -mkdir -p "$binfmt_dir" -for conf in "$binfmt_source_dir"/qemu-*-static.conf; do - [[ -e $conf ]] || continue - - line=$(<"$conf") - flags=${line##*:} - for flag in O C; do - [[ $flags == *$flag* ]] || flags+=$flag - done - - printf '%s:%s\n' "${line%:*}" "$flags" >"$binfmt_dir/$(basename "$conf")" -done +# Add O and C to the QEMU binfmt registrations so setuid binaries keep their +# credentials in emulated cross-arch containers; see omarchy-apply-binfmt. +omarchy-apply-binfmt diff --git a/migrations/1786521494.sh b/migrations/1786521494.sh deleted file mode 100644 index e54beea0cfbc..000000000000 --- a/migrations/1786521494.sh +++ /dev/null @@ -1,38 +0,0 @@ -echo "Fix QEMU binfmt registration so sudo works in emulated Docker cross-arch builds" - -OMARCHY_PATH="${OMARCHY_PATH:-/usr/share/omarchy}" -binfmt_config_script="$OMARCHY_PATH/install/config/binfmt.sh" -binfmt_source_dir="${OMARCHY_BINFMT_SOURCE_DIR:-/usr/lib/binfmt.d}" -binfmt_dir="${OMARCHY_BINFMT_DIR:-/etc/binfmt.d}" - -as_root() { - if (( EUID == 0 )); then - "$@" - else - sudo "$@" - fi -} - -[[ -f $binfmt_config_script ]] || exit 0 - -# Check every architecture the package itself registers, not just one, so an -# architecture added by a later package update still gets fixed. -needs_fix=0 -for conf in "$binfmt_source_dir"/qemu-*-static.conf; do - [[ -e $conf ]] || continue - installed="$binfmt_dir/$(basename "$conf")" - if [[ -r $installed ]]; then - flags=$(<"$installed") - flags=${flags##*:} - else - flags="" - fi - if [[ $flags != *O* || $flags != *C* ]]; then - needs_fix=1 - break - fi -done -(( needs_fix )) || exit 0 - -as_root bash -euo pipefail "$binfmt_config_script" -as_root systemctl restart systemd-binfmt.service diff --git a/migrations/1791290450.sh b/migrations/1791290450.sh new file mode 100644 index 000000000000..b1fd9549988c --- /dev/null +++ b/migrations/1791290450.sh @@ -0,0 +1,3 @@ +echo "Add O and C to QEMU binfmt registrations so sudo works in emulated Docker cross-arch builds" + +omarchy-apply-binfmt --check || sudo omarchy-apply-binfmt diff --git a/test/shell.d/binfmt-multiarch-test.sh b/test/shell.d/binfmt-multiarch-test.sh index e4db238d23ab..fc3b2cabd24d 100755 --- a/test/shell.d/binfmt-multiarch-test.sh +++ b/test/shell.d/binfmt-multiarch-test.sh @@ -4,146 +4,170 @@ set -euo pipefail source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" -config_script="$ROOT/install/config/binfmt.sh" +command="$ROOT/bin/omarchy-apply-binfmt" test_tmp=$(mktemp -d) trap 'rm -rf "$test_tmp"' EXIT -write_conf() { - # Shaped like the qemu-user-static-binfmt package's own registrations: - # a magic/mask binfmt_misc line ending in the flags field. - printf ':qemu-%s:M::magic:mask:/usr/bin/qemu-%s-static:FP\n' "$1" "$1" >"$2" -} - -# The config script rewrites every qemu-*-static registration the package -# ships, leaving the rest of each line untouched, and skips anything in the -# source directory that isn't a qemu static registration. source_dir="$test_tmp/lib-binfmt.d" dest_dir="$test_tmp/etc-binfmt.d" -mkdir -p "$source_dir" -write_conf aarch64 "$source_dir/qemu-aarch64-static.conf" -write_conf arm "$source_dir/qemu-arm-static.conf" -printf 'unrelated\n' >"$source_dir/other.conf" - -OMARCHY_BINFMT_SOURCE_DIR="$source_dir" OMARCHY_BINFMT_DIR="$dest_dir" \ - bash -euo pipefail "$config_script" >/dev/null - -grep -qFx ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:FPOC' "$dest_dir/qemu-aarch64-static.conf" || - fail "binfmt config adds O and C to aarch64 flags without dropping FP" -grep -qFx ':qemu-arm:M::magic:mask:/usr/bin/qemu-arm-static:FPOC' "$dest_dir/qemu-arm-static.conf" || - fail "binfmt config adds O and C to arm flags without dropping FP" -[[ -f $dest_dir/other.conf ]] && fail "binfmt config copies files that aren't qemu static registrations" -pass "binfmt config adds O and C to every qemu static registration without dropping existing flags" - -# Re-running must stay clean and keep producing FPOC, not pile up duplicate -# letters (FPOCOC, ...). -OMARCHY_BINFMT_SOURCE_DIR="$source_dir" OMARCHY_BINFMT_DIR="$dest_dir" \ - bash -euo pipefail "$config_script" >/dev/null -grep -qFx ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:FPOC' "$dest_dir/qemu-aarch64-static.conf" || - fail "binfmt config is idempotent" -pass "binfmt config is idempotent" - -# A registration that already carries O and C (just reordered, or with an -# extra flag the package added later) is left untouched rather than -# duplicated. -preset_dir="$test_tmp/preset-etc-binfmt.d" -mkdir -p "$preset_dir" -printf ':qemu-riscv64:M::magic:mask:/usr/bin/qemu-riscv64-static:FPOCX\n' >"$source_dir/qemu-riscv64-static.conf" -OMARCHY_BINFMT_SOURCE_DIR="$source_dir" OMARCHY_BINFMT_DIR="$preset_dir" \ - bash -euo pipefail "$config_script" >/dev/null -grep -qFx ':qemu-riscv64:M::magic:mask:/usr/bin/qemu-riscv64-static:FPOCX' "$preset_dir/qemu-riscv64-static.conf" || - fail "binfmt config leaves a registration that already has O and C untouched" -pass "binfmt config leaves a registration that already has O and C untouched" -rm -f "$source_dir/qemu-riscv64-static.conf" - -# A dev checkout may run before qemu-user-static-binfmt is installed, so the -# source directory can be empty; the script must not fail on the unmatched -# glob. -empty_source_dir="$test_tmp/empty-lib-binfmt.d" -empty_dest_dir="$test_tmp/empty-etc-binfmt.d" -mkdir -p "$empty_source_dir" -OMARCHY_BINFMT_SOURCE_DIR="$empty_source_dir" OMARCHY_BINFMT_DIR="$empty_dest_dir" \ - bash -euo pipefail "$config_script" >/dev/null || - fail "binfmt config tolerates a source directory with no qemu registrations" -pass "binfmt config tolerates a source directory with no qemu registrations" - -# The migration that fixes existing installs. -migration=$(grep -rl 'Fix QEMU binfmt registration' "$ROOT/migrations" | head -n 1 || true) -[[ -n $migration ]] || fail "binfmt migration exists" - +proc_dir="$test_tmp/binfmt_misc" fake_bin="$test_tmp/bin" -mkdir -p "$fake_bin" +calls="$test_tmp/calls.log" +mkdir -p "$source_dir" "$fake_bin" +cat >"$fake_bin/systemctl" <<'STUB' +#!/bin/bash +printf 'systemctl %s\n' "$*" >>"$TEST_LOG" +STUB cat >"$fake_bin/sudo" <<'STUB' #!/bin/bash +printf 'sudo %s\n' "$*" >>"$TEST_LOG" exec "$@" STUB -chmod +x "$fake_bin/sudo" +chmod +x "$fake_bin/systemctl" "$fake_bin/sudo" -cat >"$fake_bin/systemctl" <<'STUB' -#!/bin/bash -printf 'systemctl %s\n' "$*" >>"$TEST_LOG" -STUB -chmod +x "$fake_bin/systemctl" +write_conf() { + # Shaped like the qemu-user-static-binfmt package's own registrations: + # a magic/mask binfmt_misc line ending in the flags field. + printf ':qemu-%s:M::magic:mask:/usr/bin/qemu-%s-static:%s\n' "$1" "$1" "${3:-FP}" >"$2" +} + +registration() { + printf ':qemu-%s:M::magic:mask:/usr/bin/qemu-%s-static:%s' "$1" "$1" "$2" +} -run_migration() { - TEST_LOG="$test_tmp/calls.log" \ - PATH="$fake_bin:$PATH" \ - OMARCHY_PATH="$ROOT" \ +set_live() { + mkdir -p "$proc_dir" + : >"$proc_dir/status" + printf 'enabled\ninterpreter /usr/bin/qemu-%s-static\nflags: %s\n' "$1" "$2" >"$proc_dir/qemu-$1" +} + +apply() { + TEST_LOG="$calls" \ + PATH="$ROOT/bin:$fake_bin:$PATH" \ OMARCHY_BINFMT_SOURCE_DIR="$source_dir" \ - OMARCHY_BINFMT_DIR="$1" \ - bash -euo pipefail "$migration" >/dev/null + OMARCHY_BINFMT_DIR="$dest_dir" \ + OMARCHY_BINFMT_PROC_DIR="$proc_dir" \ + "$@" } -# An install still carrying the old FP flags gets rewritten and the binfmt -# service restarted to pick it up. -stale_dir="$test_tmp/stale-etc-binfmt.d" -mkdir -p "$stale_dir" -write_conf aarch64 "$stale_dir/qemu-aarch64-static.conf" - -: >"$test_tmp/calls.log" -run_migration "$stale_dir" - -grep -qFx ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:FPOC' "$stale_dir/qemu-aarch64-static.conf" || - fail "binfmt migration rewrites a stale registration" -grep -qFx 'systemctl restart systemd-binfmt.service' "$test_tmp/calls.log" || - fail "binfmt migration restarts systemd-binfmt.service" -pass "binfmt migration fixes existing installs and restarts the binfmt service" - -# Already-fixed installs are left alone. -: >"$test_tmp/calls.log" -run_migration "$stale_dir" -[[ ! -s $test_tmp/calls.log ]] || fail "binfmt migration skips already-fixed installs" -pass "binfmt migration is a no-op once the registration already carries O and C" - -# A partially-fixed install (say aarch64 was hand-edited already, or the -# package added an architecture after this migration last ran for this user) -# must still be caught: the check has to look at every architecture the -# package registers, not just one. -partial_dir="$test_tmp/partial-etc-binfmt.d" -mkdir -p "$partial_dir" -printf ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:FPOC\n' >"$partial_dir/qemu-aarch64-static.conf" -write_conf arm "$partial_dir/qemu-arm-static.conf" - -: >"$test_tmp/calls.log" -run_migration "$partial_dir" - -grep -qFx ':qemu-arm:M::magic:mask:/usr/bin/qemu-arm-static:FPOC' "$partial_dir/qemu-arm-static.conf" || - fail "binfmt migration fixes an architecture still on FP even when another already carries O and C" -grep -qFx 'systemctl restart systemd-binfmt.service' "$test_tmp/calls.log" || - fail "binfmt migration restarts systemd-binfmt.service for a partially-fixed install" -pass "binfmt migration checks every registered architecture, not just one" - -# A dev checkout carries migrations from a release whose install scripts the -# checked-out tree may not have yet, and omarchy-migrate runs under set -e. -: >"$test_tmp/calls.log" -missing_dir="$test_tmp/missing-etc-binfmt.d" -TEST_LOG="$test_tmp/calls.log" \ -PATH="$fake_bin:$PATH" \ -OMARCHY_PATH="$test_tmp/empty" \ -OMARCHY_BINFMT_SOURCE_DIR="$source_dir" \ -OMARCHY_BINFMT_DIR="$missing_dir" \ - bash -euo pipefail "$migration" >/dev/null || - fail "binfmt migration survives a tree without the binfmt config script" -[[ ! -s $test_tmp/calls.log ]] || fail "binfmt migration touches nothing without the binfmt config script" -pass "binfmt migration is a no-op when the binfmt config script is missing" +reset() { + rm -rf "$source_dir" "$dest_dir" "$proc_dir" + mkdir -p "$source_dir" + : >"$calls" +} + +# Every qemu static registration gets O and C added to the package's own flags, +# with the rest of the line untouched, and anything else is ignored. +reset +write_conf aarch64 "$source_dir/qemu-aarch64-static.conf" +write_conf arm "$source_dir/qemu-arm-static.conf" +printf 'unrelated\n' >"$source_dir/other.conf" + +apply "$command" --check && fail "--check reports pending registrations" +[[ ! -e $dest_dir ]] || fail "--check changes nothing" +apply "$command" + +grep -qFx "$(registration aarch64 FPOC)" "$dest_dir/qemu-aarch64-static.conf" || + fail "adds O and C to aarch64 flags without dropping FP" +grep -qFx "$(registration arm FPOC)" "$dest_dir/qemu-arm-static.conf" || + fail "adds O and C to arm flags without dropping FP" +grep -q '^# Managed by omarchy-apply-binfmt ' "$dest_dir/qemu-aarch64-static.conf" || + fail "marks overrides as managed" +[[ ! -e $dest_dir/other.conf ]] || fail "copies files that aren't qemu static registrations" +pass "adds O and C to every qemu static registration without dropping existing flags" + +# Re-running neither rewrites nor piles up duplicate letters. +before=$(cat "$dest_dir"/*.conf) +apply "$command" +[[ $(cat "$dest_dir"/*.conf) == "$before" ]] || fail "is idempotent" +apply "$command" --check || fail "--check passes once applied" +pass "is idempotent and --check passes once applied" + +# A registration that already carries O and C keeps its flags as they are. +reset +write_conf riscv64 "$source_dir/qemu-riscv64-static.conf" FPOCX +apply "$command" +grep -qFx "$(registration riscv64 FPOCX)" "$dest_dir/qemu-riscv64-static.conf" || + fail "leaves flags that already include O and C alone" +pass "leaves flags that already include O and C alone" + +# A package update that changes a registration, adds an architecture or drops +# one is followed, which a one-time copy would hide behind a stale override. +reset +write_conf aarch64 "$source_dir/qemu-aarch64-static.conf" +write_conf sparc "$source_dir/qemu-sparc-static.conf" +apply "$command" +sed -i 's/magic/magic2/' "$source_dir/qemu-aarch64-static.conf" +write_conf loongarch64 "$source_dir/qemu-loongarch64-static.conf" +rm "$source_dir/qemu-sparc-static.conf" +apply "$command" +grep -qFx ':qemu-aarch64:M::magic2:mask:/usr/bin/qemu-aarch64-static:FPOC' "$dest_dir/qemu-aarch64-static.conf" || + fail "follows a changed registration" +grep -qFx "$(registration loongarch64 FPOC)" "$dest_dir/qemu-loongarch64-static.conf" || + fail "covers an added architecture" +[[ ! -e $dest_dir/qemu-sparc-static.conf ]] || fail "removes the override of a dropped architecture" +pass "follows changed, added and dropped registrations" + +# Administrator-authored overrides are never rewritten or removed. +reset +mkdir -p "$dest_dir" +write_conf aarch64 "$source_dir/qemu-aarch64-static.conf" +printf ':qemu-aarch64:M::magic:mask:/opt/qemu/qemu-aarch64:F\n' >"$dest_dir/qemu-aarch64-static.conf" +printf ':qemu-m68k:M::magic:mask:/opt/qemu/qemu-m68k:F\n' >"$dest_dir/qemu-m68k-static.conf" +apply "$command" 2>/dev/null +grep -qFx ':qemu-aarch64:M::magic:mask:/opt/qemu/qemu-aarch64:F' "$dest_dir/qemu-aarch64-static.conf" || + fail "leaves an unmanaged override alone" +[[ -e $dest_dir/qemu-m68k-static.conf ]] || fail "leaves an unmanaged override without a registration alone" +pass "leaves administrator-authored overrides alone" + +# An empty source directory, as before qemu-user-static-binfmt is installed. +reset +apply "$command" || fail "tolerates a source directory with no qemu registrations" +pass "tolerates a source directory with no qemu registrations" + +# systemd-binfmt is restarted when overrides change, and when they are already +# on disk but the running registrations still carry the old flags. +reset +write_conf aarch64 "$source_dir/qemu-aarch64-static.conf" +set_live aarch64 PF +apply "$command" +grep -qFx 'systemctl restart systemd-binfmt.service' "$calls" || fail "restarts systemd-binfmt after writing overrides" + +: >"$calls" +apply "$command" +grep -qFx 'systemctl restart systemd-binfmt.service' "$calls" || + fail "restarts systemd-binfmt while running registrations lack O and C" + +: >"$calls" +set_live aarch64 POCF +apply "$command" +[[ ! -s $calls ]] || fail "leaves systemd-binfmt alone once running registrations match" +pass "restarts systemd-binfmt only while running registrations differ" + +# Without binfmt_misc mounted, as in the ISO's target chroot, overrides are +# still written and load at boot. +reset +write_conf aarch64 "$source_dir/qemu-aarch64-static.conf" +apply "$command" +[[ -e $dest_dir/qemu-aarch64-static.conf ]] || fail "writes overrides without binfmt_misc mounted" +[[ ! -s $calls ]] || fail "skips the restart without binfmt_misc mounted" +pass "writes overrides without restarting when binfmt_misc is not mounted" + +# The migration escalates only when something is pending, so a second user on +# an already fixed machine is not prompted. +migration=$(grep -rl 'omarchy-apply-binfmt' "$ROOT/migrations" | head -n 1 || true) +[[ -n $migration ]] || fail "binfmt migration exists" + +reset +write_conf aarch64 "$source_dir/qemu-aarch64-static.conf" +apply bash -euo pipefail "$migration" >/dev/null +grep -qFx "$(registration aarch64 FPOC)" "$dest_dir/qemu-aarch64-static.conf" || + fail "binfmt migration applies pending overrides" +grep -q '^sudo omarchy-apply-binfmt$' "$calls" || fail "binfmt migration escalates to apply" + +: >"$calls" +apply bash -euo pipefail "$migration" >/dev/null +[[ ! -s $calls ]] || fail "binfmt migration does not escalate once applied" +pass "binfmt migration escalates only when overrides are pending" diff --git a/test/shell.d/config-test.sh b/test/shell.d/config-test.sh index 12ffd85074da..6fbe7b001a66 100755 --- a/test/shell.d/config-test.sh +++ b/test/shell.d/config-test.sh @@ -186,6 +186,7 @@ if notify_alias not in pkgbuild: alpm_hooks = [ "00-omarchy-update-guard.hook", "10-omarchy-hyprland-reload-pause.hook", + "30-omarchy-binfmt.hook", "90-omarchy-hyprland-reload-resume.hook", ] for hook in alpm_hooks: