]>
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; | |
caa08508 | 5 | buildslist_yarn = pkgs.yarn2nix.mkYarnModules { |
9fb4205e IB |
6 | name = "buildslist-yarn-modules"; |
7 | packageJSON = "${buildslist_src.src}/package.json"; | |
8 | yarnLock = "${buildslist_src.src}/yarn.lock"; | |
9 | }; | |
caa08508 | 10 | buildslist_bower = pkgs.buildBowerComponents { |
9fb4205e IB |
11 | name = "buildslist"; |
12 | generated = ./bower.nix; | |
13 | src = "${buildslist_src.src}/guanlecoja/"; | |
14 | }; | |
15 | ||
caa08508 | 16 | buildslist = pkgs.python3Packages.buildPythonPackage rec { |
9fb4205e | 17 | pname = "buildbot-buildslist"; |
caa08508 | 18 | inherit (pkgs.buildbot-pkg) version; |
9fb4205e IB |
19 | |
20 | preConfigure = '' | |
21 | export HOME=$PWD | |
22 | cp -a ${buildslist_yarn}/node_modules . | |
23 | chmod -R u+w node_modules | |
24 | cp -a ${buildslist_bower}/bower_components ./libs | |
25 | chmod -R u+w libs | |
26 | ''; | |
caa08508 | 27 | propagatedBuildInputs = with pkgs.python3Packages; [ |
9fb4205e IB |
28 | (klein.overridePythonAttrs(old: { checkPhase = ""; })) |
29 | buildbot-pkg | |
30 | ]; | |
caa08508 | 31 | nativeBuildInputs = with pkgs; [ yarn nodejs ]; |
9fb4205e IB |
32 | buildInputs = [ buildslist_yarn buildslist_bower ]; |
33 | ||
34 | doCheck = false; | |
35 | src = buildslist_src.src; | |
36 | }; | |
caa08508 | 37 | buildbot_common = pkgs.python3Packages.buildPythonPackage rec { |
e2b96bf5 IB |
38 | name = "buildbot_common"; |
39 | src = ./common; | |
9fb4205e IB |
40 | format = "other"; |
41 | installPhase = '' | |
caa08508 IB |
42 | mkdir -p $out/${pkgs.python3.pythonForBuild.sitePackages} |
43 | cp -a $src $out/${pkgs.python3.pythonForBuild.sitePackages}/buildbot_common | |
9fb4205e | 44 | ''; |
e2b96bf5 | 45 | }; |
caa08508 | 46 | buildbot = pkgs.python3Packages.buildbot-full.withPlugins ([ buildslist ]); |
9fb4205e IB |
47 | in |
48 | { | |
49 | options = { | |
50 | services.buildbot.enable = lib.mkOption { | |
51 | type = lib.types.bool; | |
52 | default = false; | |
53 | description = '' | |
54 | Whether to enable buildbot. | |
55 | ''; | |
56 | }; | |
57 | }; | |
58 | ||
59 | config = lib.mkIf config.services.buildbot.enable { | |
60 | ids.uids.buildbot = myconfig.env.buildbot.user.uid; | |
61 | ids.gids.buildbot = myconfig.env.buildbot.user.gid; | |
62 | ||
63 | users.groups.buildbot.gid = config.ids.gids.buildbot; | |
64 | users.users.buildbot = { | |
65 | name = "buildbot"; | |
66 | uid = config.ids.uids.buildbot; | |
67 | group = "buildbot"; | |
68 | description = "Buildbot user"; | |
69 | home = varDir; | |
70 | }; | |
71 | ||
72 | services.myWebsites.tools.vhostConfs.git.extraConfig = lib.attrsets.mapAttrsToList (k: project: '' | |
73 | RedirectMatch permanent "^/buildbot/${project.name}$" "/buildbot/${project.name}/" | |
74 | RewriteEngine On | |
75 | RewriteRule ^/buildbot/${project.name}/ws(.*)$ unix:///run/buildbot/${project.name}.sock|ws://git.immae.eu/ws$1 [P,NE,QSA,L] | |
76 | ProxyPass /buildbot/${project.name}/ unix:///run/buildbot/${project.name}.sock|http://${project.name}-git.immae.eu/ | |
77 | ProxyPassReverse /buildbot/${project.name}/ unix:///run/buildbot/${project.name}.sock|http://${project.name}-git.immae.eu/ | |
78 | <Location /buildbot/${project.name}/> | |
79 | Use LDAPConnect | |
e2b96bf5 | 80 | Require ldap-group cn=users,ou=${project.name},cn=buildbot,ou=services,dc=immae,dc=eu |
9fb4205e IB |
81 | |
82 | SetEnvIf X-Url-Scheme https HTTPS=1 | |
83 | ProxyPreserveHost On | |
84 | </Location> | |
85 | <Location /buildbot/${project.name}/change_hook/base> | |
86 | Require local | |
87 | </Location> | |
88 | '') myconfig.env.buildbot.projects; | |
89 | ||
90 | system.activationScripts = lib.attrsets.mapAttrs' (k: project: lib.attrsets.nameValuePair "buildbot-${project.name}" { | |
91 | deps = [ "users" "wrappers" ]; | |
92 | text = let | |
caa08508 | 93 | master-cfg = "${buildbot_common}/${pkgs.python3.pythonForBuild.sitePackages}/buildbot_common/master.cfg"; |
e2b96bf5 IB |
94 | buildbot_key = pkgs.writeText "buildbot_key" (builtins.readFile "${myconfig.privateFiles}/buildbot_ssh_key"); |
95 | tac_file = pkgs.writeText "buildbot.tac" '' | |
96 | import os | |
97 | ||
98 | from twisted.application import service | |
99 | from buildbot.master import BuildMaster | |
100 | ||
101 | basedir = '${varDir}/${project.name}' | |
102 | rotateLength = 10000000 | |
103 | maxRotatedFiles = 10 | |
104 | configfile = '${master-cfg}' | |
105 | ||
106 | # Default umask for server | |
107 | umask = None | |
108 | ||
109 | # if this is a relocatable tac file, get the directory containing the TAC | |
110 | if basedir == '.': | |
111 | import os | |
112 | basedir = os.path.abspath(os.path.dirname(__file__)) | |
113 | ||
114 | # note: this line is matched against to check that this is a buildmaster | |
115 | # directory; do not edit it. | |
116 | application = service.Application('buildmaster') | |
117 | from twisted.python.logfile import LogFile | |
118 | from twisted.python.log import ILogObserver, FileLogObserver | |
119 | logfile = LogFile.fromFullPath(os.path.join(basedir, "twistd.log"), rotateLength=rotateLength, | |
120 | maxRotatedFiles=maxRotatedFiles) | |
121 | application.setComponent(ILogObserver, FileLogObserver(logfile).emit) | |
122 | ||
123 | m = BuildMaster(basedir, configfile, umask) | |
124 | m.setServiceParent(application) | |
125 | m.log_rotation.rotateLength = rotateLength | |
126 | m.log_rotation.maxRotatedFiles = maxRotatedFiles | |
127 | ''; | |
9fb4205e IB |
128 | in '' |
129 | install -m 0755 -o buildbot -g buildbot -d /run/buildbot/ | |
130 | install -m 0755 -o buildbot -g buildbot -d ${varDir} | |
131 | if [ ! -f ${varDir}/${project.name}/buildbot.tac ]; then | |
132 | $wrapperDir/sudo -u buildbot ${buildbot}/bin/buildbot create-master -c "${master-cfg}" "${varDir}/${project.name}" | |
133 | rm -f ${varDir}/${project.name}/master.cfg.sample | |
e2b96bf5 | 134 | rm -f ${varDir}/${project.name}/buildbot.tac |
9fb4205e | 135 | fi |
e2b96bf5 IB |
136 | ln -sf ${tac_file} ${varDir}/${project.name}/buildbot.tac |
137 | install -Dm600 -o buildbot -g buildbot -T ${buildbot_key} ${varDir}/buildbot_key | |
9fb4205e IB |
138 | buildbot_secrets=${varDir}/${project.name}/secrets |
139 | install -m 0600 -o buildbot -g buildbot -d $buildbot_secrets | |
140 | echo "${myconfig.env.buildbot.ldap.password}" > $buildbot_secrets/ldap | |
141 | ${builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList | |
142 | (k: v: "echo ${lib.strings.escapeShellArg v} > $buildbot_secrets/${k}") project.secrets | |
143 | )} | |
144 | chown -R buildbot:buildbot $buildbot_secrets | |
145 | chmod -R u=rX,go=- $buildbot_secrets | |
146 | ${project.activationScript} | |
147 | ''; | |
148 | }) myconfig.env.buildbot.projects; | |
149 | ||
150 | systemd.services = lib.attrsets.mapAttrs' (k: project: lib.attrsets.nameValuePair "buildbot-${project.name}" { | |
151 | description = "Buildbot Continuous Integration Server ${project.name}."; | |
152 | after = [ "network-online.target" ]; | |
153 | wantedBy = [ "multi-user.target" ]; | |
caa08508 | 154 | path = project.packages pkgs ++ (project.pythonPackages buildbot.pythonModule pkgs); |
9fb4205e IB |
155 | environment = let |
156 | project_env = lib.attrsets.mapAttrs' (k: v: lib.attrsets.nameValuePair "BUILDBOT_${k}" v) project.environment; | |
caa08508 | 157 | buildbot_config = pkgs.python3Packages.buildPythonPackage (rec { |
9fb4205e | 158 | name = "buildbot_config-${project.name}"; |
e2b96bf5 | 159 | src = ./projects + "/${project.name}"; |
9fb4205e IB |
160 | format = "other"; |
161 | installPhase = '' | |
caa08508 IB |
162 | mkdir -p $out/${pkgs.python3.pythonForBuild.sitePackages} |
163 | cp -a $src $out/${pkgs.python3.pythonForBuild.sitePackages}/buildbot_config | |
9fb4205e IB |
164 | ''; |
165 | }); | |
166 | HOME = "${varDir}/${project.name}"; | |
caa08508 IB |
167 | PYTHONPATH = "${buildbot.pythonModule.withPackages (self: project.pythonPackages self pkgs ++ [ |
168 | pkgs.python3Packages.treq pkgs.python3Packages.ldap3 buildbot | |
169 | pkgs.python3Packages.buildbot-worker | |
9fb4205e | 170 | buildbot_common buildbot_config |
caa08508 | 171 | ])}/${buildbot.pythonModule.sitePackages}${if project.pythonPathHome then ":${varDir}/${project.name}/.local/${pkgs.python3.pythonForBuild.sitePackages}" else ""}"; |
9fb4205e IB |
172 | in project_env // { inherit PYTHONPATH HOME; }; |
173 | ||
174 | serviceConfig = { | |
175 | Type = "forking"; | |
176 | User = "buildbot"; | |
177 | Group = "buildbot"; | |
178 | WorkingDirectory = "${varDir}/${project.name}"; | |
179 | ExecStart = "${buildbot}/bin/buildbot start"; | |
180 | }; | |
181 | }) myconfig.env.buildbot.projects; | |
182 | }; | |
183 | } |