2017-01-30 18:44:14 +01:00
|
|
|
# NixOS module for Buildbot Worker.
|
|
|
|
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.buildbot-worker;
|
|
|
|
|
2017-12-17 05:06:43 +01:00
|
|
|
python = cfg.package.pythonModule;
|
|
|
|
|
|
|
|
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 19:07:20 +02:00
|
|
|
keepalive = ${toString cfg.keepalive}
|
2017-12-17 05:06:43 +01: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 18:44:14 +01:00
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.buildbot-worker = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the Buildbot Worker.";
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
default = "bbworker";
|
|
|
|
type = types.str;
|
|
|
|
description = "User the buildbot Worker should execute under.";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
default = "bbworker";
|
|
|
|
type = types.str;
|
|
|
|
description = "Primary group of buildbot Worker user.";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraGroups = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2017-03-09 17:46:26 +01:00
|
|
|
default = [];
|
2017-01-30 18:44:14 +01:00
|
|
|
description = "List of extra groups that the Buildbot Worker user should be a part of.";
|
|
|
|
};
|
|
|
|
|
|
|
|
home = mkOption {
|
|
|
|
default = "/home/bbworker";
|
|
|
|
type = types.path;
|
|
|
|
description = "Buildbot home directory.";
|
|
|
|
};
|
|
|
|
|
|
|
|
buildbotDir = mkOption {
|
|
|
|
default = "${cfg.home}/worker";
|
|
|
|
type = types.path;
|
|
|
|
description = "Specifies the Buildbot directory.";
|
|
|
|
};
|
|
|
|
|
|
|
|
workerUser = mkOption {
|
|
|
|
default = "example-worker";
|
|
|
|
type = types.str;
|
|
|
|
description = "Specifies the Buildbot Worker user.";
|
|
|
|
};
|
|
|
|
|
|
|
|
workerPass = mkOption {
|
|
|
|
default = "pass";
|
|
|
|
type = types.str;
|
|
|
|
description = "Specifies the Buildbot Worker password.";
|
|
|
|
};
|
|
|
|
|
2017-12-17 05:06:43 +01:00
|
|
|
workerPassFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
description = "File used to store the Buildbot Worker password";
|
|
|
|
};
|
|
|
|
|
|
|
|
hostMessage = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
description = "Description of this worker";
|
|
|
|
};
|
|
|
|
|
|
|
|
adminMessage = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
description = "Name of the administrator of this worker";
|
|
|
|
};
|
|
|
|
|
2017-01-30 18:44:14 +01:00
|
|
|
masterUrl = mkOption {
|
|
|
|
default = "localhost:9989";
|
|
|
|
type = types.str;
|
|
|
|
description = "Specifies the Buildbot Worker connection string.";
|
|
|
|
};
|
|
|
|
|
2020-07-13 19:07:20 +02:00
|
|
|
keepalive = mkOption {
|
|
|
|
default = 600;
|
|
|
|
type = types.int;
|
|
|
|
description = "
|
|
|
|
This is a number that indicates how frequently keepalive messages should be sent
|
|
|
|
from the worker to the buildmaster, expressed in seconds.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
2017-01-30 18:44:14 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2019-02-04 04:56:46 +01:00
|
|
|
default = pkgs.python3Packages.buildbot-worker;
|
|
|
|
defaultText = "pkgs.python3Packages.buildbot-worker";
|
2017-01-30 18:44:14 +01:00
|
|
|
description = "Package to use for buildbot worker.";
|
2019-02-04 04:56:46 +01:00
|
|
|
example = literalExample "pkgs.python2Packages.buildbot-worker";
|
2017-01-30 18:44:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
packages = mkOption {
|
2017-12-17 05:06:43 +01:00
|
|
|
default = with pkgs; [ git ];
|
2017-03-07 14:01:50 +01:00
|
|
|
example = literalExample "[ pkgs.git ]";
|
2017-01-30 18:44:14 +01:00
|
|
|
type = types.listOf types.package;
|
|
|
|
description = "Packages to add to PATH for the buildbot process.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2017-12-17 05:06:43 +01:00
|
|
|
services.buildbot-worker.workerPassFile = mkDefault (pkgs.writeText "buildbot-worker-password" cfg.workerPass);
|
|
|
|
|
2020-01-08 16:05:39 +01:00
|
|
|
users.groups = optionalAttrs (cfg.group == "bbworker") {
|
2019-09-14 19:51:29 +02:00
|
|
|
bbworker = { };
|
2017-01-30 18:44:14 +01:00
|
|
|
};
|
|
|
|
|
2019-09-14 19:51:29 +02:00
|
|
|
users.users = optionalAttrs (cfg.user == "bbworker") {
|
|
|
|
bbworker = {
|
|
|
|
description = "Buildbot Worker User.";
|
|
|
|
isNormalUser = true;
|
|
|
|
createHome = true;
|
|
|
|
home = cfg.home;
|
|
|
|
group = cfg.group;
|
|
|
|
extraGroups = cfg.extraGroups;
|
|
|
|
useDefaultShell = true;
|
|
|
|
};
|
2017-01-30 18:44:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.buildbot-worker = {
|
|
|
|
description = "Buildbot Worker.";
|
2017-02-27 20:02:11 +01:00
|
|
|
after = [ "network.target" "buildbot-master.service" ];
|
2017-01-30 18:44:14 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = cfg.packages;
|
2017-12-17 05:06:43 +01:00
|
|
|
environment.PYTHONPATH = "${python.withPackages (p: [ cfg.package ])}/${python.sitePackages}";
|
2017-01-30 18:44:14 +01:00
|
|
|
|
|
|
|
preStart = ''
|
2017-12-17 05:06:43 +01:00
|
|
|
mkdir -vp "${cfg.buildbotDir}/info"
|
|
|
|
${optionalString (cfg.hostMessage != null) ''
|
|
|
|
ln -sf "${pkgs.writeText "buildbot-worker-host" cfg.hostMessage}" "${cfg.buildbotDir}/info/host"
|
|
|
|
''}
|
|
|
|
${optionalString (cfg.adminMessage != null) ''
|
|
|
|
ln -sf "${pkgs.writeText "buildbot-worker-admin" cfg.adminMessage}" "${cfg.buildbotDir}/info/admin"
|
|
|
|
''}
|
2017-01-30 18:44:14 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
2017-03-10 06:02:49 +01:00
|
|
|
Type = "simple";
|
2017-01-30 18:44:14 +01:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
WorkingDirectory = cfg.home;
|
2017-03-07 20:26:21 +01:00
|
|
|
|
|
|
|
# NOTE: call twistd directly with stdout logging for systemd
|
2017-12-17 05:06:43 +01:00
|
|
|
ExecStart = "${python.pkgs.twisted}/bin/twistd --nodaemon --pidfile= --logfile - --python ${tacFile}";
|
2017-01-30 18:44:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with lib.maintainers; [ nand0p ];
|
|
|
|
|
|
|
|
}
|