Skip to content

feat(recipe): 支持 omarchyopr 换源 - #388

Merged
ccmywish merged 1 commit into
RubyMetric:devfrom
yayoinoyume:feat/omarchy-recipe-v2
Sep 7, 2026
Merged

ccmywish merged 1 commit into
RubyMetric:devfrom
yayoinoyume:feat/omarchy-recipe-v2

Conversation

@yayoinoyume

Copy link
Copy Markdown
Contributor
  • omarchy dish: 借用 os_arch 源列表,写入 mirrorlist 并保留官方 stable 兜底。
  • omarchyopr dish: 更换 pacman.conf 的 [omarchy] 段源,支持 omarchycn 镜像(自动导入并本地签名其 registry key)。
  • edge 通道用户:换源前警告将切换到 stable。
  • Omarchy 官方:仅发布 x86_64,其他架构报错退出。

问题描述

  1. 背景:Omarchy 是基于 Arch Linux 的发行版(DHH 出品),近一年增长较快,国内用户换源目前只能手动编辑配置文件。其软件源由两部分组成:

    • Arch Linux 官方源:经 /etc/pacman.d/mirrorlist 配置,为 core/extra/multilib 提供标准 archlinux 仓库;
    • Omarchy Package Repository (OPR):Omarchy 官方专属软件包仓库,配置在 /etc/pacman.conf 的 [omarchy] 段(分 stable/edge 通道)。

    本 PR 为 chsrc 新增两个 dish:omarchy(换 Arch 镜像源)与 omarchyopr(换 OPR 仓库源),并已在 x86_64 Omarchy 上完成测试验证。

  2. 关联 对 Omarchy(基于 Arch Linux 的发行版)的支持 #387


方案与实现

新增 src/recipe/os/pacman/Omarchy.c,登记于 menu.c,贡献者信息登记于 chsrc-main.c。

omarchy dish(换 Arch 镜像源)

  • 复用 os_arch 的源列表(chef_use_other_dish_sources()),不单独维护一份镜像清单;
  • 写入逻辑针对 omarchy 特有行为做了处理:
    • 选定镜像写入后,保留官方 stable 镜像 stable-mirror.omarchy.org 作为兜底行;
    • 幂等:先清除 mirrorlist 中已累积的生效 Server 行再写入,避免重复执行时可能产生的重复条目;
    • 根据Omarchy官方的更新脚本,提示用户 omarchy-refresh-pacman 会用默认模板覆盖配置,被还原后需重新执行。
  • 与 chsrc set arch 的关系说明:这部分的源列表是相同的,感谢维护 arch 换源方式的前辈们;
  • Omarchy 官方暂时还只发布了 x86_64 仓库,非 x86_64 架构下报错退出。

omarchyopr dish(换 OPR 仓库源)

  • 上游:https://pkgs.omarchy.org/stable/$arch。
  • 镜像 omarchycn:https://git.zacharyzhang.com/api/packages/ZacharyZhang-NY/arch/omarchy/x86_64,每 6 小时同步上游 stable 通道,db/包由其 registry key 重新签名,具体可以查看 pacman-repo.md ,已作为 @consult 写入代码。
  • 选择镜像时自动导入并本地签名其 registry key(指纹硬编码自镜像方文档,失败即中止)。
  • 幂等:所选 Server 行已存在则跳过;换回官方上游时删除镜像行、保留官方行;清理本地陈旧 omarchy.db(.sig) ,这是因为官方源无 db.sig,镜像有,残留旧 sig 会导致 -Syy 验签失败。
  • edge 通道检测:开发测试中发现 edge 用户(Server = https://pkgs.omarchy.org/edge/$arch)执行换源会被静默切换到 stable(上游与可用镜像均基于 stable),已在换源前检测并警告(参照 Debian recipe 中 CDROM 源检测的处理范式),警告后继续执行。

实测验证(x86_64 Omarchy)

项目 结果
ls / get / measure(两个 dish) 通过,omarchy 正确显示借用 arch 源列表并标注
set omarchy <镜像> 真实执行 mirrorlist 写入正确,-Syy 正常
set omarchyopr omarchycn 真实执行 key 导入/lsign/验签通过,pacman -Si omarchy 从镜像正常获取
幂等重跑 不产生重复 Server 行
换回上游 镜像行删除,官方行保留,-Syy 正常
dry-run 全部路径 生成的命令均正确
测试后还原 配置文件 md5 一致,key 已从 keyring 清除

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

Hi @yayoinoyume

❤️ 感谢你的贡献!我们将在最少半小时,最多5天内阅读此 PR 并回复你

@yayoinoyume

Copy link
Copy Markdown
Contributor Author

无论如何,感谢您百忙之中抽空查看我的PR,非常感谢您!

@yayoinoyume

Copy link
Copy Markdown
Contributor Author

已按意见完成修改,并修复一处幂等缺陷

感谢 @ccmywish 的耐心评审!我已根据 issue #387 的意见重写了本 PR。

1. 移除 omarchy dish(它是 arch dish 的 alias)

按建议只保留 omarchyopr。现在 chsrc ls 中只有 omarchyopr,chsrc set omarchy 会走标准的"暂不支持的换源菜品"提示。已在 chef_set_note() 中提示用户先 chsrc set omarchyopr 再 chsrc set arch,并在备注中说明 Omarchy 基于 Arch、除专属软件包外其余换源与 Arch 一致。

2. 移除 omarchycn 自建镜像,omarchyopr 仅保留官方上游源

完全认同 chsrc 以教育网、大型商业公司作为 trust 基线的立场。omarchyopr 现在只提供一个官方源:
https://pkgs.omarchy.org/stable/$arch(上游默认)。用户仍可通过 chsrc set omarchyopr <URL> 自定义源。

3. 新增 chsrc reset omarchyopr 恢复官方源

考虑到 dish 只有一个源时,chsrc 会因"至少需要 2 个源"而阻止 chsrc set omarchyopr upstream(见 dish_select_source_by_mirror_code 与 dish_select_fastest_source 的 size==1 分支)。目前我与omarchy中国版作者联系询问得知,后续会在阿里云上提供omarchy官方镜像,因此,暂时只做 chsrc 的 reset 机制实现"恢复官方源":实现了 _resetsrc,chsrc reset omarchyopr 即可恢复官方 stable 通道。

4. 一处幂等判断缺陷的修复

os_omarchyopr_setsrc() 原用 grep -qF 判断所选源是否已存在,但 -qF 是子串匹配而非整行匹配:当用户自定义 URL 恰为现有 Server 行的前缀时(例如现有行 Server = https://pkgs.omarchy.org/stable/$arch,用户输入 .../stable/ 漏写 $arch),会误判"该行已存在"而跳过写入,但 chsrc 仍提示"换源完成",导致用户以为成功实则未改。具体举例:

假设 pacman.conf 里现在是这样一行:

Server = https://pkgs.omarchy.org/stable/$arch

在omarchy机器上验证了以下三种情况

情况 1:用户设置完全相同的源(幂等,正常跳过) 用户 chsrc set omarchyopr https://pkgs.omarchy.org/stable/$arch(就是当前的源)。

  • 改前:grep -qF → 找到该行 → 跳过
  • 改后:grep -qxF → 整行完全一样 → 找到 → 跳过
  • 两种情况都正确,行为没变。这是幂等的本意:设同一个源时不白干。

情况 2:用户设置一个"更短的、碰巧是当前行的前缀"的 URL(这是缺陷所在) 用户 chsrc set omarchyopr https://pkgs.omarchy.org/stable/(少了 $arch)。

  • 改前:grep -qF 发现当前行包含 Server = https://pkgs.omarchy.org/stable/ 这段 → 误以为"已经设好了" → 跳过,什么都不改 → 但 chsrc 还打印"换源完成,成功"。
    • 结果:用户以为换源成功了,实际上 pacman.conf 一个字都没动。 这是误导,是 bug。
  • 改后:grep -qxF 发现当前行是 ...stable/$arch,不等于 ...stable/ → 判定"没设过" → 真正执行 sed 替换 → 真的写进去。
    • 结果:换源真的生效。

情况 3:用户设置一个完全不同的 URL(正常换源) 比如 chsrc set omarchyopr https://mirror.example.com/omarchy。

  • 改前:grep -qF 在当前行里找不到这段 → 执行 sed 替换
  • 改后:grep -qxF 整行不匹配 → 执行 sed 替换
  • 两种情况都正确,行为没变。

这项改动带来的风险

需要留意一个边界:因为加了 -x(整行匹配),现在必须是整行一模一样才跳过。如果 pacman.conf 里的 Server 行带着尾随空格、tab、或者行尾注释(比如 Server = https://.../$arch # 某注释),那么:

  • 改前:grep -qF 子串匹配,仍能匹配到 → 会跳过
  • 改后:grep -qxF 整行匹配,因为行尾多了空格/注释 → 匹配不上 → 会执行 sed 替换

也就是说,如果用户在 Server 行尾手动加了空格或注释,这个 dish 会把那一整行重写成干净的 Server = <源>。

  • 对 Omarchy 官方默认配置:[omarchy] 段的 Server 行是干净的单行(Server = https://pkgs.omarchy.org/stable/$arch,无尾随内容),所以实际不会触发这个差异。
  • 只有用户手动在 Server 行尾加了空格/注释这种情况才会有差异——此时执行结果是把行重写成干净的 Server = <源>。

暂时没有想到其他边界情况。

5. 关于幂等与缓存清理

  • 幂等:sed 只匹配 ^Server = https://pkgs.omarchy.org/.* 的行,实测在同时存在 [archlinuxcn] 段的 pacman.conf 上执行,archlinuxcn 的 Server 行不受影响,不会误删。
  • 缓存清理:官方源不提供 omarchy.db.sig(HTTP 404),但本地一旦残留无效的 .db.sig(例如之前用过带 sig 的自建镜像或残留下载),pacman -Syy 会验签失败(实测复现:GPGME error: No data)。因此保留 rm -f omarchy.db(.sig) 作为兜底。

6. 测试验证结果

A 组:omarchy dish(确认已移除)

命令 结果
chsrc set omarchy tuna chsrc: 暂不支持的换源菜品。使用 chsrc list dishes 查看所有支持的菜品(EXIT=2)
chsrc get omarchy 同上(EXIT=2)
chsrc ls omarchy 同上(EXIT=2)

→ omarchy dish 已正确移除,走标准 not_found 提示,与任意未注册菜品行为一致。

B 组:omarchyopr 只读指令

命令 结果
chsrc ls 菜品列表含 omarchyopr;全文检索无 omarchy(EXIT=0)
chsrc ls omarchyopr 展示 upstream 官方源 + 完整备注 + Get/Reset/UserDefine 功能(EXIT=0)
chsrc get omarchyopr 输出 [omarchy] 段 Server = https://pkgs.omarchy.org/stable/$arch(EXIT=0)
chsrc list dishes 已注册 omarchyopr,无 omarchy(EXIT=0)

C 组:写操作

命令 结果
chsrc set omarchyopr <自定义URL> 用户自定义 URL 可正常换源(EXIT=0)
chsrc set omarchyopr https://pkgs.omarchy.org/edge/$arch sed 正常写入 edge,pacman -Syy 通过
chsrc set omarchyopr https://pkgs.omarchy.org/stable/(前缀URL) 正确执行 sed 写入
chsrc set omarchyopr <与当前相同URL> 幂等跳过,pacman.conf 保持不变
chsrc reset omarchyopr 恢复官方 stable;edge→stable 警告正常触发;提示"已重置为上游默认源"
重复 chsrc reset omarchyopr 幂等正常,状态不变

附加核验

项 结果
pacman -Syy 成功同步 core / extra / multilib / omarchy 四个仓库
OPR 仓库包数 217 个包可查
架构检查 仅 x86_64,非 x86_64 报错退出
edge 通道警告 检测到 edge 时换源前弹出警告

@yayoinoyume yayoinoyume changed the title feat(recipe): 支持 omarchy 与 omarchyopr 换源 feat(recipe): 支持 omarchyopr 换源 Sep 6, 2026
@yayoinoyume
yayoinoyume force-pushed the feat/omarchy-recipe-v2 branch from d45cefb to 5f0a159 Compare September 6, 2026 08:45
Comment thread src/recipe/os/pacman/Omarchy.c Outdated

/* 上游默认源基于 stable 通道,edge 通道用户换源后将切换到 stable */
bool is_edge = xy_run_get_status ("grep -q '^Server = https://pkgs.omarchy.org/edge/' " OS_Pacman_Omarchy_Conf) == 0;
if (is_edge && !xy_streql (source.mirror->code, "user"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里可直接用 source_is_userdefine()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢你的仔细 review!

已修改 os_omarchy_setsrc():

// 原:if (is_edge && !xy_streql (source.mirror->code, "user"))
// 改:if (is_edge && !source_is_userdefine (&source))

测试验证结果:用户自定义 URL 场景下 source_is_userdefine 能正确识别,不会误触发 edge→stable 警告;reset(非自定义)场景下 edge 警告正常。

char *exists_cmd = xy_strcat (3, "grep -qxF 'Server = ", source.url, "' " OS_Pacman_Omarchy_Conf);
if (xy_run_get_status (exists_cmd) == 0)
{
chsrc_debug ("recipe", "所选 Server 行已存在,跳过 pacman.conf 修改");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以用 chsrc_note2() 直接提示用户

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在 os_omarchy_setsrc() 末尾(chsrc_conclude 之后)增加 chsrc_note2():

本菜品仅更换 OPR 源;Arch Linux 主仓库请另行 chsrc set arch。

测试验证结果:chsrc set omarchy <自定义URL> 与 chsrc reset omarchy 执行后会输出该提示。chsrc set omarchy (无参数) 执行时不会输出,因为目前只有单源,在 framework 的 chsrc_yield_source() 阶段就提前报错退出了。

Comment thread src/recipe/menu.c

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

menu.c 的文件头也加上你的贡献信息

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在 src/recipe/menu.c 文件头的 Contributors 中追加 @yayoinoyume。

Comment thread src/recipe/os/pacman/Omarchy.c Outdated
* `chsrc set arch` 来更换;本 dish 只负责 [omarchy] 段 (OPR)。
* ------------------------------------------------------------*/

def_dish(os_omarchyopr, "omarchyopr");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我建议直接叫 omarchy 吧,不用把后面的 opr 带上。你的看法呢?

@yayoinoyume yayoinoyume Sep 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

考虑到本 dish 会在提示中引导用户另外执行 chsrc set arch 更换 Arch 主源,改名 omarchy 确实更合理,感谢您的建议。

测试验证结果:chsrc ls 显示 omarchy,旧名 omarchyopr 已走标准"暂不支持"提示。

如果还有不到位之处,我会继续改进。

@yayoinoyume
yayoinoyume force-pushed the feat/omarchy-recipe-v2 branch from 5f0a159 to 1a04e83 Compare September 6, 2026 10:09
- omarchy dish: 更换 pacman.conf 的 [omarchy] 段 (OPR) 源,仅提供官方上游 stable 源
- 提供 chsrc reset omarchy 恢复官方 OPR 源
- edge 通道用户换源前警告将切换到 stable
- 用 source_is_userdefine() 判断用户自定义源
- setsrc 末尾用 chsrc_note2() 提示可另换 Arch 主源
- Omarchy 官方仅发布 x86_64,其他架构报错退出
- Arch 主仓库源与 arch 完全一致,提示用户额外使用 chsrc set arch
@yayoinoyume
yayoinoyume force-pushed the feat/omarchy-recipe-v2 branch from 1a04e83 to 89ff5b2 Compare September 6, 2026 10:15
@yayoinoyume
yayoinoyume requested a review from ccmywish September 6, 2026 10:37
@ccmywish ccmywish added os_dish os_dish Linux Linux相关 labels Sep 7, 2026
@ccmywish ccmywish added this to the v0.2.8 milestone Sep 7, 2026
@ccmywish
ccmywish merged commit f2f86a4 into RubyMetric:dev Sep 7, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Linux Linux相关 os_dish os_dish

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants