2026-11-02 08:00:24 +01:00
|
|
|
# T3 Code server, reachable from the active NetBird network only.
|
|
|
|
|
#
|
|
|
|
|
# The service follows the mesh interface: it stops when NetBird removes the
|
|
|
|
|
# interface and starts again with the new address when a profile comes up
|
|
|
|
|
# (`netbird up --profile <name>`). It owns ~/.t3, so a desktop app on the same
|
|
|
|
|
# host must connect as a client with its local environment off.
|
|
|
|
|
#
|
|
|
|
|
# Wanted by the device rather than multi-user.target, so a host without NetBird
|
|
|
|
|
# connection does not wait for it at boot. A first deploy with the interface
|
|
|
|
|
# already up needs one `systemctl start t3code`.
|
|
|
|
|
{
|
|
|
|
|
config,
|
|
|
|
|
lib,
|
|
|
|
|
pkgs,
|
|
|
|
|
utils,
|
|
|
|
|
...
|
|
|
|
|
}: let
|
|
|
|
|
cfg = config.m3ta.t3code;
|
|
|
|
|
device = "${utils.escapeSystemdPath "/sys/subsystem/net/devices/${cfg.interface}"}.device";
|
|
|
|
|
home = config.users.users.${cfg.user}.home;
|
|
|
|
|
|
|
|
|
|
serve = pkgs.writeShellApplication {
|
|
|
|
|
name = "t3code-serve";
|
|
|
|
|
runtimeInputs = [pkgs.iproute2 pkgs.coreutils];
|
|
|
|
|
text = builtins.readFile ./t3code-serve.sh;
|
|
|
|
|
};
|
|
|
|
|
in {
|
|
|
|
|
options.m3ta.t3code = {
|
|
|
|
|
enable = lib.mkEnableOption "the T3 Code server on the NetBird interface";
|
|
|
|
|
|
|
|
|
|
user = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
description = "User running the server; the harnesses come from this user's profile.";
|
|
|
|
|
example = "m3tam3re";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
port = lib.mkOption {
|
|
|
|
|
type = lib.types.port;
|
|
|
|
|
default = 3773;
|
|
|
|
|
description = "Port for the HTTP/WebSocket server.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
interface = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
default = "wt0";
|
|
|
|
|
description = "NetBird interface to bind to and open the port on.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
package = lib.mkOption {
|
|
|
|
|
type = lib.types.package;
|
|
|
|
|
default = pkgs.llm-agents.t3code;
|
|
|
|
|
defaultText = lib.literalExpression "pkgs.llm-agents.t3code";
|
|
|
|
|
description = "T3 Code package.";
|
|
|
|
|
};
|
2026-11-05 07:48:18 +01:00
|
|
|
|
|
|
|
|
environmentFile = lib.mkOption {
|
|
|
|
|
type = lib.types.nullOr (lib.types.pathWith {
|
|
|
|
|
inStore = false;
|
|
|
|
|
absolute = true;
|
|
|
|
|
});
|
|
|
|
|
default = null;
|
|
|
|
|
example = "/run/agenix/t3code-env";
|
|
|
|
|
description = ''
|
|
|
|
|
File with `KEY=value` lines loaded into the server's environment
|
|
|
|
|
(systemd `EnvironmentFile`), e.g. tokens for the harnesses. Keep it
|
|
|
|
|
outside the Nix store, for example as an agenix secret.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2026-11-02 08:00:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
|
assertions = [
|
|
|
|
|
{
|
|
|
|
|
assertion = config.services.netbird.enable;
|
|
|
|
|
message = "m3ta.t3code requires services.netbird.enable";
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
systemd.services.t3code = {
|
|
|
|
|
description = "T3 Code server";
|
|
|
|
|
after = [device "netbird.service"];
|
|
|
|
|
bindsTo = [device];
|
|
|
|
|
wantedBy = [device];
|
|
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
User = cfg.user;
|
|
|
|
|
Group = "users";
|
|
|
|
|
WorkingDirectory = home;
|
|
|
|
|
ExecStart = "${serve}/bin/t3code-serve ${cfg.interface} ${cfg.package}/bin/t3";
|
|
|
|
|
Restart = "on-failure";
|
|
|
|
|
RestartSec = "5";
|
2026-11-05 07:48:18 +01:00
|
|
|
EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile;
|
2026-11-02 08:00:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
|
T3CODE_PORT = toString cfg.port;
|
|
|
|
|
HOME = home;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# The harnesses come from the user's profile, not from the service.
|
|
|
|
|
path = [
|
|
|
|
|
"/etc/profiles/per-user/${cfg.user}"
|
|
|
|
|
"/run/current-system/sw"
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
networking.firewall.interfaces.${cfg.interface}.allowedTCPPorts = [cfg.port];
|
|
|
|
|
};
|
|
|
|
|
}
|