From 466c2ca14aa3572972fccbf4cc9efabe74b2012b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Mon, 12 Oct 2026 00:27:23 -0400 Subject: [PATCH] Point package managers at China mirrors on cn installs npm, PyPI and uv, Go, rustup and crates.io, RubyGems and Bundler, and Maven reach their registries slowly or not at all from China. On a cn install, link the profile's environment, cargo and gem drop-ins into place. A regular file the admin wrote is never replaced; the install fails instead. --- AGENTS.md | 5 +++ default/regions/cn/cargo.toml | 5 +++ default/regions/cn/environment.conf | 8 +++++ default/regions/cn/gemrc | 3 ++ default/regions/cn/maven-settings.xml | 9 +++++ docs/regions.md | 6 +++- install/config/all.sh | 1 + install/config/region.sh | 33 +++++++++++++++++++ test/shell.d/region-test.sh | 47 +++++++++++++++++++++++++++ 9 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 default/regions/cn/cargo.toml create mode 100644 default/regions/cn/environment.conf create mode 100644 default/regions/cn/gemrc create mode 100644 default/regions/cn/maven-settings.xml create mode 100644 install/config/region.sh create mode 100644 test/shell.d/region-test.sh diff --git a/AGENTS.md b/AGENTS.md index 6de19cb9..12dea04b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -96,6 +96,11 @@ Exceptions are allowed for migration and package-helper scripts where the helper - Do not add `aliases` to new menu entries. Aliases are reserved for established alternate names users already type, kept for compatibility. +# Region + +- `/etc/omarchy/region` holds the region the installer derived from the timezone (`cn`); no file means Global. The profile lives in `default/regions/cn/`, its contract in `docs/regions.md`. +- `install/config/region.sh` links the `cn` developer mirrors into `/etc` and `/.cargo` and refuses to replace a regular file it did not create. + # Config Structure - `config/` - default configs copied to `~/.config/` diff --git a/default/regions/cn/cargo.toml b/default/regions/cn/cargo.toml new file mode 100644 index 00000000..5b56b114 --- /dev/null +++ b/default/regions/cn/cargo.toml @@ -0,0 +1,5 @@ +[source.crates-io] +replace-with = "aliyun" + +[source.aliyun] +registry = "sparse+https://mirrors.aliyun.com/crates.io-index/" diff --git a/default/regions/cn/environment.conf b/default/regions/cn/environment.conf new file mode 100644 index 00000000..60905de2 --- /dev/null +++ b/default/regions/cn/environment.conf @@ -0,0 +1,8 @@ +NPM_CONFIG_REGISTRY=https://registry.npmmirror.com +PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ +UV_DEFAULT_INDEX=https://mirrors.aliyun.com/pypi/simple/ +GOPROXY=https://mirrors.aliyun.com/goproxy/,direct +RUSTUP_DIST_SERVER=https://mirrors.aliyun.com/rustup +RUSTUP_UPDATE_ROOT=https://mirrors.aliyun.com/rustup/rustup +BUNDLE_MIRROR__ALL=https://mirrors.aliyun.com/rubygems/ +MAVEN_ARGS=--global-settings /usr/share/omarchy/default/regions/cn/maven-settings.xml diff --git a/default/regions/cn/gemrc b/default/regions/cn/gemrc new file mode 100644 index 00000000..145984f2 --- /dev/null +++ b/default/regions/cn/gemrc @@ -0,0 +1,3 @@ +--- +:sources: +- https://mirrors.aliyun.com/rubygems/ diff --git a/default/regions/cn/maven-settings.xml b/default/regions/cn/maven-settings.xml new file mode 100644 index 00000000..5066b6bd --- /dev/null +++ b/default/regions/cn/maven-settings.xml @@ -0,0 +1,9 @@ + + + + aliyun + central + https://maven.aliyun.com/repository/public + + + diff --git a/docs/regions.md b/docs/regions.md index 23858f37..e64d89c0 100644 --- a/docs/regions.md +++ b/docs/regions.md @@ -34,7 +34,11 @@ For China, the builder installs `archlinuxcn-keyring` using the existing Arch tr ## Scope of the China profile -The China profile provides repository defaults only. Language is a separate installer choice, not part of a region: a Chinese speaker outside China keeps global mirrors, and a China install in English still gets the regional ones. +The China profile provides repository defaults and developer mirrors. Language is a separate installer choice, not part of a region: a Chinese speaker outside China keeps global mirrors, and a China install in English still gets the regional ones. + +## Developer mirrors + +The `cn` profile also points the common package managers at mirrors inside China: `environment.conf` (npm, PyPI and uv, Go, rustup, Bundler, and Maven through `MAVEN_ARGS`), `cargo.toml` for crates.io, `gemrc` for RubyGems, and `maven-settings.xml`, which Maven reads in place. During installation `install/config/region.sh` links the first three to `/etc/environment.d/90-omarchy-china.conf`, `/.cargo/config.toml` and `/etc/gemrc` when the marker says `cn`. It refuses to replace a regular file it did not create. The environment reaches sessions started after login. ## Remaining release validation diff --git a/install/config/all.sh b/install/config/all.sh index a221a398..3b5655a9 100644 --- a/install/config/all.sh +++ b/install/config/all.sh @@ -1,3 +1,4 @@ +run_logged "$OMARCHY_INSTALL/config/region.sh" run_logged "$OMARCHY_INSTALL/config/theme-system.sh" run_logged "$OMARCHY_INSTALL/config/browser-policy.sh" run_logged "$OMARCHY_INSTALL/config/increase-lockout-limit.sh" diff --git a/install/config/region.sh b/install/config/region.sh new file mode 100644 index 00000000..a009c123 --- /dev/null +++ b/install/config/region.sh @@ -0,0 +1,33 @@ +cn_links=( + "environment.conf /etc/environment.d/90-omarchy-china.conf" + "cargo.toml /.cargo/config.toml" + "gemrc /etc/gemrc" +) + +# The installer writes the marker from the timezone. +region=global +if [[ -e /etc/omarchy/region ]]; then + region=$(&2 + exit 1 + fi + done + for link in "${cn_links[@]}"; do + read -r source target <<<"$link" + mkdir -p "${target%/*}" + ln -sfn "$OMARCHY_PATH/default/regions/cn/$source" "$target" + done + ;; +*) + echo "Unknown region: $region" >&2 + exit 1 + ;; +esac diff --git a/test/shell.d/region-test.sh b/test/shell.d/region-test.sh new file mode 100644 index 00000000..ef638034 --- /dev/null +++ b/test/shell.d/region-test.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +test_tmp=$(mktemp -d) +trap 'rm -rf "$test_tmp"' EXIT + +region_setup="$test_tmp/region.sh" +root="$test_tmp/root" +sed -e "s|/etc/|$root/etc/|g" -e "s| /\.cargo/| $root/.cargo/|g" "$ROOT/install/config/region.sh" >"$region_setup" +export OMARCHY_PATH="$ROOT" +mkdir -p "$root/etc/omarchy" + +bash -e "$region_setup" +[[ -z $(find "$root" -type l) ]] || fail "no marker links nothing" +pass "no marker installs Global" + +echo cn >"$root/etc/omarchy/region" +bash -e "$region_setup" +for link in "environment.conf etc/environment.d/90-omarchy-china.conf" "cargo.toml .cargo/config.toml" "gemrc etc/gemrc"; do + read -r source target <<<"$link" + [[ $(readlink "$root/$target") == "$ROOT/default/regions/cn/$source" ]] || fail "China links /$target to the shipped $source" +done +bash -e "$region_setup" +pass "the cn marker links the developer mirror drop-ins, again without error" + +rm "$root/etc/gemrc" +echo ":sources: []" >"$root/etc/gemrc" +if output=$(bash -e "$region_setup" 2>&1); then + fail "China refuses to replace an admin's /etc/gemrc" "$output" +fi +[[ $output == "Refusing to replace $root/etc/gemrc, which Omarchy did not create" && $(<"$root/etc/gemrc") == ":sources: []" ]] || + fail "China names the file it refuses to replace and leaves it" "$output" +rm "$root/etc/gemrc" +pass "region setup never replaces mirror config Omarchy did not create" + +echo mars >"$root/etc/omarchy/region" +if output=$(bash -e "$region_setup" 2>&1); then + fail "an unknown region fails" "$output" +fi +[[ $output == "Unknown region: mars" ]] || fail "region setup names the unknown region" "$output" +pass "region setup rejects an unknown region" + +grep -qx 'run_logged "$OMARCHY_INSTALL/config/region.sh"' "$ROOT/install/config/all.sh" || fail "the install runs region setup" +pass "the install runs region setup"