buildbot-nix/nix/master.nix

156 lines
5 KiB
Nix
Raw Normal View History

2023-09-10 08:11:56 +00:00
{ config
, pkgs
2023-09-10 08:53:04 +00:00
, lib
2023-09-10 08:11:56 +00:00
, ...
}:
let
2023-09-10 08:53:04 +00:00
cfg = config.services.buildbot-nix.master;
2023-09-10 08:11:56 +00:00
in
{
2023-09-10 08:53:04 +00:00
options = {
services.buildbot-nix.master = {
2023-09-10 09:00:42 +00:00
enable = lib.mkEnableOption "buildbot-master";
2023-09-10 08:53:04 +00:00
port = lib.mkOption {
type = lib.types.int;
default = 1810;
description = "Port on which buildbot-master is listening";
};
dbUrl = lib.mkOption {
type = lib.types.str;
default = "postgresql://@/buildbot";
description = "Postgresql database url";
};
github = {
tokenFile = lib.mkOption {
type = lib.types.path;
description = "Github token file";
};
webhookSecretFile = lib.mkOption {
type = lib.types.path;
description = "Github webhook secret file";
};
oauthSecretFile = lib.mkOption {
type = lib.types.path;
description = "Github oauth secret file";
};
# TODO: make this an option
# https://github.com/organizations/numtide/settings/applications
# Application name: BuildBot
# Homepage URL: https://buildbot.numtide.com
# Authorization callback URL: https://buildbot.numtide.com/auth/login
# oauth_token: 2516248ec6289e4d9818122cce0cbde39e4b788d
oauthId = lib.mkOption {
type = lib.types.str;
description = "Github oauth id. Used for the login button";
};
# Most likely you want to use the same user as for the buildbot
githubUser = lib.mkOption {
type = lib.types.str;
description = "Github user that is used for the buildbot";
};
githubAdmins = lib.mkOption {
type = lib.types.listOf lib.types.str;
2023-09-17 20:14:56 +00:00
default = [ ];
description = "Users that are allowed to login to buildbot, trigger builds and change settings";
2023-09-10 08:53:04 +00:00
};
};
workersFile = lib.mkOption {
type = lib.types.path;
description = "File containing a list of nix workers";
};
buildSystems = lib.mkOption {
type = lib.types.listOf lib.types.str;
2023-09-10 10:11:50 +00:00
default = [ pkgs.hostPlatform.system ];
2023-09-10 08:53:04 +00:00
description = "Systems that we will be build";
};
evalMaxMemorySize = lib.mkOption {
type = lib.types.str;
2023-09-10 10:11:50 +00:00
default = "2048";
2023-09-10 08:53:04 +00:00
description = ''
Maximum memory size for nix-eval-jobs (in MiB) per
worker. After the limit is reached, the worker is
restarted.
'';
};
2023-09-10 11:29:56 +00:00
domain = lib.mkOption {
2023-09-10 08:53:04 +00:00
type = lib.types.str;
2023-09-10 11:29:56 +00:00
description = "Buildbot domain";
example = "buildbot.numtide.com";
2023-09-10 08:53:04 +00:00
};
};
2023-09-10 08:11:56 +00:00
};
2023-09-10 09:00:42 +00:00
config = lib.mkIf cfg.enable {
2023-09-10 08:53:04 +00:00
services.buildbot-master = {
enable = true;
2023-09-10 11:16:33 +00:00
masterCfg = "${../buildbot_nix}/master.py";
2023-09-10 08:53:04 +00:00
dbUrl = config.services.buildbot-nix.master.dbUrl;
pythonPackages = ps: [
ps.requests
ps.treq
ps.psycopg2
(ps.toPythonModule pkgs.buildbot-worker)
pkgs.buildbot-plugins.www
pkgs.buildbot-plugins.www-react
];
};
2023-09-10 08:11:56 +00:00
2023-09-10 08:53:04 +00:00
systemd.services.buildbot-master = {
environment = {
PORT = builtins.toString cfg.port;
DB_URL = cfg.dbUrl;
GITHUB_OAUTH_ID = cfg.github.oauthId;
2023-09-10 11:29:56 +00:00
BUILDBOT_URL = "https://${cfg.domain}/";
2023-09-10 08:53:04 +00:00
BUILDBOT_GITHUB_USER = cfg.github.githubUser;
GITHUB_ADMINS = builtins.toString cfg.github.githubAdmins;
NIX_SUPPORTED_SYSTEMS = builtins.toString cfg.buildSystems;
NIX_EVAL_MAX_MEMORY_SIZE = builtins.toString cfg.evalMaxMemorySize;
};
serviceConfig = {
# in master.py we read secrets from $CREDENTIALS_DIRECTORY
LoadCredential = [
"github-token:${cfg.github.tokenFile}"
"github-webhook-secret:${cfg.github.webhookSecretFile}"
"github-oauth-secret:${cfg.github.oauthSecretFile}"
"buildbot-nix-workers:${cfg.workersFile}"
];
};
2023-09-10 08:11:56 +00:00
};
2023-09-10 08:53:04 +00:00
services.postgresql = {
2023-09-10 10:11:50 +00:00
enable = true;
2023-09-10 08:53:04 +00:00
ensureDatabases = [ "buildbot" ];
ensureUsers = [
{
name = "buildbot";
ensurePermissions."DATABASE buildbot" = "ALL PRIVILEGES";
}
2023-09-10 08:11:56 +00:00
];
};
2023-09-10 11:29:56 +00:00
services.nginx.enable = true;
services.nginx.virtualHosts.${cfg.domain} = {
locations."/".proxyPass = "http://127.0.0.1:${builtins.toString cfg.port}/";
2023-09-10 08:53:04 +00:00
locations."/sse" = {
2023-09-10 11:29:56 +00:00
proxyPass = "http://127.0.0.1:${builtins.toString cfg.port}/sse";
2023-09-10 08:53:04 +00:00
# proxy buffering will prevent sse to work
extraConfig = "proxy_buffering off;";
};
locations."/ws" = {
2023-09-10 11:29:56 +00:00
proxyPass = "http://127.0.0.1:${builtins.toString cfg.port}/ws";
2023-09-10 08:53:04 +00:00
proxyWebsockets = true;
# raise the proxy timeout for the websocket
extraConfig = "proxy_read_timeout 6000s;";
};
2023-09-10 08:11:56 +00:00
2023-09-10 08:53:04 +00:00
# In this directory we store the lastest build store paths for nix attributes
locations."/nix-outputs".root = "/var/www/buildbot/";
2023-09-10 08:11:56 +00:00
};
2023-09-10 08:53:04 +00:00
# Allow buildbot-master to write to this directory
systemd.tmpfiles.rules = [
"d /var/www/buildbot/nix-outputs 0755 buildbot buildbot - -"
];
2023-09-10 11:29:56 +00:00
2023-09-10 08:11:56 +00:00
};
}