]>
Commit | Line | Data |
---|---|---|
a1a8649a | 1 | { lib, pkgs, config, myconfig, ... }: |
9fb4205e IB |
2 | let |
3 | varDir = "/var/lib/buildbot"; | |
caa08508 | 4 | buildbot_common = pkgs.python3Packages.buildPythonPackage rec { |
e2b96bf5 IB |
5 | name = "buildbot_common"; |
6 | src = ./common; | |
9fb4205e IB |
7 | format = "other"; |
8 | installPhase = '' | |
caa08508 IB |
9 | mkdir -p $out/${pkgs.python3.pythonForBuild.sitePackages} |
10 | cp -a $src $out/${pkgs.python3.pythonForBuild.sitePackages}/buildbot_common | |
9fb4205e | 11 | ''; |
e2b96bf5 | 12 | }; |
b798cf6d | 13 | buildbot = pkgs.python3Packages.buildbot-full; |
9fb4205e IB |
14 | in |
15 | { | |
16 | options = { | |
8d213e2b | 17 | myServices.buildbot.enable = lib.mkOption { |
9fb4205e IB |
18 | type = lib.types.bool; |
19 | default = false; | |
20 | description = '' | |
21 | Whether to enable buildbot. | |
22 | ''; | |
23 | }; | |
24 | }; | |
25 | ||
8d213e2b | 26 | config = lib.mkIf config.myServices.buildbot.enable { |
9fb4205e IB |
27 | ids.uids.buildbot = myconfig.env.buildbot.user.uid; |
28 | ids.gids.buildbot = myconfig.env.buildbot.user.gid; | |
29 | ||
30 | users.groups.buildbot.gid = config.ids.gids.buildbot; | |
31 | users.users.buildbot = { | |
32 | name = "buildbot"; | |
33 | uid = config.ids.uids.buildbot; | |
34 | group = "buildbot"; | |
35 | description = "Buildbot user"; | |
36 | home = varDir; | |
6984f454 | 37 | extraGroups = [ "keys" ]; |
9fb4205e IB |
38 | }; |
39 | ||
29f8cb85 | 40 | services.websites.env.tools.watchPaths = lib.attrsets.mapAttrsToList |
17f6eae9 IB |
41 | (k: project: "/var/secrets/buildbot/${project.name}/webhook-httpd-include") |
42 | myconfig.env.buildbot.projects; | |
43 | ||
29f8cb85 | 44 | services.websites.env.tools.vhostConfs.git.extraConfig = lib.attrsets.mapAttrsToList (k: project: '' |
9fb4205e IB |
45 | RedirectMatch permanent "^/buildbot/${project.name}$" "/buildbot/${project.name}/" |
46 | RewriteEngine On | |
47 | RewriteRule ^/buildbot/${project.name}/ws(.*)$ unix:///run/buildbot/${project.name}.sock|ws://git.immae.eu/ws$1 [P,NE,QSA,L] | |
48 | ProxyPass /buildbot/${project.name}/ unix:///run/buildbot/${project.name}.sock|http://${project.name}-git.immae.eu/ | |
49 | ProxyPassReverse /buildbot/${project.name}/ unix:///run/buildbot/${project.name}.sock|http://${project.name}-git.immae.eu/ | |
50 | <Location /buildbot/${project.name}/> | |
51 | Use LDAPConnect | |
e2b96bf5 | 52 | Require ldap-group cn=users,ou=${project.name},cn=buildbot,ou=services,dc=immae,dc=eu |
9fb4205e IB |
53 | |
54 | SetEnvIf X-Url-Scheme https HTTPS=1 | |
55 | ProxyPreserveHost On | |
56 | </Location> | |
57 | <Location /buildbot/${project.name}/change_hook/base> | |
85817848 IB |
58 | <RequireAny> |
59 | Require local | |
60 | Require ldap-group cn=users,ou=${project.name},cn=buildbot,ou=services,dc=immae,dc=eu | |
ca330baa | 61 | Include /var/secrets/buildbot/${project.name}/webhook-httpd-include |
85817848 | 62 | </RequireAny> |
9fb4205e IB |
63 | </Location> |
64 | '') myconfig.env.buildbot.projects; | |
65 | ||
66 | system.activationScripts = lib.attrsets.mapAttrs' (k: project: lib.attrsets.nameValuePair "buildbot-${project.name}" { | |
67 | deps = [ "users" "wrappers" ]; | |
81b9ff89 | 68 | text = project.activationScript; |
6984f454 IB |
69 | }) myconfig.env.buildbot.projects; |
70 | ||
1a718805 | 71 | secrets.keys = ( |
6984f454 IB |
72 | lib.lists.flatten ( |
73 | lib.attrsets.mapAttrsToList (k: project: | |
74 | lib.attrsets.mapAttrsToList (k: v: | |
ca330baa | 75 | { |
6984f454 IB |
76 | permissions = "0600"; |
77 | user = "buildbot"; | |
78 | group = "buildbot"; | |
79 | text = v; | |
ca330baa | 80 | dest = "buildbot/${project.name}/${k}"; |
6984f454 IB |
81 | } |
82 | ) project.secrets | |
83 | ++ [ | |
ca330baa | 84 | { |
6984f454 IB |
85 | permissions = "0600"; |
86 | user = "wwwrun"; | |
87 | group = "wwwrun"; | |
88 | text = lib.optionalString (lib.attrsets.hasAttr "webhookTokens" project) '' | |
89 | Require expr "req('Access-Key') in { ${builtins.concatStringsSep ", " (map (x: "'${x}'") project.webhookTokens)} }" | |
90 | ''; | |
ca330baa IB |
91 | dest = "buildbot/${project.name}/webhook-httpd-include"; |
92 | } | |
6984f454 IB |
93 | ] |
94 | ) myconfig.env.buildbot.projects | |
95 | ) | |
ca330baa IB |
96 | ) ++ [ |
97 | { | |
6984f454 IB |
98 | permissions = "0600"; |
99 | user = "buildbot"; | |
100 | group = "buildbot"; | |
101 | text = myconfig.env.buildbot.ldap.password; | |
ca330baa IB |
102 | dest = "buildbot/ldap"; |
103 | } | |
104 | { | |
6984f454 IB |
105 | permissions = "0600"; |
106 | user = "buildbot"; | |
107 | group = "buildbot"; | |
108 | text = builtins.readFile "${myconfig.privateFiles}/buildbot_ssh_key"; | |
ca330baa IB |
109 | dest = "buildbot/ssh_key"; |
110 | } | |
111 | ]; | |
6984f454 | 112 | |
17f6eae9 IB |
113 | services.filesWatcher = lib.attrsets.mapAttrs' (k: project: lib.attrsets.nameValuePair "buildbot-${project.name}" { |
114 | restart = true; | |
115 | paths = [ | |
116 | "/var/secrets/buildbot/ldap" | |
117 | "/var/secrets/buildbot/ssh_key" | |
118 | ] ++ lib.attrsets.mapAttrsToList (k: v: "/var/secrets/buildbot/${project.name}/${k}") project.secrets; | |
119 | }) myconfig.env.buildbot.projects; | |
120 | ||
6984f454 IB |
121 | systemd.services = lib.attrsets.mapAttrs' (k: project: lib.attrsets.nameValuePair "buildbot-${project.name}" { |
122 | description = "Buildbot Continuous Integration Server ${project.name}."; | |
ca330baa | 123 | after = [ "network-online.target" ]; |
6984f454 IB |
124 | wantedBy = [ "multi-user.target" ]; |
125 | path = project.packages pkgs ++ (project.pythonPackages buildbot.pythonModule pkgs); | |
126 | preStart = let | |
caa08508 | 127 | master-cfg = "${buildbot_common}/${pkgs.python3.pythonForBuild.sitePackages}/buildbot_common/master.cfg"; |
e2b96bf5 IB |
128 | tac_file = pkgs.writeText "buildbot.tac" '' |
129 | import os | |
130 | ||
131 | from twisted.application import service | |
132 | from buildbot.master import BuildMaster | |
133 | ||
134 | basedir = '${varDir}/${project.name}' | |
135 | rotateLength = 10000000 | |
136 | maxRotatedFiles = 10 | |
137 | configfile = '${master-cfg}' | |
138 | ||
139 | # Default umask for server | |
140 | umask = None | |
141 | ||
142 | # if this is a relocatable tac file, get the directory containing the TAC | |
143 | if basedir == '.': | |
144 | import os | |
145 | basedir = os.path.abspath(os.path.dirname(__file__)) | |
146 | ||
147 | # note: this line is matched against to check that this is a buildmaster | |
148 | # directory; do not edit it. | |
149 | application = service.Application('buildmaster') | |
150 | from twisted.python.logfile import LogFile | |
151 | from twisted.python.log import ILogObserver, FileLogObserver | |
152 | logfile = LogFile.fromFullPath(os.path.join(basedir, "twistd.log"), rotateLength=rotateLength, | |
153 | maxRotatedFiles=maxRotatedFiles) | |
154 | application.setComponent(ILogObserver, FileLogObserver(logfile).emit) | |
155 | ||
156 | m = BuildMaster(basedir, configfile, umask) | |
157 | m.setServiceParent(application) | |
158 | m.log_rotation.rotateLength = rotateLength | |
159 | m.log_rotation.maxRotatedFiles = maxRotatedFiles | |
160 | ''; | |
9fb4205e | 161 | in '' |
9fb4205e | 162 | if [ ! -f ${varDir}/${project.name}/buildbot.tac ]; then |
6984f454 | 163 | ${buildbot}/bin/buildbot create-master -c "${master-cfg}" "${varDir}/${project.name}" |
9fb4205e | 164 | rm -f ${varDir}/${project.name}/master.cfg.sample |
e2b96bf5 | 165 | rm -f ${varDir}/${project.name}/buildbot.tac |
9fb4205e | 166 | fi |
e2b96bf5 | 167 | ln -sf ${tac_file} ${varDir}/${project.name}/buildbot.tac |
ca330baa IB |
168 | # different buildbots may be trying that simultaneously, add the || true to avoid complaining in case of race |
169 | install -Dm600 -o buildbot -g buildbot -T /var/secrets/buildbot/ssh_key ${varDir}/buildbot_key || true | |
9fb4205e | 170 | buildbot_secrets=${varDir}/${project.name}/secrets |
6984f454 | 171 | install -m 0700 -o buildbot -g buildbot -d $buildbot_secrets |
ca330baa | 172 | install -Dm600 -o buildbot -g buildbot -T /var/secrets/buildbot/ldap $buildbot_secrets/ldap |
9fb4205e | 173 | ${builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList |
ca330baa | 174 | (k: v: "install -Dm600 -o buildbot -g buildbot -T /var/secrets/buildbot/${project.name}/${k} $buildbot_secrets/${k}") project.secrets |
9fb4205e | 175 | )} |
9fb4205e | 176 | ''; |
9fb4205e IB |
177 | environment = let |
178 | project_env = lib.attrsets.mapAttrs' (k: v: lib.attrsets.nameValuePair "BUILDBOT_${k}" v) project.environment; | |
caa08508 | 179 | buildbot_config = pkgs.python3Packages.buildPythonPackage (rec { |
9fb4205e | 180 | name = "buildbot_config-${project.name}"; |
e2b96bf5 | 181 | src = ./projects + "/${project.name}"; |
9fb4205e IB |
182 | format = "other"; |
183 | installPhase = '' | |
caa08508 IB |
184 | mkdir -p $out/${pkgs.python3.pythonForBuild.sitePackages} |
185 | cp -a $src $out/${pkgs.python3.pythonForBuild.sitePackages}/buildbot_config | |
9fb4205e IB |
186 | ''; |
187 | }); | |
188 | HOME = "${varDir}/${project.name}"; | |
caa08508 | 189 | PYTHONPATH = "${buildbot.pythonModule.withPackages (self: project.pythonPackages self pkgs ++ [ |
256d607c | 190 | pkgs.python3Packages.wokkel |
caa08508 IB |
191 | pkgs.python3Packages.treq pkgs.python3Packages.ldap3 buildbot |
192 | pkgs.python3Packages.buildbot-worker | |
9fb4205e | 193 | buildbot_common buildbot_config |
caa08508 | 194 | ])}/${buildbot.pythonModule.sitePackages}${if project.pythonPathHome then ":${varDir}/${project.name}/.local/${pkgs.python3.pythonForBuild.sitePackages}" else ""}"; |
9fb4205e IB |
195 | in project_env // { inherit PYTHONPATH HOME; }; |
196 | ||
197 | serviceConfig = { | |
198 | Type = "forking"; | |
199 | User = "buildbot"; | |
200 | Group = "buildbot"; | |
81b9ff89 IB |
201 | RuntimeDirectory = "buildbot"; |
202 | RuntimeDirectoryPreserve = "yes"; | |
203 | StateDirectory = "buildbot"; | |
6984f454 | 204 | SupplementaryGroups = "keys"; |
9fb4205e IB |
205 | WorkingDirectory = "${varDir}/${project.name}"; |
206 | ExecStart = "${buildbot}/bin/buildbot start"; | |
207 | }; | |
208 | }) myconfig.env.buildbot.projects; | |
209 | }; | |
210 | } |