Skip to content

Write Once, Target Multiple Tools

When multiple tools consume the same configuration — such as MCP servers and coding rules shared between Claude Code and Codex, or service routes shared between Caddy and Prometheus — putting a shared sink in the middle keeps producers and consumers completely decoupled:

  • Producers (your feature modules) emit data once into a neutral sink (aiMcp, aiRules, endpoints, backupJobs).
  • Consumers (each tool adapter) read the reduced sink and render their own config format.
  • Adding a third tool never touches any feature module, and opting out of one tool (drop = [ yen.aspects.codex-cli ]) leaves the other untouched.

1. Define shared sinks and emit from features

Section titled “1. Define shared sinks and emit from features”
modules/ai/sinks.nix
{
yen,
std,
reduce,
...
}:
{
imports = [ std.modules.all ];
# Tool-agnostic shared sinks on `user`: features emit here once without knowing which AI tool reads them.
yen.kinds.user.sinks = {
aiMcp = {
reduce = reduce.merge;
allowOrphan = true;
};
aiRules = {
reduce = reduce.list;
allowOrphan = true;
};
};
yen.user.alice.email = "alice@example.org";
yen.host.laptop.users = [ yen.user.alice ];
# Feature modules emit MCP servers and coding rules once into the shared sinks.
yen.aspects.git-mcp = {
at = yen.kinds.user;
aiMcp.github.command = "github-mcp-server";
aiRules = "Never force-push main.";
};
yen.aspects.postgres-mcp = {
at = yen.kinds.user;
aiMcp.postgres.command = "postgres-mcp";
aiRules = "Run schema checks before migrations.";
};
}

Neither claude-code nor codex-cli knows about git-mcp or postgres-mcp, and neither knows about the other.

modules/ai/consumers.nix
{ yen, ... }:
let
b = builtins;
in
{
# Consumer 1: Claude Code reads `aiMcp` and `aiRules` into its own Home Manager config.
yen.aspects.claude-code = {
at = yen.kinds.user;
cycle =
{ aiMcp, aiRules, ... }:
{
hm.home.file = {
".claude/mcp.json".text = b.toJSON { mcpServers = aiMcp; };
".claude/CLAUDE.md".text = b.concatStringsSep "\n" aiRules;
};
};
};
# Consumer 2: Codex reads the EXACT same sinks with zero coupling to `claude-code` or feature modules.
yen.aspects.codex-cli = {
at = yen.kinds.user;
cycle =
{ aiMcp, aiRules, ... }:
{
hm.home.file = {
".codex/mcp.json".text = b.toJSON { servers = aiMcp; };
".codex/AGENTS.md".text = b.concatStringsSep "\n" aiRules;
};
};
};
}

Inspect the Home Manager files generated for Alice:

nix eval .#hm.laptop.alice.home.file
{
".claude/CLAUDE.md" = {
text = "Never force-push main.\nRun schema checks before migrations.";
};
".claude/mcp.json" = {
text = "{\"mcpServers\":{\"github\":{\"command\":\"github-mcp-server\"},\"postgres\":{\"command\":\"postgres-mcp\"}}}";
};
".codex/AGENTS.md" = {
text = "Never force-push main.\nRun schema checks before migrations.";
};
".codex/mcp.json" = {
text = "{\"servers\":{\"github\":{\"command\":\"github-mcp-server\"},\"postgres\":{\"command\":\"postgres-mcp\"}}}";
};
}
  • AI coding assistants: share aiMcp, aiSkills, aiAgents, and aiRules across Claude Code, Codex, Antigravity, or OpenCode.
  • Web & observability: emit service routes once; let Caddy generate reverse proxies and Prometheus generate scrape targets from the same sink.
  • Security & persistence: std.modules.resources uses this exact pattern for unfree, firewall, persist, and secrets (see Bubbling unfree, Firewall, Secrets & Persist).

Next, see how Yen lets you mix fleet fields with pkgs and config without specialArgs in Mixing Fleet Data with pkgs and config.

ContributeCommunitySponsor