stockholm/krebs/3modules/buildbot/slave.nix

155 lines
4.2 KiB
Nix
Raw Normal View History

2015-12-16 13:30:01 +00:00
{ config, pkgs, lib, ... }:
2016-10-20 18:54:38 +00:00
with import <stockholm/lib>;
2015-12-16 13:30:01 +00:00
let
default-packages = [ pkgs.git pkgs.bash ];
2016-11-11 00:34:18 +00:00
buildbot = pkgs.stdenv.lib.overrideDerivation pkgs.buildbot-worker (old:{
patches = [ ./buildbot-worker.patch ];
propagatedBuildInputs = old.propagatedBuildInputs ++ [ pkgs.coreutils ];
});
cfg = config.krebs.buildbot.worker;
2015-12-16 13:30:01 +00:00
api = {
2016-11-11 00:34:18 +00:00
enable = mkEnableOption "Buildbot worker";
2015-12-16 13:30:01 +00:00
workDir = mkOption {
2016-11-11 00:34:18 +00:00
default = "/var/lib/buildbot/worker";
2015-12-16 13:30:01 +00:00
type = types.str;
description = ''
2016-11-11 00:34:18 +00:00
Path to build bot worker directory.
2015-12-16 13:30:01 +00:00
Will be created on startup.
'';
};
masterhost = mkOption {
default = "localhost";
type = types.str;
description = ''
Hostname/IP of the buildbot master
'';
};
username = mkOption {
type = types.str;
description = ''
2016-11-11 00:34:18 +00:00
workername used to authenticate with master
2015-12-16 13:30:01 +00:00
'';
};
password = mkOption {
type = types.str;
description = ''
2016-11-11 00:34:18 +00:00
worker password used to authenticate with master
2015-12-16 13:30:01 +00:00
'';
};
contact = mkOption {
2016-11-11 00:34:18 +00:00
default = "nix worker <buildworker@${config.networking.hostName}>";
2015-12-16 13:30:01 +00:00
type = types.str;
description = ''
2016-11-11 00:34:18 +00:00
contact to be announced by buildworker
2015-12-16 13:30:01 +00:00
'';
};
description = mkOption {
2016-11-11 00:34:18 +00:00
default = "Nix Generated Buildworker";
2015-12-16 13:30:01 +00:00
type = types.str;
description = ''
2016-11-11 00:34:18 +00:00
description for hostto be announced by buildworker
2015-12-16 13:30:01 +00:00
'';
};
packages = mkOption {
default = [ pkgs.git ];
type = with types; listOf package;
description = ''
2016-11-11 00:34:18 +00:00
packages which should be in path for buildworker
'';
};
extraEnviron = mkOption {
default = {};
example = {
NIX_PATH = "nixpkgs=/path/to/my/nixpkgs";
};
type = types.attrsOf types.str;
description = ''
2016-11-11 00:34:18 +00:00
extra environment variables to be provided to the buildworker service
if you need nixpkgs, e.g. for running nix-shell you can set NIX_PATH here.
'';
};
2015-12-16 13:30:01 +00:00
extraConfig = mkOption {
default = "";
type = types.lines;
example = ''
port = 443
keepalive = 600
'';
description = ''
2016-11-11 00:34:18 +00:00
extra config evaluated before calling Buildworker init in .tac file
2015-12-16 13:30:01 +00:00
'';
};
};
imp = {
2016-11-11 00:34:18 +00:00
users.extraUsers.buildbotworker = {
uid = genid "buildbotworker";
description = "Buildbot worker";
2015-12-16 13:30:01 +00:00
home = cfg.workDir;
createHome = false;
};
2016-11-11 00:34:18 +00:00
users.extraGroups.buildbotworker = {
gid = genid "buildbotworker";
2015-12-16 13:30:01 +00:00
};
2016-11-11 00:34:18 +00:00
systemd.services."buildbotworker-${cfg.username}-${cfg.masterhost}" = {
description = "Buildbot worker for ${cfg.username}@${cfg.masterhost}";
2015-12-16 13:30:01 +00:00
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
path = default-packages ++ cfg.packages;
environment = {
SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
NIX_REMOTE="daemon";
} // cfg.extraEnviron;
2015-12-16 13:30:01 +00:00
serviceConfig = let
2016-02-15 17:46:19 +00:00
workdir = shell.escape cfg.workDir;
contact = shell.escape cfg.contact;
description = shell.escape cfg.description;
2016-11-11 00:34:18 +00:00
masterhost = shell.escape cfg.masterhost;
username = shell.escape cfg.username;
password = shell.escape cfg.password;
2015-12-16 13:30:01 +00:00
in {
PermissionsStartOnly = true;
Type = "forking";
PIDFile = "${workdir}/twistd.pid";
2016-11-11 00:34:18 +00:00
ExecStartPre = pkgs.writeDash "buildbot-slave-init" ''
2015-12-16 13:30:01 +00:00
set -efux
mkdir -p ${workdir}/info
2016-11-11 00:34:18 +00:00
# TODO: cleanup .tac file?
${buildbot}/bin/buildbot-worker create-worker ${workdir} ${masterhost} ${username} ${password}
2015-12-16 13:30:01 +00:00
echo ${contact} > ${workdir}/info/admin
echo ${description} > ${workdir}/info/host
2016-11-11 00:34:18 +00:00
chown buildbotworker:buildbotworker -R ${workdir}
2015-12-16 13:30:01 +00:00
chmod 700 -R ${workdir}
'';
2016-11-11 00:34:18 +00:00
ExecStart = "${buildbot}/bin/buildbot-worker start ${workdir}";
ExecStop = "${buildbot}/bin/buildbot-worker stop ${workdir}";
2015-12-16 13:30:01 +00:00
PrivateTmp = "true";
2016-11-11 00:34:18 +00:00
User = "buildbotworker";
2015-12-16 13:30:01 +00:00
Restart = "always";
RestartSec = "10";
};
};
};
in
{
2016-11-11 00:34:18 +00:00
options.krebs.buildbot.worker = api;
2016-02-14 15:43:44 +00:00
config = lib.mkIf cfg.enable imp;
2015-12-16 13:30:01 +00:00
}