]>
Commit | Line | Data |
---|---|---|
587b9e34 | 1 | { lib, pkgs, config, myconfig, mylibs, ... }: |
9fb4205e IB |
2 | let |
3 | varDir = "/var/lib/buildbot"; | |
4 | buildslist_src = mylibs.fetchedGitPrivate ./buildslist.json; | |
33aa7e5c | 5 | buildslist_yarn = mylibs.yarn2nixPackage.mkYarnModules rec { |
9fb4205e | 6 | name = "buildslist-yarn-modules"; |
33aa7e5c IB |
7 | pname = name; |
8 | inherit (pkgs.buildbot-pkg) version; | |
9fb4205e IB |
9 | packageJSON = "${buildslist_src.src}/package.json"; |
10 | yarnLock = "${buildslist_src.src}/yarn.lock"; | |
167b8165 IB |
11 | pkgConfig = { |
12 | all = { buildInputs = [ mylibs.yarn2nixPackage.src ]; }; | |
13 | }; | |
9fb4205e | 14 | }; |
caa08508 | 15 | buildslist_bower = pkgs.buildBowerComponents { |
9fb4205e IB |
16 | name = "buildslist"; |
17 | generated = ./bower.nix; | |
18 | src = "${buildslist_src.src}/guanlecoja/"; | |
19 | }; | |
20 | ||
caa08508 | 21 | buildslist = pkgs.python3Packages.buildPythonPackage rec { |
9fb4205e | 22 | pname = "buildbot-buildslist"; |
caa08508 | 23 | inherit (pkgs.buildbot-pkg) version; |
9fb4205e IB |
24 | |
25 | preConfigure = '' | |
26 | export HOME=$PWD | |
27 | cp -a ${buildslist_yarn}/node_modules . | |
28 | chmod -R u+w node_modules | |
29 | cp -a ${buildslist_bower}/bower_components ./libs | |
30 | chmod -R u+w libs | |
31 | ''; | |
caa08508 | 32 | propagatedBuildInputs = with pkgs.python3Packages; [ |
9fb4205e IB |
33 | (klein.overridePythonAttrs(old: { checkPhase = ""; })) |
34 | buildbot-pkg | |
35 | ]; | |
caa08508 | 36 | nativeBuildInputs = with pkgs; [ yarn nodejs ]; |
9fb4205e IB |
37 | buildInputs = [ buildslist_yarn buildslist_bower ]; |
38 | ||
39 | doCheck = false; | |
40 | src = buildslist_src.src; | |
41 | }; | |
caa08508 | 42 | buildbot_common = pkgs.python3Packages.buildPythonPackage rec { |
e2b96bf5 IB |
43 | name = "buildbot_common"; |
44 | src = ./common; | |
9fb4205e IB |
45 | format = "other"; |
46 | installPhase = '' | |
caa08508 IB |
47 | mkdir -p $out/${pkgs.python3.pythonForBuild.sitePackages} |
48 | cp -a $src $out/${pkgs.python3.pythonForBuild.sitePackages}/buildbot_common | |
9fb4205e | 49 | ''; |
e2b96bf5 | 50 | }; |
caa08508 | 51 | buildbot = pkgs.python3Packages.buildbot-full.withPlugins ([ buildslist ]); |
9fb4205e IB |
52 | in |
53 | { | |
54 | options = { | |
55 | services.buildbot.enable = lib.mkOption { | |
56 | type = lib.types.bool; | |
57 | default = false; | |
58 | description = '' | |
59 | Whether to enable buildbot. | |
60 | ''; | |
61 | }; | |
62 | }; | |
63 | ||
64 | config = lib.mkIf config.services.buildbot.enable { | |
256d607c IB |
65 | nixpkgs.overlays = [ (self: super: rec { |
66 | python3 = super.python3.override { | |
67 | packageOverrides = python-self: python-super: { | |
68 | wokkel = python-self.buildPythonPackage rec { | |
69 | pname = "wokkel"; | |
70 | version = "18.0.0"; | |
71 | src = python-self.fetchPypi { | |
72 | inherit pname version; | |
73 | sha256 = "1spq44gg8gsviqx1dvlmjpgfc0wk0jpyx4ap01y2pad1ai9cw016"; | |
74 | }; | |
75 | propagatedBuildInputs = with python-self; [ twisted.extras.tls twisted incremental dateutil ]; | |
76 | doChecks = false; | |
77 | }; | |
78 | apprise = python-self.buildPythonPackage rec { | |
79 | pname = "apprise"; | |
80 | version = "0.7.4"; | |
81 | src = (mylibs.fetchedGithub ./apprise.json).src; | |
82 | propagatedBuildInputs = with python-self; [ decorator | |
83 | requests requests_oauthlib oauthlib urllib3 six click | |
84 | markdown pyyaml sleekxmpp | |
85 | ]; | |
86 | doChecks = false; | |
87 | }; | |
88 | }; | |
89 | }; | |
90 | }) ]; | |
91 | ||
9fb4205e IB |
92 | ids.uids.buildbot = myconfig.env.buildbot.user.uid; |
93 | ids.gids.buildbot = myconfig.env.buildbot.user.gid; | |
94 | ||
95 | users.groups.buildbot.gid = config.ids.gids.buildbot; | |
96 | users.users.buildbot = { | |
97 | name = "buildbot"; | |
98 | uid = config.ids.uids.buildbot; | |
99 | group = "buildbot"; | |
100 | description = "Buildbot user"; | |
101 | home = varDir; | |
6984f454 | 102 | extraGroups = [ "keys" ]; |
9fb4205e IB |
103 | }; |
104 | ||
105 | services.myWebsites.tools.vhostConfs.git.extraConfig = lib.attrsets.mapAttrsToList (k: project: '' | |
106 | RedirectMatch permanent "^/buildbot/${project.name}$" "/buildbot/${project.name}/" | |
107 | RewriteEngine On | |
108 | RewriteRule ^/buildbot/${project.name}/ws(.*)$ unix:///run/buildbot/${project.name}.sock|ws://git.immae.eu/ws$1 [P,NE,QSA,L] | |
109 | ProxyPass /buildbot/${project.name}/ unix:///run/buildbot/${project.name}.sock|http://${project.name}-git.immae.eu/ | |
110 | ProxyPassReverse /buildbot/${project.name}/ unix:///run/buildbot/${project.name}.sock|http://${project.name}-git.immae.eu/ | |
111 | <Location /buildbot/${project.name}/> | |
112 | Use LDAPConnect | |
e2b96bf5 | 113 | Require ldap-group cn=users,ou=${project.name},cn=buildbot,ou=services,dc=immae,dc=eu |
9fb4205e IB |
114 | |
115 | SetEnvIf X-Url-Scheme https HTTPS=1 | |
116 | ProxyPreserveHost On | |
117 | </Location> | |
118 | <Location /buildbot/${project.name}/change_hook/base> | |
85817848 IB |
119 | <RequireAny> |
120 | Require local | |
121 | Require ldap-group cn=users,ou=${project.name},cn=buildbot,ou=services,dc=immae,dc=eu | |
ca330baa | 122 | Include /var/secrets/buildbot/${project.name}/webhook-httpd-include |
85817848 | 123 | </RequireAny> |
9fb4205e IB |
124 | </Location> |
125 | '') myconfig.env.buildbot.projects; | |
126 | ||
127 | system.activationScripts = lib.attrsets.mapAttrs' (k: project: lib.attrsets.nameValuePair "buildbot-${project.name}" { | |
128 | deps = [ "users" "wrappers" ]; | |
6984f454 IB |
129 | text = '' |
130 | install -m 0755 -o buildbot -g buildbot -d /run/buildbot/ | |
131 | install -m 0755 -o buildbot -g buildbot -d ${varDir} | |
132 | ${project.activationScript} | |
133 | ''; | |
134 | }) myconfig.env.buildbot.projects; | |
135 | ||
ca330baa | 136 | mySecrets.keys = ( |
6984f454 IB |
137 | lib.lists.flatten ( |
138 | lib.attrsets.mapAttrsToList (k: project: | |
139 | lib.attrsets.mapAttrsToList (k: v: | |
ca330baa | 140 | { |
6984f454 IB |
141 | permissions = "0600"; |
142 | user = "buildbot"; | |
143 | group = "buildbot"; | |
144 | text = v; | |
ca330baa | 145 | dest = "buildbot/${project.name}/${k}"; |
6984f454 IB |
146 | } |
147 | ) project.secrets | |
148 | ++ [ | |
ca330baa | 149 | { |
6984f454 IB |
150 | permissions = "0600"; |
151 | user = "wwwrun"; | |
152 | group = "wwwrun"; | |
153 | text = lib.optionalString (lib.attrsets.hasAttr "webhookTokens" project) '' | |
154 | Require expr "req('Access-Key') in { ${builtins.concatStringsSep ", " (map (x: "'${x}'") project.webhookTokens)} }" | |
155 | ''; | |
ca330baa IB |
156 | dest = "buildbot/${project.name}/webhook-httpd-include"; |
157 | } | |
6984f454 IB |
158 | ] |
159 | ) myconfig.env.buildbot.projects | |
160 | ) | |
ca330baa IB |
161 | ) ++ [ |
162 | { | |
6984f454 IB |
163 | permissions = "0600"; |
164 | user = "buildbot"; | |
165 | group = "buildbot"; | |
166 | text = myconfig.env.buildbot.ldap.password; | |
ca330baa IB |
167 | dest = "buildbot/ldap"; |
168 | } | |
169 | { | |
6984f454 IB |
170 | permissions = "0600"; |
171 | user = "buildbot"; | |
172 | group = "buildbot"; | |
173 | text = builtins.readFile "${myconfig.privateFiles}/buildbot_ssh_key"; | |
ca330baa IB |
174 | dest = "buildbot/ssh_key"; |
175 | } | |
176 | ]; | |
6984f454 IB |
177 | |
178 | systemd.services = lib.attrsets.mapAttrs' (k: project: lib.attrsets.nameValuePair "buildbot-${project.name}" { | |
179 | description = "Buildbot Continuous Integration Server ${project.name}."; | |
ca330baa | 180 | after = [ "network-online.target" ]; |
6984f454 IB |
181 | wantedBy = [ "multi-user.target" ]; |
182 | path = project.packages pkgs ++ (project.pythonPackages buildbot.pythonModule pkgs); | |
183 | preStart = let | |
caa08508 | 184 | master-cfg = "${buildbot_common}/${pkgs.python3.pythonForBuild.sitePackages}/buildbot_common/master.cfg"; |
e2b96bf5 IB |
185 | tac_file = pkgs.writeText "buildbot.tac" '' |
186 | import os | |
187 | ||
188 | from twisted.application import service | |
189 | from buildbot.master import BuildMaster | |
190 | ||
191 | basedir = '${varDir}/${project.name}' | |
192 | rotateLength = 10000000 | |
193 | maxRotatedFiles = 10 | |
194 | configfile = '${master-cfg}' | |
195 | ||
196 | # Default umask for server | |
197 | umask = None | |
198 | ||
199 | # if this is a relocatable tac file, get the directory containing the TAC | |
200 | if basedir == '.': | |
201 | import os | |
202 | basedir = os.path.abspath(os.path.dirname(__file__)) | |
203 | ||
204 | # note: this line is matched against to check that this is a buildmaster | |
205 | # directory; do not edit it. | |
206 | application = service.Application('buildmaster') | |
207 | from twisted.python.logfile import LogFile | |
208 | from twisted.python.log import ILogObserver, FileLogObserver | |
209 | logfile = LogFile.fromFullPath(os.path.join(basedir, "twistd.log"), rotateLength=rotateLength, | |
210 | maxRotatedFiles=maxRotatedFiles) | |
211 | application.setComponent(ILogObserver, FileLogObserver(logfile).emit) | |
212 | ||
213 | m = BuildMaster(basedir, configfile, umask) | |
214 | m.setServiceParent(application) | |
215 | m.log_rotation.rotateLength = rotateLength | |
216 | m.log_rotation.maxRotatedFiles = maxRotatedFiles | |
217 | ''; | |
9fb4205e | 218 | in '' |
9fb4205e | 219 | if [ ! -f ${varDir}/${project.name}/buildbot.tac ]; then |
6984f454 | 220 | ${buildbot}/bin/buildbot create-master -c "${master-cfg}" "${varDir}/${project.name}" |
9fb4205e | 221 | rm -f ${varDir}/${project.name}/master.cfg.sample |
e2b96bf5 | 222 | rm -f ${varDir}/${project.name}/buildbot.tac |
9fb4205e | 223 | fi |
e2b96bf5 | 224 | ln -sf ${tac_file} ${varDir}/${project.name}/buildbot.tac |
ca330baa IB |
225 | # different buildbots may be trying that simultaneously, add the || true to avoid complaining in case of race |
226 | install -Dm600 -o buildbot -g buildbot -T /var/secrets/buildbot/ssh_key ${varDir}/buildbot_key || true | |
9fb4205e | 227 | buildbot_secrets=${varDir}/${project.name}/secrets |
6984f454 | 228 | install -m 0700 -o buildbot -g buildbot -d $buildbot_secrets |
ca330baa | 229 | install -Dm600 -o buildbot -g buildbot -T /var/secrets/buildbot/ldap $buildbot_secrets/ldap |
9fb4205e | 230 | ${builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList |
ca330baa | 231 | (k: v: "install -Dm600 -o buildbot -g buildbot -T /var/secrets/buildbot/${project.name}/${k} $buildbot_secrets/${k}") project.secrets |
9fb4205e | 232 | )} |
9fb4205e | 233 | ''; |
9fb4205e IB |
234 | environment = let |
235 | project_env = lib.attrsets.mapAttrs' (k: v: lib.attrsets.nameValuePair "BUILDBOT_${k}" v) project.environment; | |
caa08508 | 236 | buildbot_config = pkgs.python3Packages.buildPythonPackage (rec { |
9fb4205e | 237 | name = "buildbot_config-${project.name}"; |
e2b96bf5 | 238 | src = ./projects + "/${project.name}"; |
9fb4205e IB |
239 | format = "other"; |
240 | installPhase = '' | |
caa08508 IB |
241 | mkdir -p $out/${pkgs.python3.pythonForBuild.sitePackages} |
242 | cp -a $src $out/${pkgs.python3.pythonForBuild.sitePackages}/buildbot_config | |
9fb4205e IB |
243 | ''; |
244 | }); | |
245 | HOME = "${varDir}/${project.name}"; | |
caa08508 | 246 | PYTHONPATH = "${buildbot.pythonModule.withPackages (self: project.pythonPackages self pkgs ++ [ |
256d607c | 247 | pkgs.python3Packages.wokkel |
caa08508 IB |
248 | pkgs.python3Packages.treq pkgs.python3Packages.ldap3 buildbot |
249 | pkgs.python3Packages.buildbot-worker | |
9fb4205e | 250 | buildbot_common buildbot_config |
caa08508 | 251 | ])}/${buildbot.pythonModule.sitePackages}${if project.pythonPathHome then ":${varDir}/${project.name}/.local/${pkgs.python3.pythonForBuild.sitePackages}" else ""}"; |
9fb4205e IB |
252 | in project_env // { inherit PYTHONPATH HOME; }; |
253 | ||
254 | serviceConfig = { | |
255 | Type = "forking"; | |
256 | User = "buildbot"; | |
257 | Group = "buildbot"; | |
6984f454 | 258 | SupplementaryGroups = "keys"; |
9fb4205e IB |
259 | WorkingDirectory = "${varDir}/${project.name}"; |
260 | ExecStart = "${buildbot}/bin/buildbot start"; | |
261 | }; | |
262 | }) myconfig.env.buildbot.projects; | |
263 | }; | |
264 | } |