2022-12-28 21:21:41 +00:00
|
|
|
|
# NixOS module for Buildbot continuous integration server.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
2021-12-19 01:06:50 +00:00
|
|
|
|
{ config, lib, options, pkgs, ... }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
cfg = config.services.buildbot-master;
|
2021-12-19 01:06:50 +00:00
|
|
|
|
opt = options.services.buildbot-master;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
2023-04-12 12:48:02 +00:00
|
|
|
|
package = pkgs.python3.pkgs.toPythonModule cfg.package;
|
|
|
|
|
python = package.pythonModule;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
2022-12-02 08:20:57 +00:00
|
|
|
|
escapeStr = escape [ "'" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
defaultMasterCfg = pkgs.writeText "master.cfg" ''
|
|
|
|
|
from buildbot.plugins import *
|
2023-10-09 19:29:22 +00:00
|
|
|
|
${cfg.extraImports}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
factory = util.BuildFactory()
|
|
|
|
|
c = BuildmasterConfig = dict(
|
|
|
|
|
workers = [${concatStringsSep "," cfg.workers}],
|
2020-06-18 07:06:33 +00:00
|
|
|
|
protocols = { 'pb': {'port': ${toString cfg.pbPort} } },
|
2020-04-24 23:36:52 +00:00
|
|
|
|
title = '${escapeStr cfg.title}',
|
|
|
|
|
titleURL = '${escapeStr cfg.titleUrl}',
|
|
|
|
|
buildbotURL = '${escapeStr cfg.buildbotUrl}',
|
|
|
|
|
db = dict(db_url='${escapeStr cfg.dbUrl}'),
|
|
|
|
|
www = dict(port=${toString cfg.port}),
|
|
|
|
|
change_source = [ ${concatStringsSep "," cfg.changeSource} ],
|
|
|
|
|
schedulers = [ ${concatStringsSep "," cfg.schedulers} ],
|
|
|
|
|
builders = [ ${concatStringsSep "," cfg.builders} ],
|
2020-06-15 15:56:04 +00:00
|
|
|
|
services = [ ${concatStringsSep "," cfg.reporters} ],
|
2023-10-09 19:29:22 +00:00
|
|
|
|
configurators = [ ${concatStringsSep "," cfg.configurators} ],
|
2020-04-24 23:36:52 +00:00
|
|
|
|
)
|
|
|
|
|
for step in [ ${concatStringsSep "," cfg.factorySteps} ]:
|
|
|
|
|
factory.addStep(step)
|
|
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
tacFile = pkgs.writeText "buildbot-master.tac" ''
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
from twisted.application import service
|
|
|
|
|
from buildbot.master import BuildMaster
|
|
|
|
|
|
|
|
|
|
basedir = '${cfg.buildbotDir}'
|
|
|
|
|
|
|
|
|
|
configfile = '${cfg.masterCfg}'
|
|
|
|
|
|
|
|
|
|
# Default umask for server
|
|
|
|
|
umask = None
|
|
|
|
|
|
|
|
|
|
# note: this line is matched against to check that this is a buildmaster
|
|
|
|
|
# directory; do not edit it.
|
|
|
|
|
application = service.Application('buildmaster')
|
|
|
|
|
|
|
|
|
|
m = BuildMaster(basedir, configfile, umask)
|
|
|
|
|
m.setServiceParent(application)
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
options = {
|
|
|
|
|
services.buildbot-master = {
|
|
|
|
|
|
|
|
|
|
factorySteps = mkOption {
|
|
|
|
|
type = types.listOf types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Factory Steps";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
default = [];
|
|
|
|
|
example = [
|
2022-03-30 09:31:56 +00:00
|
|
|
|
"steps.Git(repourl='https://github.com/buildbot/pyflakes.git', mode='incremental')"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
"steps.ShellCommand(command=['trial', 'pyflakes'])"
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
changeSource = mkOption {
|
|
|
|
|
type = types.listOf types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "List of Change Sources.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
default = [];
|
|
|
|
|
example = [
|
2022-03-30 09:31:56 +00:00
|
|
|
|
"changes.GitPoller('https://github.com/buildbot/pyflakes.git', workdir='gitpoller-workdir', branch='master', pollinterval=300)"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
|
configurators = mkOption {
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
description = lib.mdDoc "Configurator Steps, see https://docs.buildbot.net/latest/manual/configuration/configurators.html";
|
|
|
|
|
default = [];
|
|
|
|
|
example = [
|
|
|
|
|
"util.JanitorConfigurator(logHorizon=timedelta(weeks=4), hour=12, dayOfWeek=6)"
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
|
enable = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Whether to enable the Buildbot continuous integration server.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Extra configuration to append to master.cfg";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
default = "c['buildbotNetUsageData'] = None";
|
|
|
|
|
};
|
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
|
extraImports = mkOption {
|
|
|
|
|
type = types.str;
|
|
|
|
|
description = lib.mdDoc "Extra python imports to prepend to master.cfg";
|
|
|
|
|
default = "";
|
|
|
|
|
example = "from buildbot.process.project import Project";
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
|
masterCfg = mkOption {
|
|
|
|
|
type = types.path;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Optionally pass master.cfg path. Other options in this configuration will be ignored.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
default = defaultMasterCfg;
|
2022-09-09 14:08:57 +00:00
|
|
|
|
defaultText = literalMD ''generated configuration file'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
example = "/etc/nixos/buildbot/master.cfg";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
schedulers = mkOption {
|
|
|
|
|
type = types.listOf types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "List of Schedulers.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
default = [
|
|
|
|
|
"schedulers.SingleBranchScheduler(name='all', change_filter=util.ChangeFilter(branch='master'), treeStableTimer=None, builderNames=['runtests'])"
|
|
|
|
|
"schedulers.ForceScheduler(name='force',builderNames=['runtests'])"
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
builders = mkOption {
|
|
|
|
|
type = types.listOf types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "List of Builders.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
default = [
|
|
|
|
|
"util.BuilderConfig(name='runtests',workernames=['example-worker'],factory=factory)"
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
workers = mkOption {
|
|
|
|
|
type = types.listOf types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "List of Workers.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
default = [ "worker.Worker('example-worker', 'pass')" ];
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-15 15:56:04 +00:00
|
|
|
|
reporters = mkOption {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "List of reporter objects used to present build status to various users.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
|
default = "buildbot";
|
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "User the buildbot server should execute under.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
|
default = "buildbot";
|
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Primary group of buildbot user.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extraGroups = mkOption {
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
default = [];
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "List of extra groups that the buildbot user should be a part of.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
home = mkOption {
|
|
|
|
|
default = "/home/buildbot";
|
|
|
|
|
type = types.path;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Buildbot home directory.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
buildbotDir = mkOption {
|
|
|
|
|
default = "${cfg.home}/master";
|
2021-12-19 01:06:50 +00:00
|
|
|
|
defaultText = literalExpression ''"''${config.${opt.home}}/master"'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
type = types.path;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Specifies the Buildbot directory.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
2020-06-18 07:06:33 +00:00
|
|
|
|
pbPort = mkOption {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
default = 9989;
|
2020-06-18 07:06:33 +00:00
|
|
|
|
type = types.either types.str types.int;
|
|
|
|
|
example = "'tcp:9990:interface=127.0.0.1'";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2020-06-18 07:06:33 +00:00
|
|
|
|
The buildmaster will listen on a TCP port of your choosing
|
|
|
|
|
for connections from workers.
|
|
|
|
|
It can also use this port for connections from remote Change Sources,
|
|
|
|
|
status clients, and debug tools.
|
|
|
|
|
This port should be visible to the outside world, and you’ll need to tell
|
|
|
|
|
your worker admins about your choice.
|
|
|
|
|
If put in (single) quotes, this can also be used as a connection string,
|
2022-08-12 12:06:08 +00:00
|
|
|
|
as defined in the [ConnectionStrings guide](https://twistedmatrix.com/documents/current/core/howto/endpoints.html).
|
2020-06-18 07:06:33 +00:00
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
listenAddress = mkOption {
|
|
|
|
|
default = "0.0.0.0";
|
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Specifies the bind address on which the buildbot HTTP interface listens.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
buildbotUrl = mkOption {
|
|
|
|
|
default = "http://localhost:8010/";
|
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Specifies the Buildbot URL.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
title = mkOption {
|
|
|
|
|
default = "Buildbot";
|
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Specifies the Buildbot Title.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
titleUrl = mkOption {
|
|
|
|
|
default = "Buildbot";
|
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Specifies the Buildbot TitleURL.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
dbUrl = mkOption {
|
|
|
|
|
default = "sqlite:///state.sqlite";
|
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Specifies the database connection string.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
|
default = 8010;
|
2022-12-17 10:02:37 +00:00
|
|
|
|
type = types.port;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Specifies port number on which the buildbot HTTP interface listens.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
|
package = mkPackageOption pkgs "buildbot-full" {
|
|
|
|
|
example = "buildbot";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
packages = mkOption {
|
|
|
|
|
default = [ pkgs.git ];
|
2021-10-06 13:57:05 +00:00
|
|
|
|
defaultText = literalExpression "[ pkgs.git ]";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
type = types.listOf types.package;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Packages to add to PATH for the buildbot process.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pythonPackages = mkOption {
|
2021-02-05 17:12:51 +00:00
|
|
|
|
type = types.functionTo (types.listOf types.package);
|
2020-04-24 23:36:52 +00:00
|
|
|
|
default = pythonPackages: with pythonPackages; [ ];
|
2021-10-06 13:57:05 +00:00
|
|
|
|
defaultText = literalExpression "pythonPackages: with pythonPackages; [ ]";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Packages to add the to the PYTHONPATH of the buildbot process.";
|
2021-10-06 13:57:05 +00:00
|
|
|
|
example = literalExpression "pythonPackages: with pythonPackages; [ requests ]";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
users.groups = optionalAttrs (cfg.group == "buildbot") {
|
|
|
|
|
buildbot = { };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
users.users = optionalAttrs (cfg.user == "buildbot") {
|
|
|
|
|
buildbot = {
|
|
|
|
|
description = "Buildbot User.";
|
|
|
|
|
isNormalUser = true;
|
|
|
|
|
createHome = true;
|
2022-12-02 08:20:57 +00:00
|
|
|
|
inherit (cfg) home group extraGroups;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
useDefaultShell = true;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.services.buildbot-master = {
|
|
|
|
|
description = "Buildbot Continuous Integration Server.";
|
2024-01-25 14:12:00 +00:00
|
|
|
|
after = [ "network.target" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
path = cfg.packages ++ cfg.pythonPackages python.pkgs;
|
2023-04-12 12:48:02 +00:00
|
|
|
|
environment.PYTHONPATH = "${python.withPackages (self: cfg.pythonPackages self ++ [ package ])}/${python.sitePackages}";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
|
mkdir -vp "${cfg.buildbotDir}"
|
|
|
|
|
# Link the tac file so buildbot command line tools recognize the directory
|
|
|
|
|
ln -sf "${tacFile}" "${cfg.buildbotDir}/buildbot.tac"
|
|
|
|
|
${cfg.package}/bin/buildbot create-master --db "${cfg.dbUrl}" "${cfg.buildbotDir}"
|
|
|
|
|
rm -f buildbot.tac.new master.cfg.sample
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
Type = "simple";
|
|
|
|
|
User = cfg.user;
|
|
|
|
|
Group = cfg.group;
|
|
|
|
|
WorkingDirectory = cfg.home;
|
|
|
|
|
# NOTE: call twistd directly with stdout logging for systemd
|
2023-10-09 19:29:22 +00:00
|
|
|
|
ExecStart = "${python.pkgs.twisted}/bin/twistd -o --nodaemon --pidfile= --logfile - --python ${cfg.buildbotDir}/buildbot.tac";
|
|
|
|
|
# To reload on upgrade, set the following in your configuration:
|
|
|
|
|
# systemd.services.buildbot-master.reloadIfChanged = true;
|
|
|
|
|
ExecReload = [
|
|
|
|
|
"${pkgs.coreutils}/bin/ln -sf ${tacFile} ${cfg.buildbotDir}/buildbot.tac"
|
|
|
|
|
"${pkgs.coreutils}/bin/kill -HUP $MAINPID"
|
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-18 07:06:33 +00:00
|
|
|
|
imports = [
|
|
|
|
|
(mkRenamedOptionModule [ "services" "buildbot-master" "bpPort" ] [ "services" "buildbot-master" "pbPort" ])
|
2020-06-15 15:56:04 +00:00
|
|
|
|
(mkRemovedOptionModule [ "services" "buildbot-master" "status" ] ''
|
|
|
|
|
Since Buildbot 0.9.0, status targets are deprecated and ignored.
|
|
|
|
|
Review your configuration and migrate to reporters (available at services.buildbot-master.reporters).
|
|
|
|
|
'')
|
2020-06-18 07:06:33 +00:00
|
|
|
|
];
|
|
|
|
|
|
2024-01-13 08:15:51 +00:00
|
|
|
|
meta.maintainers = lib.teams.buildbot.members;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
}
|