Skip to content

WIP: 修复总开关失效 / 自定义 provider 丢失 / License 不一致 + 测试与 CI 改进 - #1

Merged
luochen1990 merged 2 commits into
masterfrom
fix-mirrors-bugs-20260721-1814
Jul 21, 2026
Merged

WIP: 修复总开关失效 / 自定义 provider 丢失 / License 不一致 + 测试与 CI 改进#1
luochen1990 merged 2 commits into
masterfrom
fix-mirrors-bugs-20260721-1814

Conversation

@luochen1990

Copy link
Copy Markdown
Owner

背景

继上次审计发现的 3 个 P0 bug + 5 项 P1/P2 改进, 本次 PR 全部修复.

修复内容

P0 (阻塞级)

  • 总开关失效: `mirrors.enable = false` 不再注入任何 substituters / 环境变量 / 配置文件. 此前所有 `mkIf` 只检查逐软件 `enable`, 总开关形同虚设.
  • 自定义 provider 丢失内置预设: 用户通过 `mirrors.providerPresets.my-cache.*` 添加自定义 provider 时, 不再导致内置 10 个 provider (tuna/ustc/...) 全部丢失. 根因是 `option.default` 在用户整段定义时会被替换, 改为 config 注入后走标准 module 合并.
  • `providerPresets.X.Y = null` 类型冲突 (review 发现): option 类型从 `nullOr attrs` 改为 `attrs`, "provider 不提供某软件" 用 attrset 中省略字段表达, 避免用户 `null` 与内置 `{url=...}` 在 module system 合并时报 `defined both null and not null`.
  • License 标注不一致: README/flake.nix/CHANGELOG/AGENTS 中的 TBD 标注统一为 MIT, 补 LICENSE 文件.

P1 (工程改进)

  • 断言改为派生式: `checks/mirrors-assertions.nix` 的 expected 从硬编码 URL 改为从 `module/providers.nix` 派生, 避免 URL 改动时双重维护. 同时保留 3 条非派生守护断言检查关键字段存在性 (兼顾 DRY 与回归检测).
  • README 加 DaoCloud docker 限流提醒 (1 MiB/s, 20 req/min).

P2 (体验优化)

  • 5 个边缘场景断言: `checks/mirrors-assertions-edge.nix`, 守护历史 bug 不回归:
    • `enable-false-leak`: 总开关关闭时零副作用 (全量遍历所有可能被注入的键)
    • `custom-provider-merge`: 用户加自定义 provider 时内置 provider 不丢失
    • `builtin-override`: 覆盖内置 provider 字段时其他字段保持不变
    • `per-software-disable`: 逐软件 `enable=false` 只关停该软件
    • `substituter-order`: mkBefore 让镜像 substituter 排在用户值之前
  • provider 拼写检查: 拼错的 provider 名通过 NixOS 标准 assertions 给出明确告警, 不再静默失败.
  • CI workflow: `.github/workflows/ci.yml` 在 PR / push 时跑 `just check`.
  • 镜像 URL 定期巡检: `.github/workflows/verify-mirrors.yml` 每周一 09:00 UTC+8 跑 `just verify-mirrors-quiet`, 失效时自动开 issue 通知维护者.

DoD

  • `just check` 全绿 (lint + 6 个 eval 场景断言全通过)
  • `just verify-mirrors` 全绿 (24 个 URL 可达 + mirrorz 数据一致性)
  • Code Reviewer / Code Simplifier 双轮迭代, 关键反馈已落实
  • 2 个 commit 边界清晰 (P0 修复 + P1/P2 测试与 CI)

验证命令

```bash
nix develop -c just check
nix develop -c just verify-mirrors
```

注意事项

  • 本次 PR rebase 自 master 的 `c89b170` (python 巡检脚本), 与之兼容.
  • Breaking change: `mirrors.providerPresets.X.Y = null` 不再合法 (类型层面禁止), 改为省略字段. 文档已同步.

- mirrors.enable=false 不再注入任何 substituters / 环境变量 / 配置文件
  (此前每个 mkIf 只检查逐软件 enable, 总开关形同虚设)
- 内置 providerPresets 从 option.default 移到 config 注入,
  避免用户加自定义 provider 时内置 10 个 provider (tuna/ustc/...) 全部丢失
- option 类型 attrsOf(attrsOf(nullOr attrs)) 改为 attrsOf(attrsOf attrs),
  避免用户 null 与内置 {url=...} 在 module system 合并时报
  'defined both null and not null'
- option 类型层面禁止 null, 改用 attrset 中省略字段表达'不提供'
  (attrByPath 自动当作 null, 语义等价)
- 补 LICENSE (MIT), 同步 README/flake.nix/CHANGELOG/AGENTS 中的 TBD 标注
断言改造:
- checks/mirrors-assertions.nix 改为派生式: expected 从 providers.nix 派生,
  避免 URL 改动时双重维护; 同时保留 3 条非派生守护断言检查关键字段存在性
- 新增 checks/mirrors-assertions-edge.nix (5 个场景, 守护历史 bug 不回归):
  * enable-false-leak: 总开关关闭时零副作用 (全量遍历所有可能被注入的键)
  * custom-provider-merge: 用户加自定义 provider 时内置 provider 不丢失
  * builtin-override: 覆盖内置 provider 字段时其他字段保持不变
  * per-software-disable: 逐软件 enable=false 只关停该软件
  * substituter-order: mkBefore 让镜像 substituter 排在用户值之前
- flake.nix 引入 mkEvalCheck 工厂, 默认+边缘场景共用 'eval + 比对断言' 基础设施
- module/config.nix 加 NixOS assertions: provider 名拼写错误给出明确告警,
  不再静默失败

CI workflow:
- .github/workflows/ci.yml: cachix/install-nix-action@v31 + nix develop -c just check
  (进 devShell 后 lint 工具齐全, 与本地开发环境一致)
- .github/workflows/verify-mirrors.yml: 每周一 09:00 (UTC+8) 跑 just verify-mirrors-quiet,
  失效自动开 issue (mirror-verify-failed label), 成功自动关闭旧 issue

文档与体验:
- README 加 DaoCloud docker 限流提醒 (1 MiB/s, 20 req/min)
- CHANGELOG 归档 0.2.0 段
@luochen1990
luochen1990 force-pushed the fix-mirrors-bugs-20260721-1814 branch from 3d33e89 to 36c614a Compare July 21, 2026 11:57
@luochen1990
luochen1990 marked this pull request as ready for review July 21, 2026 12:16
@luochen1990
luochen1990 merged commit 5011c07 into master Jul 21, 2026
2 checks passed
@luochen1990
luochen1990 deleted the fix-mirrors-bugs-20260721-1814 branch July 22, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant