该技能用于编写或编辑 Nix 的 flake.nix 文件,重点围绕 flake-parts 与 perSystem 组织多架构输出。据资料,所有 flake 均使用 flake-parts 的 perSystem 生成按架构划分的输出;formatter 统一设置为 formatter = pkgs.nixpkgs-fmt。shell 脚本应使用 pkgs.writeShellApplication 而非 writeShellScriptBin,前者启用严格模式并在构建期校验 runtimeInputs,脚本需添加 meta.description。命名约定上,flake.nix 保持精简,把定义委派给各 .nix 文件再导入;perSystem 用于与架构相关的 packages、devShells、checks、formatter;顶层 flake 用于与架构无关的 nixosConfigurations、lib、overlays;每个包或脚本都应有 meta.description。资料还给出语言模板:Haskell 使用 haskell-template,关键输入为 haskell-flake、nixos-unified、fourmolu-nix,flake.nix 完全委派给 nixos-unified 自动装配并自动导入 ./nix/modules/flake/.nix;Rust 使用 rust-nix-template,关键输入为 rust-flake、process-compose-flake,用 builtins.readDir 自动导入 ./nix/modules/.nix;Home Manager、nix-darwin、NixOS 使用 nixos-unified-template,关键输入为 home-manager、nix-darwin、nixos-unified,同样使用 autowiring。开发服务方面,process-compose-flake 在 devShell 中集成 process-compose 运行多进程开发环境;services-flake 构建于其之上,提供 PostgreSQL、Redis 等现成服务模块。测试方面,将测试隔离在 test/flake.nix 以免污染父级,测试 flake 可直接引用父内容,如 configDir = builtins.path { path = ./..; name = "config"; };NixOS 虚拟机测试使用 pkgs.testers.nixosTest。具体安装命令与完整代码示例暂未提供。
nix-flake
部署与运维
更新于 10-15 23:43