Skip to content

refactor: 引入 flake-fhs 简化 flake 实现 - #2

Merged
luochen1990 merged 1 commit into
masterfrom
refactor-flake-fhs-20260811-2236
Aug 12, 2026
Merged

refactor: 引入 flake-fhs 简化 flake 实现#2
luochen1990 merged 1 commit into
masterfrom
refactor-flake-fhs-20260811-2236

Conversation

@luochen1990

@luochen1990 luochen1990 commented Aug 11, 2026

Copy link
Copy Markdown
Owner

动机

引入 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)
  • formatter: 裸 nixpkgs-fmt → treefmt (treefmt.toml 配 nixpkgs-fmt + ruff, 底层不变)
  • nixosModules.default 别名保留 (指向 nixosModules.mirrors, 兼容不同引用习惯)
  • 移除 flake-utils input (被 flake-fhs 替代)

验证

just check 全绿 (deadnix + statix + ruff + nix flake check, 7 个 check 场景全部通过).

注意

statix W03 (manual_inherit) 规则被禁用: statix 对 checks/scope.nix 嵌套 let 作用域有结构性误报 (会把字面量赋值误判为应改用 inherit), 详见 statix.toml 注释.

@luochen1990
luochen1990 force-pushed the refactor-flake-fhs-20260811-2236 branch from 3a0bbf0 to b54c71f Compare August 11, 2026 15:47
@luochen1990 luochen1990 changed the title WIP: refactor: 引入 flake-fhs 简化 flake 实现 refactor: 引入 flake-fhs 简化 flake 实现 Aug 11, 2026
@luochen1990
luochen1990 force-pushed the refactor-flake-fhs-20260811-2236 branch 4 times, most recently from f707510 to d3ce8b1 Compare August 12, 2026 00:13
flake.nix 从 180 行精简到 ~25 行, 所有 outputs 改由 flake-fhs 按目录约定自动生成.
module/ → modules/mirrors/ (default.nix + config.cfg.nix); checks 聚合为 1 个 drv 跑全部 50 个断言; formatter 切到 treefmt.
@luochen1990
luochen1990 force-pushed the refactor-flake-fhs-20260811-2236 branch from d3ce8b1 to c43c504 Compare August 12, 2026 00:16
@luochen1990
luochen1990 merged commit c191982 into master Aug 12, 2026
2 checks passed
@luochen1990
luochen1990 deleted the refactor-flake-fhs-20260811-2236 branch August 13, 2026 12:45
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