nix mcp设置
Nix flake用于带MCP服务器和插件的Claude Code。
这有什么作用
- 通过安装Claude Code CLI 克劳德代码nix
- 安装依赖项:bun、uv、nodejs、jq
- 配置MCP服务器(Azure DevOps)-合并到现有
~/.claude.json - 安装插件(claude-mem)
先决条件
- 尼克斯 启用薄片
- 码头工人 CLI可用(
docker命令)
- Docker桌面、Rancher桌面、Colima或带有Docker CLI的Podman
快速开始
选项1:简单(推荐)
使用包含Claude Code包的预配置模块:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
home-manager.url = "github:nix-community/home-manager";
nix-mcp-setup.url = "github:helgeu/nix-mcp-setup";
};
outputs = { nixpkgs, home-manager, nix-mcp-setup, ... }: {
homeConfigurations."youruser" = home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.aarch64-darwin;
modules = [
# Use system-specific module with package included
nix-mcp-setup.homeManagerModulesWithPackage.aarch64-darwin.default
{
programs.claude-code = {
enable = true;
mcp.azure-devops.work = {
enable = true;
organizationUrl = "https://dev.azure.com/myorg";
};
# plugins.claude-mem.enable = true; # Optional
};
}
];
};
};
}选项2:使用extraSpecialArgs
为了更好地控制,请将薄片通过 extraSpecialArgs:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
home-manager.url = "github:nix-community/home-manager";
nix-mcp-setup.url = "github:helgeu/nix-mcp-setup";
};
outputs = { nixpkgs, home-manager, nix-mcp-setup, ... }: {
homeConfigurations."youruser" = home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.aarch64-darwin;
extraSpecialArgs = {
inherit nix-mcp-setup;
};
modules = [
nix-mcp-setup.homeManagerModules.default
{
programs.claude-code = {
enable = true;
mcp.azure-devops.work = {
enable = true;
organizationUrl = "https://dev.azure.com/myorg";
};
# plugins.claude-mem.enable = true; # Optional
};
}
];
};
};
}然后运行:
home-manager switch选项3:独立安装
仅安装Claude代码(无MCP配置):
nix profile install github:helgeu/nix-mcp-setup模块选项
programs.claude-code
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
enable bool的。 false | 启用克劳德代码 | ||
package | 包 | 克劳德代码 | 克劳德代码包 |
containerCommand | 字符串 | "docker" | 容器运行时(docker, podman等等) |
validateContainerRuntime bool的。 true | 如果未找到容器运行时,则发出警告 |
programs.claude-code.mcp.azure-devops.
可以配置多个Azure DevOps实例。每 ` 成为MCP服务器名称的一部分(例如。, work → ado-mcp-work`).
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
enable bool的。 false | 启用此ADO MCP服务器实例 | ||
organizationUrl | string | 必填 | ADO组织URL |
image | string | 固定摘要 | Docker镜像(为了可重复性而固定) |
patEnvVar | 字符串 | "AZURE_DEVOPS_PAT_" | PAT环境变量(根据实例名称自动生成) |
prePull bool的。 true | 激活期间预拉图像 |
具有多个实例的示例:
programs.claude-code.mcp.azure-devops = {
work = {
enable = true;
organizationUrl = "https://dev.azure.com/work-org";
# patEnvVar defaults to "AZURE_DEVOPS_PAT_WORK"
};
client-acme = {
enable = true;
organizationUrl = "https://dev.azure.com/acme-corp";
patEnvVar = "ADO_PAT_ACME"; # Override default
};
};programs.claude-code.mcp.github
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
installGhCli bool的。 true | 安装GitHub CLI(gh)进行PAT管理 |
programs.claude-code.mcp.github.instances.
可以配置多个GitHub实例(GitHub+GitHub Enterprise)。每 ` 成为MCP服务器名称的一部分(例如。, personal → github-mcp-personal`).
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
enable bool的。 false | 启用此GitHub MCP服务器实例 | ||
image | string | 固定摘要 | Docker镜像(为了可重复性而固定) |
patEnvVar | 字符串 | "GITHUB_PAT_" | PAT环境变量(根据实例名称自动生成) |
host | 字符串 | null | GitHub企业主机URL(GitHub为空) |
toolsets | 列表 | [] | 限制工具:repos、issues、pull_requests、actions等。 |
prePull bool的。 true | 激活期间预拉图像 |
具有多个实例的示例:
programs.claude-code.mcp.github.instances = {
personal = {
enable = true;
# patEnvVar defaults to "GITHUB_PAT_PERSONAL"
};
work-ghe = {
enable = true;
host = "https://github.mycompany.com";
patEnvVar = "GH_PAT_WORK";
toolsets = [ "repos" "issues" "pull_requests" ];
};
};programs.claude-code.mcp.context7
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
enable bool的。 false | 启用Context7 MCP服务器 | ||
image | string | 固定摘要 | Docker镜像(为了可重复性而固定) |
serverName | 字符串 | "context7-mcp" | 配置中的MCP服务器名称 |
prePull bool的。 true | 激活期间预拉图像 |
programs.claude-code.plugins.claude-mem
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
enable bool的。 false | 启用claude mem插件 | ||
autoInstall bool的。 true | 激活时自动安装 |
配置
Azure DevOps PAT
将PAT设置为环境变量(每个实例一个):
# For instance "work" → env var AZURE_DEVOPS_PAT_WORK
export AZURE_DEVOPS_PAT_WORK="your-work-pat"
export AZURE_DEVOPS_PAT_CLIENT_ACME="your-acme-pat"使用辅助脚本设置PAT:
# Interactive mode
./scripts/create-ado-pat.sh
# Or specify instance directly
./scripts/create-ado-pat.sh --instance work --org "https://dev.azure.com/work-org"GitHub PAT
将PAT设置为环境变量(每个实例一个):
# For instance "personal" → env var GITHUB_PAT_PERSONAL
export GITHUB_PAT_PERSONAL="ghp_xxxxxxxxxxxx"
export GH_PAT_WORK="ghp_yyyyyyyyyyyy" # Custom env var for work-ghe instance使用辅助脚本设置PAT:
# Interactive mode
./scripts/create-github-pat.sh
# Set up PAT for specific instance
./scripts/create-github-pat.sh --instance personal
# Set up PAT for GitHub Enterprise instance
./scripts/create-github-pat.sh --instance work-ghe --host "https://github.mycompany.com"或者在以下位置手动创建:https://github.com/settings/tokens
现有的~/.claude.json
模块 合并 MCP服务器到您现有的 ~/.claude.json。它不会覆盖您的其他设置。
手动插件安装
如果 autoInstall = false,手动安装:
./scripts/setup-claude-plugins.sh claude-mem更新Docker镜像
Docker镜像由摘要固定,以实现可重复性。要更新到最新版本,请执行以下操作:
# Pull latest and get new digest
docker pull ghcr.io/metorial/mcp-container--vortiago--mcp-azure-devops--mcp-azure-devops:latest
docker inspect ghcr.io/metorial/mcp-container--vortiago--mcp-azure-devops--mcp-azure-devops:latest \
--format='{{index .RepoDigests 0}}'
# Use the output in your config:
mcp.azure-devops.image = "ghcr.io/...@sha256:abc123...";MCP服务器
| 服务器 | Docker镜像 | 状态 |
|---|---|---|
| Azure DevOps | ghcr.io/metorial/mcp-container--vortiago--mcp-azure-devops--mcp-azure-devops | ✅ 已执行 |
| GitHub | ghcr.io/github/github-mcp-server | ✅ 已执行 |
| 背景7 | mcp/context7 | ✅ 已执行 |
项目结构
nix-mcp-setup/
├── flake.nix # Main entry point
├── modules/
│ ├── home-manager.nix # Home Manager module
│ ├── mcp-servers/
│ │ ├── azure-devops-mcp.nix # ADO MCP config
│ │ ├── github-mcp.nix # GitHub MCP config
│ │ └── context7-mcp.nix # Context7 MCP config
│ └── plugins/
│ └── claude-mem.nix # claude-mem plugin
├── scripts/
│ ├── create-ado-pat.sh # Generate ADO PAT (multi-instance)
│ ├── create-ado-pat.ps1 # Generate ADO PAT (PowerShell, legacy)
│ ├── create-github-pat.sh # Generate GitHub PAT
│ └── setup-claude-plugins.sh # Manual plugin install
├── examples/
│ └── claude.json # Example config
└── docs/
├── ROADMAP.md
├── PLAN-NIX-MODULE.md
└── PLUGIN-DEPENDENCIES.md测试
创建一个测试目录并执行以下操作:
mkdir /tmp/nix-mcp-test && cd /tmp/nix-mcp-test创建 flake.nix (参见示例/test flake.nix),然后:
# Dry run - see what would be generated
home-manager build --flake .#test
# Check generated config
cat result/home-path/etc/profile.d/hm-session-vars.sh
# Actually apply (modifies your home)
home-manager switch --flake .#test验证
设置后:
# Check Claude Code
claude --version
# Check MCP servers
claude mcp list
# Check plugins
claude plugin list
# Check config was merged
cat ~/.claude.json | jq '.mcpServers'许可证
麻省理工学院
