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
|
2024-03-02 15:10:47 +00:00
|
|
|
cfg = config.services.buildbot-nix.coordinator;
|
2023-09-10 08:11:56 +00:00
|
|
|
in
|
|
|
|
{
|
2023-09-10 08:53:04 +00:00
|
|
|
options = {
|
2024-03-02 15:10:47 +00:00
|
|
|
services.buildbot-nix.coordinator = {
|
|
|
|
enable = lib.mkEnableOption "buildbot-coordinator";
|
2023-09-10 08:53:04 +00:00
|
|
|
dbUrl = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "postgresql://@/buildbot";
|
|
|
|
description = "Postgresql database url";
|
|
|
|
};
|
2023-12-23 18:54:42 +00:00
|
|
|
cachix = {
|
|
|
|
name = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
|
|
|
default = null;
|
|
|
|
description = "Cachix name";
|
|
|
|
};
|
|
|
|
|
|
|
|
signingKeyFile = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.path;
|
|
|
|
default = null;
|
|
|
|
description = "Cachix signing key";
|
|
|
|
};
|
|
|
|
|
|
|
|
authTokenFile = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
|
|
|
default = null;
|
|
|
|
description = "Cachix auth token";
|
|
|
|
};
|
|
|
|
};
|
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-11-12 06:07:30 +00:00
|
|
|
evalWorkerCount = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.int;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Number of nix-eval-jobs worker processes. If null, the number of cores is used.
|
|
|
|
If you experience memory issues (buildbot-workers going out-of-memory), you can reduce this number.
|
|
|
|
'';
|
|
|
|
};
|
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-11-04 08:50:23 +00:00
|
|
|
|
|
|
|
outputsPath = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.path;
|
|
|
|
description = "Path where we store the latest build store paths names for nix attributes as text files. This path will be exposed via nginx at \${domain}/nix-outputs";
|
|
|
|
default = null;
|
|
|
|
example = "/var/www/buildbot/nix-outputs";
|
|
|
|
};
|
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-11-04 08:19:56 +00:00
|
|
|
# By default buildbot uses a normal user, which is not a good default, because
|
|
|
|
# we grant normal users potentially access to other resources. Also
|
|
|
|
# we don't to be able to ssh into buildbot.
|
|
|
|
|
|
|
|
users.users.buildbot = {
|
|
|
|
isNormalUser = lib.mkForce false;
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
|
|
|
|
2023-12-23 18:54:42 +00:00
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.cachix.name != null -> cfg.cachix.signingKeyFile != null || cfg.cachix.authTokenFile != null;
|
|
|
|
message = "if cachix.name is provided, then cachix.signingKeyFile and cachix.authTokenFile must be set";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-09-10 08:53:04 +00:00
|
|
|
services.buildbot-master = {
|
|
|
|
enable = true;
|
2023-11-04 10:25:33 +00:00
|
|
|
|
|
|
|
# disable example workers from nixpkgs
|
|
|
|
builders = [ ];
|
|
|
|
schedulers = [ ];
|
|
|
|
workers = [ ];
|
|
|
|
|
2023-11-04 08:19:56 +00:00
|
|
|
home = "/var/lib/buildbot";
|
2023-09-24 07:08:03 +00:00
|
|
|
extraImports = ''
|
|
|
|
from datetime import timedelta
|
2024-03-02 15:10:47 +00:00
|
|
|
from buildbot_nix import NixConfigurator, CachixConfig
|
2023-09-24 07:08:03 +00:00
|
|
|
'';
|
|
|
|
configurators = [
|
|
|
|
''
|
|
|
|
util.JanitorConfigurator(logHorizon=timedelta(weeks=4), hour=12, dayOfWeek=6)
|
|
|
|
''
|
|
|
|
''
|
|
|
|
NixConfigurator(
|
2024-03-02 15:10:47 +00:00
|
|
|
gerrit=GerritConfig(
|
|
|
|
...
|
2023-09-24 07:08:03 +00:00
|
|
|
),
|
2024-03-02 15:10:47 +00:00
|
|
|
url=${builtins.toJSON config.services.buildbot-coordinator.buildbotUrl},
|
2023-09-24 07:08:03 +00:00
|
|
|
nix_eval_max_memory_size=${builtins.toJSON cfg.evalMaxMemorySize},
|
2023-12-23 18:54:42 +00:00
|
|
|
nix_eval_worker_count=${if cfg.evalWorkerCount == null then "None" else builtins.toString cfg.evalWorkerCount},
|
2023-09-24 07:08:03 +00:00
|
|
|
nix_supported_systems=${builtins.toJSON cfg.buildSystems},
|
2023-11-04 08:50:23 +00:00
|
|
|
outputs_path=${if cfg.outputsPath == null then "None" else builtins.toJSON cfg.outputsPath},
|
2023-09-24 07:08:03 +00:00
|
|
|
)
|
|
|
|
''
|
|
|
|
];
|
|
|
|
buildbotUrl =
|
|
|
|
let
|
|
|
|
host = config.services.nginx.virtualHosts.${cfg.domain};
|
|
|
|
hasSSL = host.forceSSL || host.addSSL;
|
|
|
|
in
|
|
|
|
"${if hasSSL then "https" else "http"}://${cfg.domain}/";
|
2024-03-02 15:10:47 +00:00
|
|
|
dbUrl = config.services.buildbot-nix.coordinator.dbUrl;
|
2023-09-10 08:53:04 +00:00
|
|
|
pythonPackages = ps: [
|
|
|
|
ps.requests
|
|
|
|
ps.treq
|
|
|
|
ps.psycopg2
|
|
|
|
(ps.toPythonModule pkgs.buildbot-worker)
|
|
|
|
pkgs.buildbot-plugins.www-react
|
2023-10-31 10:32:05 +00:00
|
|
|
(pkgs.python3.pkgs.callPackage ../default.nix { })
|
2023-12-07 12:02:50 +00:00
|
|
|
];
|
2023-09-10 08:53:04 +00:00
|
|
|
};
|
2023-09-10 08:11:56 +00:00
|
|
|
|
2023-09-10 08:53:04 +00:00
|
|
|
systemd.services.buildbot-master = {
|
2023-10-31 10:32:05 +00:00
|
|
|
after = [ "postgresql.service" ];
|
2023-09-10 08:53:04 +00:00
|
|
|
serviceConfig = {
|
|
|
|
# in master.py we read secrets from $CREDENTIALS_DIRECTORY
|
|
|
|
LoadCredential = [
|
|
|
|
"buildbot-nix-workers:${cfg.workersFile}"
|
2023-12-23 18:54:42 +00:00
|
|
|
]
|
|
|
|
++ lib.optional (cfg.cachix.signingKeyFile != null)
|
|
|
|
"cachix-signing-key:${builtins.toString cfg.cachix.signingKeyFile}"
|
|
|
|
++ lib.optional (cfg.cachix.authTokenFile != null)
|
|
|
|
"cachix-auth-token:${builtins.toString cfg.cachix.authTokenFile}";
|
2023-09-10 08:53:04 +00:00
|
|
|
};
|
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" ];
|
2023-11-18 07:32:11 +00:00
|
|
|
ensureUsers = [{
|
|
|
|
name = "buildbot";
|
|
|
|
ensureDBOwnership = true;
|
|
|
|
}];
|
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} = {
|
2023-11-04 08:50:23 +00:00
|
|
|
locations = {
|
2024-03-02 15:10:47 +00:00
|
|
|
"/".proxyPass = "http://127.0.0.1:${builtins.toString config.services.buildbot-coordinator.port}/";
|
2023-11-04 08:50:23 +00:00
|
|
|
"/sse" = {
|
2024-03-02 15:10:47 +00:00
|
|
|
proxyPass = "http://127.0.0.1:${builtins.toString config.services.buildbot-coordinator.port}/sse";
|
2023-11-04 08:50:23 +00:00
|
|
|
# proxy buffering will prevent sse to work
|
|
|
|
extraConfig = "proxy_buffering off;";
|
|
|
|
};
|
|
|
|
"/ws" = {
|
2024-03-02 15:10:47 +00:00
|
|
|
proxyPass = "http://127.0.0.1:${builtins.toString config.services.buildbot-coordinator.port}/ws";
|
2023-11-04 08:50:23 +00:00
|
|
|
proxyWebsockets = true;
|
|
|
|
# raise the proxy timeout for the websocket
|
|
|
|
extraConfig = "proxy_read_timeout 6000s;";
|
|
|
|
};
|
|
|
|
} // lib.optionalAttrs (cfg.outputsPath != null) {
|
|
|
|
"/nix-outputs".root = cfg.outputsPath;
|
2023-09-10 08:53:04 +00:00
|
|
|
};
|
2023-09-10 08:11:56 +00:00
|
|
|
};
|
|
|
|
|
2024-03-02 15:10:47 +00:00
|
|
|
systemd.tmpfiles.rules = lib.optional (cfg.outputsPath != null)
|
|
|
|
# Allow buildbot-coordinator to write to this directory
|
2023-11-04 10:32:16 +00:00
|
|
|
"d ${cfg.outputsPath} 0755 buildbot buildbot - -";
|
2023-09-10 08:11:56 +00:00
|
|
|
};
|
|
|
|
}
|