1 { lib, pkgs, config, ... }:
3 varDir = "/var/lib/buildbot";
4 buildbot_common = pkgs.python3Packages.buildPythonPackage rec {
5 name = "buildbot_common";
9 mkdir -p $out/${pkgs.python3.pythonForBuild.sitePackages}
10 cp -a $src $out/${pkgs.python3.pythonForBuild.sitePackages}/buildbot_common
13 buildbot = pkgs.python3Packages.buildbot-full;
17 myServices.buildbot.enable = lib.mkOption {
18 type = lib.types.bool;
21 Whether to enable buildbot.
26 config = lib.mkIf config.myServices.buildbot.enable {
27 services.duplyBackup.profiles.buildbot = {
30 ids.uids.buildbot = config.myEnv.buildbot.user.uid;
31 ids.gids.buildbot = config.myEnv.buildbot.user.gid;
33 users.groups.buildbot.gid = config.ids.gids.buildbot;
34 users.users.buildbot = {
36 uid = config.ids.uids.buildbot;
38 description = "Buildbot user";
40 extraGroups = [ "keys" ];
43 services.websites.env.tools.watchPaths = lib.attrsets.mapAttrsToList
44 (k: project: "/var/secrets/buildbot/${project.name}/webhook-httpd-include")
45 config.myEnv.buildbot.projects;
47 services.websites.env.tools.vhostConfs.git.extraConfig = lib.attrsets.mapAttrsToList (k: project: ''
48 RedirectMatch permanent "^/buildbot/${project.name}$" "/buildbot/${project.name}/"
50 RewriteRule ^/buildbot/${project.name}/ws(.*)$ unix:///run/buildbot/${project.name}.sock|ws://git.immae.eu/ws$1 [P,NE,QSA,L]
51 ProxyPass /buildbot/${project.name}/ unix:///run/buildbot/${project.name}.sock|http://${project.name}-git.immae.eu/
52 ProxyPassReverse /buildbot/${project.name}/ unix:///run/buildbot/${project.name}.sock|http://${project.name}-git.immae.eu/
53 <Location /buildbot/${project.name}/>
55 Require ldap-group cn=users,ou=${project.name},cn=buildbot,ou=services,dc=immae,dc=eu
57 SetEnvIf X-Url-Scheme https HTTPS=1
60 <Location /buildbot/${project.name}/change_hook/base>
63 Require ldap-group cn=users,ou=${project.name},cn=buildbot,ou=services,dc=immae,dc=eu
64 Include /var/secrets/buildbot/${project.name}/webhook-httpd-include
67 '') config.myEnv.buildbot.projects;
69 system.activationScripts = lib.attrsets.mapAttrs' (k: project: lib.attrsets.nameValuePair "buildbot-${project.name}" {
70 deps = [ "users" "wrappers" ];
72 install -m 755 -o buildbot -g buildbot -d ${varDir}/${project.name}
74 ${project.activationScript}
76 }) config.myEnv.buildbot.projects;
80 lib.attrsets.mapAttrsToList (k: project:
81 lib.attrsets.mapAttrsToList (k: v:
87 dest = "buildbot/${project.name}/${k}";
95 text = lib.optionalString (project.webhookTokens != null) ''
96 Require expr "req('Access-Key') in { ${builtins.concatStringsSep ", " (map (x: "'${x}'") project.webhookTokens)} }"
98 dest = "buildbot/${project.name}/webhook-httpd-include";
101 ) config.myEnv.buildbot.projects
105 permissions = "0600";
108 text = config.myEnv.buildbot.ldap.password;
109 dest = "buildbot/ldap";
112 permissions = "0600";
115 text = builtins.readFile "${config.myEnv.privateFiles}/buildbot_ssh_key";
116 dest = "buildbot/ssh_key";
120 services.filesWatcher = lib.attrsets.mapAttrs' (k: project: lib.attrsets.nameValuePair "buildbot-${project.name}" {
123 "/var/secrets/buildbot/ldap"
124 "/var/secrets/buildbot/ssh_key"
125 ] ++ lib.attrsets.mapAttrsToList (k: v: "/var/secrets/buildbot/${project.name}/${k}") project.secrets;
126 }) config.myEnv.buildbot.projects;
128 systemd.services = lib.attrsets.mapAttrs' (k: project: lib.attrsets.nameValuePair "buildbot-${project.name}" {
129 description = "Buildbot Continuous Integration Server ${project.name}.";
130 after = [ "network-online.target" ];
131 wantedBy = [ "multi-user.target" ];
132 path = project.packages pkgs ++ (project.pythonPackages buildbot.pythonModule pkgs);
134 master-cfg = "${buildbot_common}/${pkgs.python3.pythonForBuild.sitePackages}/buildbot_common/master.cfg";
135 tac_file = pkgs.writeText "buildbot.tac" ''
138 from twisted.application import service
139 from buildbot.master import BuildMaster
141 basedir = '${varDir}/${project.name}'
142 rotateLength = 10000000
144 configfile = '${master-cfg}'
146 # Default umask for server
149 # if this is a relocatable tac file, get the directory containing the TAC
152 basedir = os.path.abspath(os.path.dirname(__file__))
154 # note: this line is matched against to check that this is a buildmaster
155 # directory; do not edit it.
156 application = service.Application('buildmaster')
157 from twisted.python.logfile import LogFile
158 from twisted.python.log import ILogObserver, FileLogObserver
159 logfile = LogFile.fromFullPath(os.path.join(basedir, "twistd.log"), rotateLength=rotateLength,
160 maxRotatedFiles=maxRotatedFiles)
161 application.setComponent(ILogObserver, FileLogObserver(logfile).emit)
163 m = BuildMaster(basedir, configfile, umask)
164 m.setServiceParent(application)
165 m.log_rotation.rotateLength = rotateLength
166 m.log_rotation.maxRotatedFiles = maxRotatedFiles
169 if [ ! -f ${varDir}/${project.name}/buildbot.tac ]; then
170 ${buildbot}/bin/buildbot create-master -c "${master-cfg}" "${varDir}/${project.name}"
171 rm -f ${varDir}/${project.name}/master.cfg.sample
172 rm -f ${varDir}/${project.name}/buildbot.tac
174 ln -sf ${tac_file} ${varDir}/${project.name}/buildbot.tac
175 # different buildbots may be trying that simultaneously, add the || true to avoid complaining in case of race
176 install -Dm600 -o buildbot -g buildbot -T /var/secrets/buildbot/ssh_key ${varDir}/buildbot_key || true
177 buildbot_secrets=${varDir}/${project.name}/secrets
178 install -m 0700 -o buildbot -g buildbot -d $buildbot_secrets
179 install -Dm600 -o buildbot -g buildbot -T /var/secrets/buildbot/ldap $buildbot_secrets/ldap
180 ${builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList
181 (k: v: "install -Dm600 -o buildbot -g buildbot -T /var/secrets/buildbot/${project.name}/${k} $buildbot_secrets/${k}") project.secrets
185 project_env = with lib.attrsets;
186 mapAttrs' (k: v: nameValuePair "BUILDBOT_${k}" v) project.environment //
187 mapAttrs' (k: v: nameValuePair "BUILDBOT_PATH_${k}" (v pkgs)) (attrByPath ["builderPaths"] {} project);
188 buildbot_config = pkgs.python3Packages.buildPythonPackage (rec {
189 name = "buildbot_config-${project.name}";
190 src = ./projects + "/${project.name}";
193 mkdir -p $out/${pkgs.python3.pythonForBuild.sitePackages}
194 cp -a $src $out/${pkgs.python3.pythonForBuild.sitePackages}/buildbot_config
197 HOME = "${varDir}/${project.name}";
198 PYTHONPATH = "${buildbot.pythonModule.withPackages (self: project.pythonPackages self pkgs ++ [
199 pkgs.python3Packages.wokkel
200 pkgs.python3Packages.treq pkgs.python3Packages.ldap3 buildbot
201 pkgs.python3Packages.buildbot-worker
202 buildbot_common buildbot_config
203 ])}/${buildbot.pythonModule.sitePackages}${if project.pythonPathHome then ":${varDir}/${project.name}/.local/${pkgs.python3.pythonForBuild.sitePackages}" else ""}";
204 in project_env // { inherit PYTHONPATH HOME; };
210 RuntimeDirectory = "buildbot";
211 RuntimeDirectoryPreserve = "yes";
212 StateDirectory = "buildbot";
213 SupplementaryGroups = "keys";
214 WorkingDirectory = "${varDir}/${project.name}";
215 ExecStart = "${buildbot}/bin/buildbot start";
217 }) config.myEnv.buildbot.projects;