1 # NixOS module for Buildbot Worker.
3 { config, lib, options, pkgs, ... }:
8 cfg = config.services.buildbot-worker;
9 opt = options.services.buildbot-worker;
11 package = pkgs.python3.pkgs.toPythonModule cfg.package;
12 python = package.pythonModule;
14 tacFile = pkgs.writeText "aur-buildbot-worker.tac" ''
18 from buildbot_worker.bot import Worker
19 from twisted.application import service
21 basedir = '${cfg.buildbotDir}'
23 # note: this line is matched against to check that this is a worker
24 # directory; do not edit it.
25 application = service.Application('buildbot-worker')
27 master_url_split = '${cfg.masterUrl}'.split(':')
28 buildmaster_host = master_url_split[0]
29 port = int(master_url_split[1])
30 workername = '${cfg.workerUser}'
32 with open('${cfg.workerPassFile}', 'r', encoding='utf-8') as passwd_file:
33 passwd = passwd_file.read().strip('\r\n')
34 keepalive = ${toString cfg.keepalive}
40 s = Worker(buildmaster_host, port, workername, passwd, basedir,
41 keepalive, umask=umask, maxdelay=maxdelay,
42 numcpus=numcpus, allow_shutdown=allow_shutdown)
43 s.setServiceParent(application)
48 services.buildbot-worker = {
53 description = "Whether to enable the Buildbot Worker.";
59 description = "User the buildbot Worker should execute under.";
65 description = "Primary group of buildbot Worker user.";
68 extraGroups = mkOption {
69 type = types.listOf types.str;
71 description = "List of extra groups that the Buildbot Worker user should be a part of.";
75 default = "/home/bbworker";
77 description = "Buildbot home directory.";
80 buildbotDir = mkOption {
81 default = "${cfg.home}/worker";
82 defaultText = literalExpression ''"''${config.${opt.home}}/worker"'';
84 description = "Specifies the Buildbot directory.";
87 workerUser = mkOption {
88 default = "example-worker";
90 description = "Specifies the Buildbot Worker user.";
93 workerPass = mkOption {
96 description = "Specifies the Buildbot Worker password.";
99 workerPassFile = mkOption {
101 description = "File used to store the Buildbot Worker password";
104 hostMessage = mkOption {
106 type = types.nullOr types.str;
107 description = "Description of this worker";
110 adminMessage = mkOption {
112 type = types.nullOr types.str;
113 description = "Name of the administrator of this worker";
116 masterUrl = mkOption {
117 default = "localhost:9989";
119 description = "Specifies the Buildbot Worker connection string.";
122 keepalive = mkOption {
126 This is a number that indicates how frequently keepalive messages should be sent
127 from the worker to the buildmaster, expressed in seconds.
131 package = mkPackageOption pkgs "buildbot-worker" { };
133 packages = mkOption {
134 default = with pkgs; [ git ];
135 defaultText = literalExpression "[ pkgs.git ]";
136 type = types.listOf types.package;
137 description = "Packages to add to PATH for the buildbot process.";
142 config = mkIf cfg.enable {
143 services.buildbot-worker.workerPassFile = mkDefault (pkgs.writeText "buildbot-worker-password" cfg.workerPass);
145 users.groups = optionalAttrs (cfg.group == "bbworker") {
149 users.users = optionalAttrs (cfg.user == "bbworker") {
151 description = "Buildbot Worker User.";
156 extraGroups = cfg.extraGroups;
157 useDefaultShell = true;
161 systemd.services.buildbot-worker = {
162 description = "Buildbot Worker.";
163 after = [ "network.target" "buildbot-master.service" ];
164 wantedBy = [ "multi-user.target" ];
166 environment.PYTHONPATH = "${python.withPackages (p: [ package ])}/${python.sitePackages}";
169 mkdir -vp "${cfg.buildbotDir}/info"
170 ${optionalString (cfg.hostMessage != null) ''
171 ln -sf "${pkgs.writeText "buildbot-worker-host" cfg.hostMessage}" "${cfg.buildbotDir}/info/host"
173 ${optionalString (cfg.adminMessage != null) ''
174 ln -sf "${pkgs.writeText "buildbot-worker-admin" cfg.adminMessage}" "${cfg.buildbotDir}/info/admin"
182 WorkingDirectory = cfg.home;
184 # NOTE: call twistd directly with stdout logging for systemd
185 ExecStart = "${python.pkgs.twisted}/bin/twistd --nodaemon --pidfile= --logfile - --python ${tacFile}";
191 meta.maintainers = lib.teams.buildbot.members;