2026-10-25 13:01:05 +01:00
|
|
|
{
|
|
|
|
|
config,
|
|
|
|
|
pkgs,
|
|
|
|
|
...
|
|
|
|
|
}: let
|
|
|
|
|
# Netbird mesh VPN range — the server is only reachable from mesh peers.
|
|
|
|
|
# m3-atlas Traefik proxies memory.m3ta.dev to this port over Netbird.
|
2026-10-31 11:18:49 +01:00
|
|
|
# (Fleet mesh address block is 100.81.0.0/16 — kernel route on wt0.)
|
|
|
|
|
netbirdRange = "100.81.0.0/16";
|
2026-10-25 13:01:05 +01:00
|
|
|
port = config.m3ta.ports.get "ai-memory";
|
|
|
|
|
in {
|
|
|
|
|
# ── ai-memory server ──────────────────────────────────────────────────
|
|
|
|
|
# Shared agent memory for all hosts (private + work), see
|
|
|
|
|
# https://aimemory.sh. Clients: m3ta-home `coding.aiMemory`.
|
|
|
|
|
#
|
|
|
|
|
# Flow: Agent → memory.m3ta.dev (TLS via m3-atlas Traefik) → Netbird → :${toString port}
|
|
|
|
|
# Hermes on this host talks to 127.0.0.1 directly.
|
|
|
|
|
services.ai-memory = {
|
|
|
|
|
enable = true;
|
|
|
|
|
# Same build as the clients (m3ta-home uses llm-agents.ai-memory),
|
|
|
|
|
# prebuilt via the numtide cache instead of compiling the flake.
|
|
|
|
|
package = pkgs.llm-agents.ai-memory;
|
|
|
|
|
bind = "0.0.0.0";
|
|
|
|
|
inherit port;
|
|
|
|
|
enableWeb = true;
|
|
|
|
|
# Root bearer, token pepper, recovery token, cookie/proxy settings and
|
|
|
|
|
# the LLM provider key. Never put any of these into `settings`.
|
|
|
|
|
ageSecret = "ai-memory-server-env";
|
|
|
|
|
settings = {
|
|
|
|
|
allowed_hosts = ["memory.m3ta.dev" "localhost" "127.0.0.1" "::1"];
|
|
|
|
|
# One operator, several workspaces (private, az, home): keep one
|
|
|
|
|
# cross-project profile for all of them. With database users the
|
|
|
|
|
# profile is off unless enabled explicitly.
|
|
|
|
|
profile = {
|
|
|
|
|
enabled = true;
|
|
|
|
|
share = "global";
|
|
|
|
|
};
|
|
|
|
|
# Shared server: auto-improvement proposals wait for approval.
|
|
|
|
|
auto_improve.require_approval = true;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-25 14:24:51 +01:00
|
|
|
# A changed secret (model, keys, tokens) does not change the unit file, so
|
|
|
|
|
# without this the running server keeps the old environment after a switch.
|
|
|
|
|
systemd.services.ai-memory.restartTriggers = [config.age.secrets."ai-memory-server-env".file];
|
|
|
|
|
|
2026-10-25 13:01:05 +01:00
|
|
|
networking.firewall = {
|
|
|
|
|
extraCommands = ''
|
|
|
|
|
# Allow ai-memory only from Netbird mesh VPN
|
|
|
|
|
ip46tables -A nixos-fw -p tcp --dport ${toString port} -s ${netbirdRange} -j nixos-fw-accept
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
extraStopCommands = ''
|
|
|
|
|
ip46tables -D nixos-fw -p tcp --dport ${toString port} -s ${netbirdRange} -j nixos-fw-accept 2>/dev/null || true
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
}
|