2026-04-04 16:26:33 -04:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
cfg = config.services.openclaw-node;
|
|
|
|
|
openclawPkg = pkgs.openclaw;
|
|
|
|
|
in {
|
|
|
|
|
options.services.openclaw-node = {
|
|
|
|
|
enable = lib.mkEnableOption "OpenClaw Node service";
|
|
|
|
|
|
|
|
|
|
user = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
default = "ai-worker";
|
|
|
|
|
description = "User to run the OpenClaw headless node as.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
gatewayHost = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
default = "127.0.0.1";
|
|
|
|
|
description = "Gateway host (IP or hostname).";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
gatewayPort = lib.mkOption {
|
|
|
|
|
type = lib.types.int;
|
|
|
|
|
default = 18789;
|
|
|
|
|
description = "Gateway WebSocket port.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
gatewayTokenFile = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
default = "";
|
|
|
|
|
description = "Path to file containing the gateway auth token.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
displayName = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
default = "lazyworkhorse-host";
|
|
|
|
|
description = "Display name for this node (shown in pairing).";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
|
systemd.services.openclaw-node = {
|
|
|
|
|
description = "OpenClaw Headless Node Service";
|
|
|
|
|
after = [ "network.target" ];
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
Type = "exec";
|
|
|
|
|
User = cfg.user;
|
|
|
|
|
Group = cfg.user;
|
2026-04-04 17:07:13 -04:00
|
|
|
WorkingDirectory = "/home/${cfg.user}";
|
2026-04-04 16:26:33 -04:00
|
|
|
ExecStart = ''
|
2026-04-04 17:49:39 -04:00
|
|
|
${pkgs.bash}/bin/bash -c 'export OPENCLAW_GATEWAY_TOKEN=$(cat ${cfg.gatewayTokenFile}) && exec ${openclawPkg}/bin/openclaw node run --host ${cfg.gatewayHost} --port ${toString cfg.gatewayPort} --display-name "${cfg.displayName}"'
|
2026-04-04 16:26:33 -04:00
|
|
|
'';
|
2026-04-04 17:43:03 -04:00
|
|
|
Restart = "always";
|
|
|
|
|
RestartSec = 5;
|
2026-04-04 16:26:33 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
|
NODE_ENV = "production";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|