refactor: 引入 flake-fhs 简化 flake 实现 - #2
Merged
Conversation
luochen1990
force-pushed
the
refactor-flake-fhs-20260811-2236
branch
from
August 11, 2026 15:47
3a0bbf0 to
b54c71f
Compare
luochen1990
force-pushed
the
refactor-flake-fhs-20260811-2236
branch
4 times, most recently
from
August 12, 2026 00:13
f707510 to
d3ce8b1
Compare
flake.nix 从 180 行精简到 ~25 行, 所有 outputs 改由 flake-fhs 按目录约定自动生成. module/ → modules/mirrors/ (default.nix + config.cfg.nix); checks 聚合为 1 个 drv 跑全部 50 个断言; formatter 切到 treefmt.
luochen1990
force-pushed
the
refactor-flake-fhs-20260811-2236
branch
from
August 12, 2026 00:16
d3ce8b1 to
c43c504
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
动机
引入 flake-fhs (Flake Filesystem Hierarchy Standard) 消除手写 flake outputs 样板代码, flake.nix 从 180 行精简到 ~25 行 (核心逻辑 ~10 行).
改动
module/ → modules/mirrors/ (flake-fhs 目录模块)
mirrors 模块改造为 flake-fhs 原生目录模块:
default.nix: options 定义 + 无条件 config (providerPresets 注入 / entries 派生 / 拼写检查).mirrors.enable在此声明, flake-fhs 的 injectEnable 检测到已存在便不再重复注入config.cfg.nix: 受mirrors.enable控制的直写下发 (nix.settings / environment.* / docker), flake-fhs 自动用mkIf config.mirrors.enable包裹checks/
2 个扁平数据文件 → 7 个场景目录 (
checks/<name>/{package,assertions}.nix), 走 callPackage +scope.nix注入共享逻辑 (mkEvalCheck / evalMirrors / builtinPresets / assertHelpers).3 个边缘场景的硬编码 URL 派生化 (从 builtinPresets 读取 expected, 修改 providers.nix 时自动跟随).
其他
shells/default.nix: 提取原 flake.nix 的 devTools (SSOT)treefmt.toml配 nixpkgs-fmt + ruff, 底层不变)nixosModules.default别名保留 (指向nixosModules.mirrors, 兼容不同引用习惯)验证
just check全绿 (deadnix + statix + ruff + nix flake check, 7 个 check 场景全部通过).注意
statix W03 (
manual_inherit) 规则被禁用: statix 对checks/scope.nix嵌套 let 作用域有结构性误报 (会把字面量赋值误判为应改用 inherit), 详见statix.toml注释.