nix-agent

nix-agent

A local MCP server for trusted NixOS automation that enables inspecting files, applying patch sets, and validating/switching NixOS or Home Manager configurations.

Category
Visit Server

README

nix-agent

nix-agent is a local MCP server for trusted NixOS automation.

It works alongside mcp-nixos:

  • nix-agent handles local inspection, patching, validation, and switching
  • mcp-nixos handles package and option discovery

NOTE: This is experimental and a work in progress. Feedback and contributions are very welcome.

What you get

  • a runnable stdio MCP server
  • a Nix flake package and app
  • a NixOS module at nixosModules.default
  • a companion agent skill in skills/nix-agent/
  • example MCP host configs in examples/

One-shot agent install

Paste this to a coding agent (Claude Code, opencode, etc.) and it will do the install for you:

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.

Fast install

Add this flake input and module to your NixOS config:

{
  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;
        })
      ];
    };
  };
}

Then rebuild:

sudo nixos-rebuild switch --flake .#my-host

That installs the nix-agent binary.

MCP host config

Point your MCP host at:

{
  "mcpServers": {
    "nix-agent": {
      "command": "nix-agent",
      "args": []
    }
  }
}

See examples/claude-code-mcp.json and examples/opencode-mcp.json.

Companion skill

Install or copy skills/nix-agent/ into your agent's skill directory.

Quick install:

./install-skill.sh opencode

The MCP exposes the tools. The skill teaches the correct workflow.

Tool surface

nix-agent exposes two tools:

  • inspect_state(path) — read a local file.
  • apply_patch_set(patch_set, flake_uri=None, mode="nixos") — write each Patch(path, content), format any .nix files, and (when flake_uri is given) validate then switch.
    • mode="nixos" (default) runs sudo nixos-rebuild dry-activate then switch.
    • mode="home-manager" runs home-manager build then home-manager switch (no sudo).
    • Returns changed_files, rollback_generation, current_generation, command outputs, and a status.

mcp-nixos handles package and option discovery.

Basic workflow

  1. If you need package or option info, query mcp-nixos first.
  2. Build a PatchSet of Patch(path, content) entries.
  3. Call apply_patch_set(patch_set, flake_uri="/etc/nixos#hostname") for NixOS, or apply_patch_set(patch_set, flake_uri="/path/to/flake#user@host", mode="home-manager") for Home Manager.
  4. If anything looks wrong, recover via sudo nixos-rebuild switch --rollback (NixOS) or by activating a previous Home Manager generation. The response includes rollback_generation for reference.

You can also call apply_patch_set(PatchSet(patches=[]), flake_uri=...) with no patches to validate and switch the current flake state — useful after manual edits or to re-run a rebuild without writing any files.

On validation or switch failure the response includes a first_error field with the first error: line extracted from Nix's output, alongside the full log.

Design notes

  • nix-agent deliberately does not ship an in-MCP approval gate. Path restrictions belong in the host's permission system (e.g. Claude Code's allow/deny lists), and rollback safety belongs to Nix generations. Re-implementing either inside the MCP just adds friction without improving safety.
  • Do not write secret payloads through patches — reference secrets via sops-nix or agenix.
  • v1 assumes a trusted local environment.
  • Fully non-interactive apply requires privileged automation; see docs/privileged-automation.md.

More detail

  • release notes: docs/releases/v0.1.0.md
  • skill docs: skills/nix-agent/SKILL.md
  • examples: examples/

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured