fix: propagate config.env.vars to LaunchAgent/systemd service environment (#1735)

When installing the Gateway daemon via LaunchAgent (macOS) or systemd (Linux),
environment variables defined in config.env.vars were not being included in
the service environment. This caused API keys and other env vars configured
in clawdbot.json5 to be unavailable when the Gateway ran as a service.

The fix adds a configEnvVars parameter to buildGatewayInstallPlan() which
merges config.env.vars into the service environment. Service-specific
variables (CLAWDBOT_*, HOME, PATH) take precedence over config env vars.

Fixes the issue where users had to manually edit the LaunchAgent plist
to add environment variables like GOOGLE_API_KEY.
This commit is contained in:
Matias Wainsten
2026-01-25 07:35:55 -03:00
committed by GitHub
parent bfa57aae44
commit f29f51569a
8 changed files with 85 additions and 1 deletions

View File

@@ -31,6 +31,8 @@ export async function buildGatewayInstallPlan(params: {
devMode?: boolean;
nodePath?: string;
warn?: WarnFn;
/** Environment variables from config.env.vars to include in the service environment */
configEnvVars?: Record<string, string | undefined>;
}): Promise<GatewayInstallPlan> {
const devMode = params.devMode ?? resolveGatewayDevMode();
const nodePath =
@@ -50,7 +52,7 @@ export async function buildGatewayInstallPlan(params: {
const warning = renderSystemNodeWarning(systemNode, programArguments[0]);
if (warning) params.warn?.(warning, "Gateway runtime");
}
const environment = buildServiceEnvironment({
const serviceEnvironment = buildServiceEnvironment({
env: params.env,
port: params.port,
token: params.token,
@@ -60,6 +62,16 @@ export async function buildGatewayInstallPlan(params: {
: undefined,
});
// Merge config.env.vars into the service environment.
// Config env vars are added first so service-specific vars take precedence.
const environment: Record<string, string | undefined> = {};
if (params.configEnvVars) {
for (const [key, value] of Object.entries(params.configEnvVars)) {
if (value) environment[key] = value;
}
}
Object.assign(environment, serviceEnvironment);
return { programArguments, workingDirectory, environment };
}