Add remote autoscaler daemon endpoint support
All checks were successful
buildbot/nix-eval Build done.
buildbot/nix-build Build done.
buildbot/nix-effects Build done.

This commit is contained in:
Abel Luck 2026-03-05 15:47:57 +01:00
parent 95021a4253
commit 679b5c8d07
11 changed files with 291 additions and 22 deletions

View file

@ -45,6 +45,24 @@ in
description = "Unix socket path exposed by the autoscaler API server.";
};
listenHost = lib.mkOption {
type = lib.types.str;
default = "127.0.0.1";
description = "TCP listen host for the autoscaler API server when listenPort is set.";
};
listenPort = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
description = "Optional TCP listen port for the autoscaler API server. Null keeps Unix socket mode.";
};
authTokenFile = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "Optional file containing bearer token required for /v1 and /metrics API requests.";
};
logLevel = lib.mkOption {
type = lib.types.str;
default = "info";
@ -287,6 +305,10 @@ in
assertion = !cfg.capacity.nestedVirtualization || cfg.aws.onDemandLaunchTemplateIdFile != null;
message = "services.nix-builder-autoscaler.aws.onDemandLaunchTemplateIdFile must be set when capacity.nestedVirtualization is true.";
}
{
assertion = cfg.listenPort == null || (cfg.listenPort >= 1 && cfg.listenPort <= 65535);
message = "services.nix-builder-autoscaler.listenPort must be null or a TCP port between 1 and 65535.";
}
];
environment.systemPackages = [ cfg.package ];
@ -338,10 +360,16 @@ in
${lib.optionalString (cfg.aws.assumeRoleArnFile != null) ''
assume_role_arn="$(tr -d '\n' < ${lib.escapeShellArg cfg.aws.assumeRoleArnFile})"
''}
${lib.optionalString (cfg.authTokenFile != null) ''
auth_token="$(tr -d '\n' < ${lib.escapeShellArg cfg.authTokenFile})"
''}
cat > ${generatedConfigPath} <<EOF
[server]
socket_path = "${cfg.socketPath}"
listen_host = "${cfg.listenHost}"
listen_port = ${toString (if cfg.listenPort != null then cfg.listenPort else 0)}
${lib.optionalString (cfg.authTokenFile != null) ''auth_token = "$auth_token"''}
log_level = "${cfg.logLevel}"
db_path = "${cfg.dbPath}"