1 { lib, pkgs, config, myconfig, mylibs, ... }:
3 varDir = "/var/lib/buildbot";
4 buildslist_src = mylibs.fetchedGitPrivate ./buildslist.json;
5 buildslist_yarn = mylibs.yarn2nixPackage.mkYarnModules rec {
6 name = "buildslist-yarn-modules";
8 inherit (pkgs.buildbot-pkg) version;
9 packageJSON = "${buildslist_src.src}/package.json";
10 yarnLock = "${buildslist_src.src}/yarn.lock";
12 all = { buildInputs = [ mylibs.yarn2nixPackage.src ]; };
15 buildslist_bower = pkgs.buildBowerComponents {
17 generated = ./bower.nix;
18 src = "${buildslist_src.src}/guanlecoja/";
21 buildslist = pkgs.python3Packages.buildPythonPackage rec {
22 pname = "buildbot-buildslist";
23 inherit (pkgs.buildbot-pkg) version;
27 cp -a ${buildslist_yarn}/node_modules .
28 chmod -R u+w node_modules
29 cp -a ${buildslist_bower}/bower_components ./libs
32 propagatedBuildInputs = with pkgs.python3Packages; [
33 (klein.overridePythonAttrs(old: { checkPhase = ""; }))
36 nativeBuildInputs = with pkgs; [ yarn nodejs ];
37 buildInputs = [ buildslist_yarn buildslist_bower ];
40 src = buildslist_src.src;
42 buildbot_common = pkgs.python3Packages.buildPythonPackage rec {
43 name = "buildbot_common";
47 mkdir -p $out/${pkgs.python3.pythonForBuild.sitePackages}
48 cp -a $src $out/${pkgs.python3.pythonForBuild.sitePackages}/buildbot_common
51 buildbot = pkgs.python3Packages.buildbot-full.withPlugins ([ buildslist ]);
55 services.buildbot.enable = lib.mkOption {
56 type = lib.types.bool;
59 Whether to enable buildbot.
64 config = lib.mkIf config.services.buildbot.enable {
65 ids.uids.buildbot = myconfig.env.buildbot.user.uid;
66 ids.gids.buildbot = myconfig.env.buildbot.user.gid;
68 users.groups.buildbot.gid = config.ids.gids.buildbot;
69 users.users.buildbot = {
71 uid = config.ids.uids.buildbot;
73 description = "Buildbot user";
75 extraGroups = [ "keys" ];
78 services.myWebsites.tools.vhostConfs.git.extraConfig = lib.attrsets.mapAttrsToList (k: project: ''
79 RedirectMatch permanent "^/buildbot/${project.name}$" "/buildbot/${project.name}/"
81 RewriteRule ^/buildbot/${project.name}/ws(.*)$ unix:///run/buildbot/${project.name}.sock|ws://git.immae.eu/ws$1 [P,NE,QSA,L]
82 ProxyPass /buildbot/${project.name}/ unix:///run/buildbot/${project.name}.sock|http://${project.name}-git.immae.eu/
83 ProxyPassReverse /buildbot/${project.name}/ unix:///run/buildbot/${project.name}.sock|http://${project.name}-git.immae.eu/
84 <Location /buildbot/${project.name}/>
86 Require ldap-group cn=users,ou=${project.name},cn=buildbot,ou=services,dc=immae,dc=eu
88 SetEnvIf X-Url-Scheme https HTTPS=1
91 <Location /buildbot/${project.name}/change_hook/base>
94 Require ldap-group cn=users,ou=${project.name},cn=buildbot,ou=services,dc=immae,dc=eu
95 Include /var/secrets/buildbot/${project.name}/webhook-httpd-include
98 '') myconfig.env.buildbot.projects;
100 system.activationScripts = lib.attrsets.mapAttrs' (k: project: lib.attrsets.nameValuePair "buildbot-${project.name}" {
101 deps = [ "users" "wrappers" ];
103 install -m 0755 -o buildbot -g buildbot -d /run/buildbot/
104 install -m 0755 -o buildbot -g buildbot -d ${varDir}
105 ${project.activationScript}
107 }) myconfig.env.buildbot.projects;
111 lib.attrsets.mapAttrsToList (k: project:
112 lib.attrsets.mapAttrsToList (k: v:
114 permissions = "0600";
118 dest = "buildbot/${project.name}/${k}";
123 permissions = "0600";
126 text = lib.optionalString (lib.attrsets.hasAttr "webhookTokens" project) ''
127 Require expr "req('Access-Key') in { ${builtins.concatStringsSep ", " (map (x: "'${x}'") project.webhookTokens)} }"
129 dest = "buildbot/${project.name}/webhook-httpd-include";
132 ) myconfig.env.buildbot.projects
136 permissions = "0600";
139 text = myconfig.env.buildbot.ldap.password;
140 dest = "buildbot/ldap";
143 permissions = "0600";
146 text = builtins.readFile "${myconfig.privateFiles}/buildbot_ssh_key";
147 dest = "buildbot/ssh_key";
151 systemd.services = lib.attrsets.mapAttrs' (k: project: lib.attrsets.nameValuePair "buildbot-${project.name}" {
152 description = "Buildbot Continuous Integration Server ${project.name}.";
153 after = [ "network-online.target" ];
154 wantedBy = [ "multi-user.target" ];
155 path = project.packages pkgs ++ (project.pythonPackages buildbot.pythonModule pkgs);
157 master-cfg = "${buildbot_common}/${pkgs.python3.pythonForBuild.sitePackages}/buildbot_common/master.cfg";
158 tac_file = pkgs.writeText "buildbot.tac" ''
161 from twisted.application import service
162 from buildbot.master import BuildMaster
164 basedir = '${varDir}/${project.name}'
165 rotateLength = 10000000
167 configfile = '${master-cfg}'
169 # Default umask for server
172 # if this is a relocatable tac file, get the directory containing the TAC
175 basedir = os.path.abspath(os.path.dirname(__file__))
177 # note: this line is matched against to check that this is a buildmaster
178 # directory; do not edit it.
179 application = service.Application('buildmaster')
180 from twisted.python.logfile import LogFile
181 from twisted.python.log import ILogObserver, FileLogObserver
182 logfile = LogFile.fromFullPath(os.path.join(basedir, "twistd.log"), rotateLength=rotateLength,
183 maxRotatedFiles=maxRotatedFiles)
184 application.setComponent(ILogObserver, FileLogObserver(logfile).emit)
186 m = BuildMaster(basedir, configfile, umask)
187 m.setServiceParent(application)
188 m.log_rotation.rotateLength = rotateLength
189 m.log_rotation.maxRotatedFiles = maxRotatedFiles
192 if [ ! -f ${varDir}/${project.name}/buildbot.tac ]; then
193 ${buildbot}/bin/buildbot create-master -c "${master-cfg}" "${varDir}/${project.name}"
194 rm -f ${varDir}/${project.name}/master.cfg.sample
195 rm -f ${varDir}/${project.name}/buildbot.tac
197 ln -sf ${tac_file} ${varDir}/${project.name}/buildbot.tac
198 # different buildbots may be trying that simultaneously, add the || true to avoid complaining in case of race
199 install -Dm600 -o buildbot -g buildbot -T /var/secrets/buildbot/ssh_key ${varDir}/buildbot_key || true
200 buildbot_secrets=${varDir}/${project.name}/secrets
201 install -m 0700 -o buildbot -g buildbot -d $buildbot_secrets
202 install -Dm600 -o buildbot -g buildbot -T /var/secrets/buildbot/ldap $buildbot_secrets/ldap
203 ${builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList
204 (k: v: "install -Dm600 -o buildbot -g buildbot -T /var/secrets/buildbot/${project.name}/${k} $buildbot_secrets/${k}") project.secrets
208 project_env = lib.attrsets.mapAttrs' (k: v: lib.attrsets.nameValuePair "BUILDBOT_${k}" v) project.environment;
209 buildbot_config = pkgs.python3Packages.buildPythonPackage (rec {
210 name = "buildbot_config-${project.name}";
211 src = ./projects + "/${project.name}";
214 mkdir -p $out/${pkgs.python3.pythonForBuild.sitePackages}
215 cp -a $src $out/${pkgs.python3.pythonForBuild.sitePackages}/buildbot_config
218 HOME = "${varDir}/${project.name}";
219 PYTHONPATH = "${buildbot.pythonModule.withPackages (self: project.pythonPackages self pkgs ++ [
220 pkgs.python3Packages.wokkel
221 pkgs.python3Packages.treq pkgs.python3Packages.ldap3 buildbot
222 pkgs.python3Packages.buildbot-worker
223 buildbot_common buildbot_config
224 ])}/${buildbot.pythonModule.sitePackages}${if project.pythonPathHome then ":${varDir}/${project.name}/.local/${pkgs.python3.pythonForBuild.sitePackages}" else ""}";
225 in project_env // { inherit PYTHONPATH HOME; };
231 SupplementaryGroups = "keys";
232 WorkingDirectory = "${varDir}/${project.name}";
233 ExecStart = "${buildbot}/bin/buildbot start";
235 }) myconfig.env.buildbot.projects;