Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions build-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,43 @@ keep_apple_silicon_mkinitcpio_drop_ins() {
fail "lost the limine-entry-tool.d cleanup in $pkgbuild"
}

# Upstream's omarchy-settings PKGBUILD installs its user units from an explicit
# list rather than a glob, so a unit this fork adds under default/systemd/user/
# ships under /usr/share/omarchy/default/ but never reaches
# /usr/lib/systemd/user/, where first-run and the migration enable it. That is
# what 4.0.2-2 did with the ambient keyboard backlight unit: every install got
# a wants symlink to a unit systemd reports as not-found. Add an install line
# for each fork unit right after upstream's own, and step aside for a unit
# upstream has since adopted.
readonly fork_user_units=(
omarchy-brightness-keyboard-auto.service
)

install_fork_user_units() {
local pkgbuild="$1" unit last line

for unit in "${fork_user_units[@]}"; do
[[ -f "$checkout/default/systemd/user/$unit" ]] ||
fail "default/systemd/user/$unit is listed in fork_user_units but missing from the checkout"
if grep -qF "default/systemd/user/$unit " "$pkgbuild"; then
continue
fi

# Fail loudly if upstream restructures this. Silently not matching would
# ship a package without the unit, which is the failure this exists to
# prevent and the one that only shows as a dangling symlink after install.
last=$(grep -nE '^[[:space:]]*install -Dm644 default/systemd/user/[^[:space:]]+\.service ' "$pkgbuild" |
tail -n 1 | cut -d: -f1)
[[ -n $last ]] ||
fail "omarchy-settings PKGBUILD no longer installs user units as expected; re-check it against $pkgbuild"

line=" install -Dm644 default/systemd/user/$unit \"\$pkgdir/usr/lib/systemd/user/$unit\""
awk -v n="$last" -v line="$line" '{ print } NR == n { print line }' "$pkgbuild" >"$pkgbuild.tmp" &&
mv "$pkgbuild.tmp" "$pkgbuild"
grep -qF "$line" "$pkgbuild" || fail "could not add $unit to $pkgbuild"
done
}

# makepkg runs with --nodeps because the runtime dependencies include packages
# built here, so pacman cannot resolve them yet. That skips makedepends too,
# leaving the build tools to be installed up front.
Expand Down Expand Up @@ -187,6 +224,7 @@ build_package() {
fi
if [[ $package == "omarchy-settings" ]]; then
keep_apple_silicon_mkinitcpio_drop_ins "$build_dir/$package/PKGBUILD"
install_fork_user_units "$build_dir/$package/PKGBUILD"
fi
if [[ $package == "omarchy" || $package == "omarchy-settings" ]]; then
set_pkgrel "$build_dir/$package/PKGBUILD"
Expand Down
37 changes: 37 additions & 0 deletions test/shell.d/install-mac-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,43 @@ if ! (
fail "set_pkgrel no-ops without OMARCHY_PKGREL, writes a number, and rejects junk"
fi
rm -rf "$rel_dir"
# Upstream's package() lists its user units one by one, so a unit only this
# fork ships has to be added to that list or it never reaches
# /usr/lib/systemd/user/ and the migration that enables it dangles.
units_dir=$(mktemp -d)
cat >"$units_dir/PKGBUILD" <<'PKG'
package() {
install -Dm644 default/systemd/user/bt-agent.service "$pkgdir/usr/lib/systemd/user/bt-agent.service"
install -Dm644 default/systemd/user/omarchy-crash-watch.service "$pkgdir/usr/lib/systemd/user/omarchy-crash-watch.service"
install -d "$pkgdir/usr/share/omarchy/applications"
}
PKG
if ! (
source "$build_script"
install_fork_user_units "$units_dir/PKGBUILD"
# A second pass, or upstream adopting the unit, must not add it twice.
install_fork_user_units "$units_dir/PKGBUILD"
added='install -Dm644 default/systemd/user/omarchy-brightness-keyboard-auto.service "$pkgdir/usr/lib/systemd/user/omarchy-brightness-keyboard-auto.service"'
[[ $(grep -cF "$added" "$units_dir/PKGBUILD") == 1 ]] || exit 1
# Directly after upstream's last unit, so it stays inside package().
grep -A1 -F 'omarchy-crash-watch.service' "$units_dir/PKGBUILD" | grep -qF "$added" || exit 1
printf 'package() {\n install -d "$pkgdir/usr/share"\n}\n' >"$units_dir/PKGBUILD"
if ( install_fork_user_units "$units_dir/PKGBUILD" >/dev/null 2>&1 ); then
exit 1
fi
); then
rm -rf "$units_dir"
fail "install_fork_user_units adds each fork unit once after upstream's units and refuses an unrecognised package()"
fi
rm -rf "$units_dir"
pass "install_fork_user_units adds each fork unit once after upstream's units and refuses an unrecognised package()"

grep -A3 'package == "omarchy-settings"' "$build_script" | grep -q install_fork_user_units ||
fail "the package build installs the fork's user units into omarchy-settings"
grep -qF ' omarchy-brightness-keyboard-auto.service' "$build_script" ||
fail "the package build lists the ambient keyboard backlight unit as a fork unit"
pass "the package build installs the fork's user units into omarchy-settings"

grep -A2 'package == "omarchy-settings"' "$build_script" | grep -q set_pkgrel ||
fail "the package build stamps pkgrel on omarchy and omarchy-settings"
pass "the package build can stamp a Mac-only pkgrel on omarchy and omarchy-settings"
Expand Down
Loading