Files
imladris/configs/mcp.nix
Kyle Isom baf09e8b1f Add MCP to Nix packages and wire agent to Nix-managed binary
- Add mcp flake input (git+ssh://git@git.wntrmute.dev/mc/mcp.git)
- Add mcp CLI to mcpkg.nix system packages (installed on all machines)
- Update mcp.nix to use Nix-managed mcp-agent binary path instead of
  hardcoded /usr/local/bin/mcp-agent

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 22:48:40 -07:00

60 lines
1.8 KiB
Nix

# MCP (Metacircular Control Plane) agent user and configuration.
#
# Creates a dedicated 'mcp' system user with rootless podman support
# and a systemd service for the agent daemon.
{ pkgs, inputs, ... }:
let
mcpUid = 995;
in
{
users.users.mcp = {
isSystemUser = true;
uid = mcpUid; # Pin UID so systemd Environment references stay stable.
group = "mcp";
home = "/srv/mcp";
shell = pkgs.shadow; # nologin equivalent
subUidRanges = [{ startUid = 100000; count = 65536; }];
subGidRanges = [{ startGid = 100000; count = 65536; }];
linger = true;
};
users.groups.mcp = {};
systemd.services.mcp-agent = {
description = "MCP Agent";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "${inputs.mcp.packages.x86_64-linux.mcp-agent}/bin/mcp-agent server --config /srv/mcp/mcp-agent.toml";
Restart = "on-failure";
RestartSec = 5;
User = "mcp";
Group = "mcp";
Environment = [
"HOME=/srv/mcp"
"XDG_RUNTIME_DIR=/run/user/${toString mcpUid}"
"PATH=/run/current-system/sw/bin:/usr/local/bin"
];
NoNewPrivileges = true;
ProtectSystem = "full"; # "strict" blocks /run/user; "full" protects /usr and /boot
# ProtectHome makes /run/user inaccessible, which breaks rootless podman.
# The agent's home is /srv/mcp (not /home), so this is acceptable.
ProtectHome = false;
PrivateTmp = true;
PrivateDevices = true;
ProtectKernelTunables = true;
ProtectKernelModules = true;
RestrictSUIDSGID = true;
LockPersonality = true;
RestrictRealtime = true;
ReadWritePaths = [ "/srv" ];
};
};
}