2017-01-30 12:44:14 -05:00
|
|
|
# NixOS module for Buildbot Worker.
|
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
options,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.services.buildbot-worker;
|
|
|
|
opt = options.services.buildbot-worker;
|
|
|
|
|
2023-04-07 18:34:08 +02:00
|
|
|
package = pkgs.python3.pkgs.toPythonModule cfg.package;
|
|
|
|
python = package.pythonModule;
|
2017-12-16 23:06:43 -05:00
|
|
|
|
|
|
|
tacFile = pkgs.writeText "aur-buildbot-worker.tac" ''
|
|
|
|
import os
|
|
|
|
from io import open
|
|
|
|
|
|
|
|
from buildbot_worker.bot import Worker
|
|
|
|
from twisted.application import service
|
|
|
|
|
|
|
|
basedir = '${cfg.buildbotDir}'
|
|
|
|
|
|
|
|
# note: this line is matched against to check that this is a worker
|
|
|
|
# directory; do not edit it.
|
|
|
|
application = service.Application('buildbot-worker')
|
|
|
|
|
|
|
|
master_url_split = '${cfg.masterUrl}'.split(':')
|
|
|
|
buildmaster_host = master_url_split[0]
|
|
|
|
port = int(master_url_split[1])
|
|
|
|
workername = '${cfg.workerUser}'
|
|
|
|
|
|
|
|
with open('${cfg.workerPassFile}', 'r', encoding='utf-8') as passwd_file:
|
|
|
|
passwd = passwd_file.read().strip('\r\n')
|
2020-07-13 13:07:20 -04:00
|
|
|
keepalive = ${toString cfg.keepalive}
|
2017-12-16 23:06:43 -05:00
|
|
|
umask = None
|
|
|
|
maxdelay = 300
|
|
|
|
numcpus = None
|
|
|
|
allow_shutdown = None
|
|
|
|
|
|
|
|
s = Worker(buildmaster_host, port, workername, passwd, basedir,
|
|
|
|
keepalive, umask=umask, maxdelay=maxdelay,
|
|
|
|
numcpus=numcpus, allow_shutdown=allow_shutdown)
|
|
|
|
s.setServiceParent(application)
|
|
|
|
'';
|
|
|
|
|
2017-01-30 12:44:14 -05:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.buildbot-worker = {
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2017-01-30 12:44:14 -05:00
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the Buildbot Worker.";
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
user = lib.mkOption {
|
2017-01-30 12:44:14 -05:00
|
|
|
default = "bbworker";
|
2024-12-08 13:18:23 +01:00
|
|
|
type = lib.types.str;
|
2017-01-30 12:44:14 -05:00
|
|
|
description = "User the buildbot Worker should execute under.";
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
group = lib.mkOption {
|
2017-01-30 12:44:14 -05:00
|
|
|
default = "bbworker";
|
2024-12-08 13:18:23 +01:00
|
|
|
type = lib.types.str;
|
2017-01-30 12:44:14 -05:00
|
|
|
description = "Primary group of buildbot Worker user.";
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
extraGroups = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2017-03-09 11:46:26 -05:00
|
|
|
default = [ ];
|
2017-01-30 12:44:14 -05:00
|
|
|
description = "List of extra groups that the Buildbot Worker user should be a part of.";
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
home = lib.mkOption {
|
2017-01-30 12:44:14 -05:00
|
|
|
default = "/home/bbworker";
|
2024-12-08 13:18:23 +01:00
|
|
|
type = lib.types.path;
|
2017-01-30 12:44:14 -05:00
|
|
|
description = "Buildbot home directory.";
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
buildbotDir = lib.mkOption {
|
2017-01-30 12:44:14 -05:00
|
|
|
default = "${cfg.home}/worker";
|
2024-12-08 13:18:23 +01:00
|
|
|
defaultText = lib.literalExpression ''"''${config.${opt.home}}/worker"'';
|
|
|
|
type = lib.types.path;
|
2017-01-30 12:44:14 -05:00
|
|
|
description = "Specifies the Buildbot directory.";
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
workerUser = lib.mkOption {
|
2017-01-30 12:44:14 -05:00
|
|
|
default = "example-worker";
|
2024-12-08 13:18:23 +01:00
|
|
|
type = lib.types.str;
|
2017-01-30 12:44:14 -05:00
|
|
|
description = "Specifies the Buildbot Worker user.";
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
workerPass = lib.mkOption {
|
2017-01-30 12:44:14 -05:00
|
|
|
default = "pass";
|
2024-12-08 13:18:23 +01:00
|
|
|
type = lib.types.str;
|
2017-01-30 12:44:14 -05:00
|
|
|
description = "Specifies the Buildbot Worker password.";
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
workerPassFile = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
2017-12-16 23:06:43 -05:00
|
|
|
description = "File used to store the Buildbot Worker password";
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
hostMessage = lib.mkOption {
|
2017-12-16 23:06:43 -05:00
|
|
|
default = null;
|
2024-12-08 13:18:23 +01:00
|
|
|
type = lib.types.nullOr lib.types.str;
|
2017-12-16 23:06:43 -05:00
|
|
|
description = "Description of this worker";
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
adminMessage = lib.mkOption {
|
2017-12-16 23:06:43 -05:00
|
|
|
default = null;
|
2024-12-08 13:18:23 +01:00
|
|
|
type = lib.types.nullOr lib.types.str;
|
2017-12-16 23:06:43 -05:00
|
|
|
description = "Name of the administrator of this worker";
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
masterUrl = lib.mkOption {
|
2017-01-30 12:44:14 -05:00
|
|
|
default = "localhost:9989";
|
2024-12-08 13:18:23 +01:00
|
|
|
type = lib.types.str;
|
2017-01-30 12:44:14 -05:00
|
|
|
description = "Specifies the Buildbot Worker connection string.";
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
keepalive = lib.mkOption {
|
2020-07-13 13:07:20 -04:00
|
|
|
default = 600;
|
2024-12-08 13:18:23 +01:00
|
|
|
type = lib.types.int;
|
2022-08-14 05:16:55 +02:00
|
|
|
description = ''
|
2020-07-13 13:07:20 -04:00
|
|
|
This is a number that indicates how frequently keepalive messages should be sent
|
|
|
|
from the worker to the buildmaster, expressed in seconds.
|
2022-08-14 05:16:55 +02:00
|
|
|
'';
|
2020-07-13 13:07:20 -04:00
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
package = lib.mkPackageOption pkgs "buildbot-worker" { };
|
2017-01-30 12:44:14 -05:00
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
packages = lib.mkOption {
|
2017-12-16 23:06:43 -05:00
|
|
|
default = with pkgs; [ git ];
|
2024-12-08 13:18:23 +01:00
|
|
|
defaultText = lib.literalExpression "[ pkgs.git ]";
|
|
|
|
type = lib.types.listOf lib.types.package;
|
2017-01-30 12:44:14 -05:00
|
|
|
description = "Packages to add to PATH for the buildbot process.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
services.buildbot-worker.workerPassFile = lib.mkDefault (
|
|
|
|
pkgs.writeText "buildbot-worker-password" cfg.workerPass
|
|
|
|
);
|
2017-12-16 23:06:43 -05:00
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
users.groups = lib.optionalAttrs (cfg.group == "bbworker") {
|
2019-09-14 19:51:29 +02:00
|
|
|
bbworker = { };
|
2017-01-30 12:44:14 -05:00
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
users.users = lib.optionalAttrs (cfg.user == "bbworker") {
|
2019-09-14 19:51:29 +02:00
|
|
|
bbworker = {
|
|
|
|
description = "Buildbot Worker User.";
|
|
|
|
isNormalUser = true;
|
|
|
|
createHome = true;
|
|
|
|
home = cfg.home;
|
|
|
|
group = cfg.group;
|
|
|
|
extraGroups = cfg.extraGroups;
|
|
|
|
useDefaultShell = true;
|
|
|
|
};
|
2017-01-30 12:44:14 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.buildbot-worker = {
|
|
|
|
description = "Buildbot Worker.";
|
2017-02-27 14:02:11 -05:00
|
|
|
after = [
|
|
|
|
"network.target"
|
|
|
|
"buildbot-master.service"
|
|
|
|
];
|
2017-01-30 12:44:14 -05:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = cfg.packages;
|
2023-04-07 18:34:08 +02:00
|
|
|
environment.PYTHONPATH = "${python.withPackages (p: [ package ])}/${python.sitePackages}";
|
2017-01-30 12:44:14 -05:00
|
|
|
|
|
|
|
preStart = ''
|
2017-12-16 23:06:43 -05:00
|
|
|
mkdir -vp "${cfg.buildbotDir}/info"
|
2024-12-08 13:18:23 +01:00
|
|
|
${lib.optionalString (cfg.hostMessage != null) ''
|
2017-12-16 23:06:43 -05:00
|
|
|
ln -sf "${pkgs.writeText "buildbot-worker-host" cfg.hostMessage}" "${cfg.buildbotDir}/info/host"
|
|
|
|
''}
|
2024-12-08 13:18:23 +01:00
|
|
|
${lib.optionalString (cfg.adminMessage != null) ''
|
2017-12-16 23:06:43 -05:00
|
|
|
ln -sf "${pkgs.writeText "buildbot-worker-admin" cfg.adminMessage}" "${cfg.buildbotDir}/info/admin"
|
|
|
|
''}
|
2017-01-30 12:44:14 -05:00
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
2017-03-10 00:02:49 -05:00
|
|
|
Type = "simple";
|
2017-01-30 12:44:14 -05:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
WorkingDirectory = cfg.home;
|
2017-03-07 14:26:21 -05:00
|
|
|
|
|
|
|
# NOTE: call twistd directly with stdout logging for systemd
|
2017-12-16 23:06:43 -05:00
|
|
|
ExecStart = "${python.pkgs.twisted}/bin/twistd --nodaemon --pidfile= --logfile - --python ${tacFile}";
|
2017-01-30 12:44:14 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-12-28 11:48:40 +10:00
|
|
|
meta.maintainers = lib.teams.buildbot.members;
|
2017-01-30 12:44:14 -05:00
|
|
|
|
|
|
|
}
|