Files
nixos-config/hosts/m3-hermes/services/t3code.nix
T
m3ta-chiron d8239fcd32 fix(m3-hermes): firewall — interface match instead of IPv4 CIDR in ip46tables
The mesh-only accept rules used 'ip46tables ... -s 100.x/16'. ip46tables
runs every rule through iptables AND ip6tables; ip6tables cannot parse an
IPv4 CIDR and aborts with 'host/network not found', failing the whole
firewall.service (status 2).

Consequence beyond the unit failure: the firewall-start script aborted at
the first such rule, so the trailing default-reject rules were never
applied — the input filter was effectively OPEN (only SSH/established
rules had been added). This also explains why the mesh services were
reachable although the previous 100.64.0.0/16 source rule never matched
any peer.

Fix: match on the NetBird interface (-i wt0) instead of a source range —
family-agnostic, survives NetBird range changes, and matches the idiom
the generated script already uses for NetBird service ports. Applied to
ai-memory, hermes-dashboard and t3code rules (add + stop-commands).

After deploying: firewall.service completes, default-reject applies, and
49374/9119/8642/3773 become reachable from the mesh ONLY (previously
open to everyone). Anything that silently relied on the open filter will
start failing — that is the intended posture.
2026-10-31 13:17:42 +01:00

78 lines
2.9 KiB
Nix

# T3 Code server (https://t3.codes) — interactive coding-agent cockpit.
#
# Part of the three-lane agent setup (agreed 2026-10-26):
# - Lane 1, interactive cockpit: T3 Code on m3-hermes, reached over the
# NetBird mesh via direct pairing (no T3 Connect cloud relay).
# - Lane 2, autonomous workers: herdr sandbox (see herdr-sandbox.nix).
# - Lane 3, control & inbox: Hermes via Matrix (unchanged).
#
# Flow: T3 desktop/mobile app ──NetBird mesh──▶ wt0 :3773 (this server).
# The server binds 0.0.0.0, but the firewall admits the port for mesh
# peers only — same posture as ai-memory and the hermes dashboard.
#
# One-time interactive steps after deploy (deliberately NOT declarative —
# subscription auth must live in each harness's own credential store and
# may not be shared with other tools per provider ToS):
# - Pair clients: `sudo -u m3tam3re t3 pair` (or take the pairing URL
# from `journalctl -u t3code` after first start) and add the
# environment in the T3 app via the printed URL/QR code.
# - Claude Code: `sudo -u m3tam3re claude auth login`
# (persists in /home/m3tam3re/.claude).
# - OpenCode: `sudo -u m3tam3re opencode auth login`
# (subscription auth persists in OpenCode's own state dir).
{
config,
pkgs,
...
}: let
# Mesh-only via interface match on wt0 (NetBird) — an IPv4 CIDR in -s
# would abort the ip6tables run of ip46tables and fail the unit.
port = config.m3ta.ports.get "t3code";
in {
# CLI on the system for interactive admin (t3 pair, t3 service status)
# plus the harnesses T3 Code orchestrates. Login shells need them for
# the one-time auth flows documented in the header.
environment.systemPackages = [
pkgs.llm-agents.t3code
pkgs.llm-agents.opencode2
pkgs.llm-agents.claude-code
];
# ── T3 Code server (system service, cockpit user) ────────────────────
systemd.services.t3code = {
description = "T3 Code server (interactive coding-agent cockpit)";
after = ["network-online.target"];
wants = ["network-online.target"];
wantedBy = ["multi-user.target"];
serviceConfig = {
User = "m3tam3re";
Group = "users";
WorkingDirectory = "/home/m3tam3re";
ExecStart = "${pkgs.llm-agents.t3code}/bin/t3 serve --host 0.0.0.0";
Restart = "on-failure";
RestartSec = "5";
};
environment.T3CODE_PORT = toString port;
# Harness CLIs and git for the agents T3 Code spawns.
path = with pkgs; [
git
llm-agents.opencode2
llm-agents.claude-code
];
};
networking.firewall = {
extraCommands = ''
# Allow t3code only from Netbird mesh VPN
ip46tables -A nixos-fw -p tcp --dport ${toString port} -i wt0 -j nixos-fw-accept
'';
extraStopCommands = ''
ip46tables -D nixos-fw -p tcp --dport ${toString port} -i wt0 -j nixos-fw-accept 2>/dev/null || true
'';
};
}