diff --git a/bin/omarchy-apply-pacman b/bin/omarchy-apply-pacman index e004637d..59f41506 100755 --- a/bin/omarchy-apply-pacman +++ b/bin/omarchy-apply-pacman @@ -53,12 +53,15 @@ else trap 'rm -rf "$staging"' EXIT fi cp "$OMARCHY_PATH/default/pacman/pacman-$channel.conf" "$staging/pacman.conf" -cp "$OMARCHY_PATH/default/pacman/mirrorlist-$channel" "$staging/mirrorlist" -if [[ $region != "global" ]]; then +if [[ $region == "global" ]]; then + cp "$OMARCHY_PATH/default/pacman/mirrorlist-$channel" "$staging/mirrorlist" +else profile="$OMARCHY_PATH/default/regions/$region/pacman" printf '\n' >> "$staging/pacman.conf" cat "$profile/pacman.conf.append" >> "$staging/pacman.conf" - cat "$profile/mirrorlist.append" >> "$staging/mirrorlist" + # pacman tries servers in order, so the regional mirror leads and the + # channel's own mirror stays as the fallback. + cat "$profile/mirrorlist-$channel.prepend" "$OMARCHY_PATH/default/pacman/mirrorlist-$channel" > "$staging/mirrorlist" fi [[ -z $render_dir ]] || exit 0 diff --git a/bin/omarchy-channel-set b/bin/omarchy-channel-set index 6a5c018f..60200f97 100755 --- a/bin/omarchy-channel-set +++ b/bin/omarchy-channel-set @@ -55,10 +55,10 @@ validate_dev_region() { [[ -f $region_file ]] && region=$(<"$region_file") [[ $region == "global" ]] && return 0 - # The refresh after linking needs a runnable helper and both fragments, not - # just a directory with the region's name. + # The refresh after linking needs a runnable helper and the edge fragments + # dev uses, not just a directory with the region's name. local profile="$checkout/default/regions/$region/pacman" - if [[ ! -x $checkout/bin/omarchy-apply-pacman || ! -r $profile/pacman.conf.append || ! -r $profile/mirrorlist.append ]]; then + if [[ ! -x $checkout/bin/omarchy-apply-pacman || ! -r $profile/pacman.conf.append || ! -r $profile/mirrorlist-edge.prepend ]]; then fail "$checkout does not support the '$region' region, so switching would drop its package repositories. Check out a branch with default/regions/$region, or remove $region_file to use global defaults." fi } diff --git a/default/regions/cn/pacman/mirrorlist-edge.prepend b/default/regions/cn/pacman/mirrorlist-edge.prepend new file mode 100644 index 00000000..50ca5dd2 --- /dev/null +++ b/default/regions/cn/pacman/mirrorlist-edge.prepend @@ -0,0 +1 @@ +Server = https://mirror.omarchy.cn/$repo/os/$arch diff --git a/default/regions/cn/pacman/mirrorlist-rc.prepend b/default/regions/cn/pacman/mirrorlist-rc.prepend new file mode 100644 index 00000000..0ffc1ba1 --- /dev/null +++ b/default/regions/cn/pacman/mirrorlist-rc.prepend @@ -0,0 +1 @@ +Server = https://rc-mirror.omarchy.cn/$repo/os/$arch diff --git a/default/regions/cn/pacman/mirrorlist-stable.prepend b/default/regions/cn/pacman/mirrorlist-stable.prepend new file mode 100644 index 00000000..90a2678c --- /dev/null +++ b/default/regions/cn/pacman/mirrorlist-stable.prepend @@ -0,0 +1 @@ +Server = https://stable-mirror.omarchy.cn/$repo/os/$arch diff --git a/default/regions/cn/pacman/mirrorlist.append b/default/regions/cn/pacman/mirrorlist.append deleted file mode 100644 index d0fe979a..00000000 --- a/default/regions/cn/pacman/mirrorlist.append +++ /dev/null @@ -1 +0,0 @@ -Server = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch diff --git a/test/shell.d/channel-test.sh b/test/shell.d/channel-test.sh index 72418727..fb670e3e 100644 --- a/test/shell.d/channel-test.sh +++ b/test/shell.d/channel-test.sh @@ -213,7 +213,7 @@ if grep -Eq $'^(link|refresh)\t' "$log_file"; then fail "dev refuses an empty region profile before linking or refreshing pacman" "$(cat "$log_file")" fi mkdir -p "$checkout/default/regions/cn/pacman" -touch "$checkout/default/regions/cn/pacman/pacman.conf.append" "$checkout/default/regions/cn/pacman/mirrorlist.append" +touch "$checkout/default/regions/cn/pacman/pacman.conf.append" "$checkout/default/regions/cn/pacman/mirrorlist-edge.prepend" chmod -x "$checkout/bin/omarchy-apply-pacman" if OMARCHY_TEST_REGION_FILE="$test_tmp/region" run_channel dev >"$test_tmp/region.out" 2>"$test_tmp/region.err"; then fail "dev refuses a checkout whose pacman helper cannot run" diff --git a/test/shell.d/region-pacman-test.sh b/test/shell.d/region-pacman-test.sh index 92b394ef..d02ea60d 100644 --- a/test/shell.d/region-pacman-test.sh +++ b/test/shell.d/region-pacman-test.sh @@ -27,12 +27,12 @@ pass "refresh keeps existing config file modes" printf 'cn\n' > "$TARGET_ROOT/etc/omarchy/region" for channel in stable rc edge; do case "$channel" in - stable) host=stable-mirror.omarchy.org ;; - rc) host=rc-mirror.omarchy.org ;; - edge) host=mirror.omarchy.org ;; + stable) host=stable-mirror.omarchy ;; + rc) host=rc-mirror.omarchy ;; + edge) host=mirror.omarchy ;; esac apply "$channel" - expected=$(printf 'Server = https://%s/$repo/os/$arch\nServer = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch' "$host") + expected=$(printf 'Server = https://%s.cn/$repo/os/$arch\nServer = https://%s.org/$repo/os/$arch' "$host" "$host") [[ $(<"$TARGET_ROOT/etc/pacman.d/mirrorlist") == "$expected" ]] || fail "$channel mirror order and variables" { cat "$ROOT/default/pacman/pacman-$channel.conf" @@ -43,7 +43,7 @@ for channel in stable rc edge; do cmp "$TARGET_ROOT/etc/pacman.conf.bak" "$TARGET_ROOT/etc/pacman.conf" cmp "$TARGET_ROOT/etc/pacman.d/mirrorlist.bak" "$TARGET_ROOT/etc/pacman.d/mirrorlist" done -pass "China keeps each channel first, appends only CN defaults, and is idempotent" +pass "China puts its channel mirror first, keeps the global one as fallback, and is idempotent" cp "$TARGET_ROOT/etc/pacman.conf" "$scratch/before.conf" cp "$TARGET_ROOT/etc/pacman.d/mirrorlist" "$scratch/before.mirrors" @@ -75,8 +75,8 @@ mkdir -p "$scratch/rendered" "$ROOT/bin/omarchy-apply-pacman" --render rc "$scratch/rendered" "$TARGET_ROOT" rg -qxF 'Server = https://pkgs.omarchy.org/rc/$arch' "$scratch/rendered/pacman.conf" rg -qxF '[archlinuxcn]' "$scratch/rendered/pacman.conf" -[[ $(<"$scratch/rendered/mirrorlist") == $'Server = https://rc-mirror.omarchy.org/$repo/os/$arch\nServer = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch' ]] || - fail "render keeps the channel mirror first" +[[ $(<"$scratch/rendered/mirrorlist") == $'Server = https://rc-mirror.omarchy.cn/$repo/os/$arch\nServer = https://rc-mirror.omarchy.org/$repo/os/$arch' ]] || + fail "render puts the regional channel mirror first" cmp "$scratch/before.conf" "$TARGET_ROOT/etc/pacman.conf" pass "render builds the regional channel files without touching the target" diff --git a/test/shell.d/region-refresh-boundary-test.sh b/test/shell.d/region-refresh-boundary-test.sh index 6bca2559..916e35e9 100755 --- a/test/shell.d/region-refresh-boundary-test.sh +++ b/test/shell.d/region-refresh-boundary-test.sh @@ -7,7 +7,7 @@ source "$SHELL_TEST_DIR/fixtures/sudo-boundary-test.sh" copy_boundary_file bin/omarchy-refresh-pacman copy_boundary_file bin/omarchy-apply-pacman for file in default/pacman/pacman-rc.conf default/pacman/mirrorlist-rc \ - default/regions/cn/pacman/pacman.conf.append default/regions/cn/pacman/mirrorlist.append; do + default/regions/cn/pacman/pacman.conf.append default/regions/cn/pacman/mirrorlist-rc.prepend; do copy_boundary_file "$file" done @@ -63,7 +63,7 @@ PY printf '\n' cat "$ROOT/default/regions/cn/pacman/pacman.conf.append" } >"$boundary_tmp/expected-pacman.conf" -cat "$ROOT/default/pacman/mirrorlist-rc" "$ROOT/default/regions/cn/pacman/mirrorlist.append" >"$boundary_tmp/expected-mirrorlist" +cat "$ROOT/default/regions/cn/pacman/mirrorlist-rc.prepend" "$ROOT/default/pacman/mirrorlist-rc" >"$boundary_tmp/expected-mirrorlist" cmp -s "$boundary_tmp/expected-pacman.conf" "$SUDO_TEST_CAPTURE/etc/pacman.conf" || fail "root installs the rendered China pacman.conf" "$(diff "$boundary_tmp/expected-pacman.conf" "$SUDO_TEST_CAPTURE/etc/pacman.conf" 2>&1)" cmp -s "$boundary_tmp/expected-mirrorlist" "$SUDO_TEST_CAPTURE/etc/pacman.d/mirrorlist" ||