nix代理
nix-agent 是用于可信NixOS自动化的本地MCP服务器。
它协同工作 mcp-nixos:
nix-agent处理本地检查、修补、验证和切换mcp-nixos处理包和选项发现
注意:这是一项实验性工作,正在进行中。我们非常欢迎您的反馈和贡献。
你得到了什么
- 可运行的stdio MCP服务器
- Nix薄片包装和应用程序
- 一个nixos模块和
nixosModules.default - 同伴代理技能
skills/nix-agent/ - MCP主机配置示例
examples/
一次性代理安装
将此粘贴到编码代理(Claude Code、opencode等),它将为您完成安装:
Read https://raw.githubusercontent.com/JEFF7712/nix-agent/main/docs/agent-install.md and follow every step to install nix-agent on this NixOS system, install the companion skill, and register nix-agent in my MCP settings for this machine.快速安装
将此flake输入和模块添加到您的NixOS配置中:
{
inputs.nix-agent.url = "github:JEFF7712/nix-agent";
outputs = { nixpkgs, nix-agent, ... }: {
nixosConfigurations.my-host = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
nix-agent.nixosModules.default
({ ... }: {
programs.nix-agent.enable = true;
})
];
};
};
}然后重建:
sudo nixos-rebuild switch --flake .#my-host这将安装 nix-agent 二元的。
MCP主机配置
将您的MCP主机指向:
{
"mcpServers": {
"nix-agent": {
"command": "nix-agent",
"args": []
}
}
}看 examples/claude-code-mcp.json 和 examples/opencode-mcp.json.
同伴技能
安装或复制 skills/nix-agent/ 进入你经纪人的技能目录。
快速安装:
./install-skill.sh opencodeMCP公开工具。该技能教授正确的工作流程。
工具表面
nix-agent 公开了两个工具:
inspect_state(path)--读取本地文件。apply_patch_set(patch_set, flake_uri=None, mode="nixos")--写每一个Patch(path, content),格式化任何.nix文件,以及(当flake_uri给出)验证然后切换。
- mode="nixos" (默认)运行 sudo nixos-rebuild dry-activate 然后 switch. - mode="home-manager" 跑 home-manager build 然后 home-manager switch (没有sudo)。 - 退货 changed_files, rollback_generation, current_generation、命令输出和a status.
mcp-nixos 处理包和选项发现。
基本工作流程
- 如果您需要套餐或选项信息,请查询
mcp-nixos第一。 - 建立一个
PatchSet的Patch(path, content)条目。 - 呼叫
apply_patch_set(patch_set, flake_uri="/etc/nixos#hostname")对于NixOS,或apply_patch_set(patch_set, flake_uri="/path/to/flake#user@host", mode="home-manager")对于Home Manager来说。 - 如果出现任何问题,请通过以下方式恢复
sudo nixos-rebuild switch --rollback(NixOS)或通过激活上一代Home Manager。回应包括rollback_generation以供参考。
您也可以致电 apply_patch_set(PatchSet(patches=[]), flake_uri=...) 没有补丁来验证和切换当前的薄片状态——在手动编辑后或在不写入任何文件的情况下重新运行重建时很有用。
在验证或切换失败时,响应包括 first_error 第一个字段 error: 从Nix的输出中提取的行,以及完整的日志。
设计说明
nix-agent故意做 不 在MCP批准门装运。路径限制属于主机的权限系统(例如Claude Code的允许/拒绝列表),回滚安全属于Nix一代。在MCP内部重新实施这两种方案只会增加摩擦,而不会提高安全性。- 不要通过补丁编写秘密有效载荷——通过引用秘密
sops-nix或agenix. - v1假设本地环境是可信的。
- 完全非交互式应用程序需要特权自动化;看见
docs/privileged-automation.md.
更多细节
- 发行说明:
docs/releases/v0.1.0.md - 技能文档:
skills/nix-agent/SKILL.md - 示例:
examples/
