1 # NixOS module for Buildbot Worker.
10 cfg = config.services.buildbot-worker;
11 opt = options.services.buildbot-worker;
13 package = pkgs.python3.pkgs.toPythonModule cfg.package;
14 python = package.pythonModule;
16 tacFile = pkgs.writeText "aur-buildbot-worker.tac" ''
20 from buildbot_worker.bot import Worker
21 from twisted.application import service
23 basedir = '${cfg.buildbotDir}'
25 # note: this line is matched against to check that this is a worker
26 # directory; do not edit it.
27 application = service.Application('buildbot-worker')
29 master_url_split = '${cfg.masterUrl}'.split(':')
30 buildmaster_host = master_url_split[0]
31 port = int(master_url_split[1])
32 workername = '${cfg.workerUser}'
34 with open('${cfg.workerPassFile}', 'r', encoding='utf-8') as passwd_file:
35 passwd = passwd_file.read().strip('\r\n')
36 keepalive = ${toString cfg.keepalive}
42 s = Worker(buildmaster_host, port, workername, passwd, basedir,
43 keepalive, umask=umask, maxdelay=maxdelay,
44 numcpus=numcpus, allow_shutdown=allow_shutdown)
45 s.setServiceParent(application)
51 services.buildbot-worker = {
53 enable = lib.mkOption {
54 type = lib.types.bool;
56 description = "Whether to enable the Buildbot Worker.";
62 description = "User the buildbot Worker should execute under.";
65 group = lib.mkOption {
68 description = "Primary group of buildbot Worker user.";
71 extraGroups = lib.mkOption {
72 type = lib.types.listOf lib.types.str;
74 description = "List of extra groups that the Buildbot Worker user should be a part of.";
78 default = "/home/bbworker";
79 type = lib.types.path;
80 description = "Buildbot home directory.";
83 buildbotDir = lib.mkOption {
84 default = "${cfg.home}/worker";
85 defaultText = lib.literalExpression ''"''${config.${opt.home}}/worker"'';
86 type = lib.types.path;
87 description = "Specifies the Buildbot directory.";
90 workerUser = lib.mkOption {
91 default = "example-worker";
93 description = "Specifies the Buildbot Worker user.";
96 workerPass = lib.mkOption {
99 description = "Specifies the Buildbot Worker password.";
102 workerPassFile = lib.mkOption {
103 type = lib.types.path;
104 description = "File used to store the Buildbot Worker password";
107 hostMessage = lib.mkOption {
109 type = lib.types.nullOr lib.types.str;
110 description = "Description of this worker";
113 adminMessage = lib.mkOption {
115 type = lib.types.nullOr lib.types.str;
116 description = "Name of the administrator of this worker";
119 masterUrl = lib.mkOption {
120 default = "localhost:9989";
121 type = lib.types.str;
122 description = "Specifies the Buildbot Worker connection string.";
125 keepalive = lib.mkOption {
127 type = lib.types.int;
129 This is a number that indicates how frequently keepalive messages should be sent
130 from the worker to the buildmaster, expressed in seconds.
134 package = lib.mkPackageOption pkgs "buildbot-worker" { };
136 packages = lib.mkOption {
137 default = with pkgs; [ git ];
138 defaultText = lib.literalExpression "[ pkgs.git ]";
139 type = lib.types.listOf lib.types.package;
140 description = "Packages to add to PATH for the buildbot process.";
145 config = lib.mkIf cfg.enable {
146 services.buildbot-worker.workerPassFile = lib.mkDefault (
147 pkgs.writeText "buildbot-worker-password" cfg.workerPass
150 users.groups = lib.optionalAttrs (cfg.group == "bbworker") {
154 users.users = lib.optionalAttrs (cfg.user == "bbworker") {
156 description = "Buildbot Worker User.";
161 extraGroups = cfg.extraGroups;
162 useDefaultShell = true;
166 systemd.services.buildbot-worker = {
167 description = "Buildbot Worker.";
170 "buildbot-master.service"
172 wantedBy = [ "multi-user.target" ];
174 environment.PYTHONPATH = "${python.withPackages (p: [ package ])}/${python.sitePackages}";
177 mkdir -vp "${cfg.buildbotDir}/info"
178 ${lib.optionalString (cfg.hostMessage != null) ''
179 ln -sf "${pkgs.writeText "buildbot-worker-host" cfg.hostMessage}" "${cfg.buildbotDir}/info/host"
181 ${lib.optionalString (cfg.adminMessage != null) ''
182 ln -sf "${pkgs.writeText "buildbot-worker-admin" cfg.adminMessage}" "${cfg.buildbotDir}/info/admin"
190 WorkingDirectory = cfg.home;
192 # NOTE: call twistd directly with stdout logging for systemd
193 ExecStart = "${python.pkgs.twisted}/bin/twistd --nodaemon --pidfile= --logfile - --python ${tacFile}";
199 meta.maintainers = lib.teams.buildbot.members;