2023-09-10 08:11:56 +00:00
|
|
|
{ config
|
|
|
|
, pkgs
|
2023-09-10 08:53:04 +00:00
|
|
|
, lib
|
2024-07-26 10:17:56 +00:00
|
|
|
, options
|
2023-09-10 08:11:56 +00:00
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
let
|
2023-09-10 08:53:04 +00:00
|
|
|
cfg = config.services.buildbot-nix.master;
|
2024-06-14 08:59:10 +00:00
|
|
|
inherit (lib) mkRemovedOptionModule mkRenamedOptionModule;
|
2024-07-18 15:39:36 +00:00
|
|
|
|
|
|
|
interpolateType =
|
|
|
|
lib.mkOptionType {
|
|
|
|
name = "interpolate";
|
|
|
|
|
|
|
|
description = ''
|
|
|
|
A type represnting a Buildbot interpolation string, supports interpolations like `result-%(prop:attr)s`.
|
|
|
|
'';
|
|
|
|
|
|
|
|
check = x:
|
|
|
|
x ? "_type" && x._type == "interpolate" && x ? "value";
|
|
|
|
};
|
|
|
|
|
|
|
|
interpolateToString =
|
|
|
|
value:
|
|
|
|
if lib.isAttrs value && value ? "_type" && value._type == "interpolate" then
|
|
|
|
"util.Interpolate(${builtins.toJSON value.value})"
|
|
|
|
else
|
|
|
|
builtins.toJSON value;
|
2023-09-10 08:11:56 +00:00
|
|
|
in
|
|
|
|
{
|
2024-04-27 15:06:17 +00:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule
|
2024-04-30 13:45:39 +00:00
|
|
|
[
|
|
|
|
"services"
|
|
|
|
"buildbot-nix"
|
|
|
|
"master"
|
|
|
|
"github"
|
|
|
|
"admins"
|
|
|
|
]
|
|
|
|
[
|
|
|
|
"services"
|
|
|
|
"buildbot-nix"
|
|
|
|
"master"
|
|
|
|
"admins"
|
|
|
|
]
|
|
|
|
)
|
2024-05-18 19:36:22 +00:00
|
|
|
(mkRenamedOptionModule
|
|
|
|
[
|
|
|
|
"services"
|
|
|
|
"buildbot-nix"
|
|
|
|
"master"
|
|
|
|
"github"
|
|
|
|
"tokenFile"
|
|
|
|
]
|
|
|
|
[
|
|
|
|
"services"
|
|
|
|
"buildbot-nix"
|
|
|
|
"master"
|
|
|
|
"github"
|
|
|
|
"authType"
|
|
|
|
"legacy"
|
|
|
|
"tokenFile"
|
|
|
|
]
|
|
|
|
)
|
2024-06-14 08:59:10 +00:00
|
|
|
(mkRemovedOptionModule
|
|
|
|
[
|
|
|
|
"services"
|
|
|
|
"buildbot-nix"
|
|
|
|
"master"
|
|
|
|
"github"
|
|
|
|
"user"
|
|
|
|
]
|
|
|
|
''
|
|
|
|
Setting a user is not required.
|
|
|
|
''
|
|
|
|
)
|
2024-04-27 15:06:17 +00:00
|
|
|
];
|
|
|
|
|
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
|
|
|
dbUrl = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "postgresql://@/buildbot";
|
|
|
|
description = "Postgresql database url";
|
|
|
|
};
|
2024-04-27 15:06:17 +00:00
|
|
|
authBackend = lib.mkOption {
|
2024-04-30 13:45:39 +00:00
|
|
|
type = lib.types.enum [
|
|
|
|
"github"
|
|
|
|
"gitea"
|
|
|
|
"none"
|
|
|
|
];
|
2024-04-27 15:06:17 +00:00
|
|
|
default = "github";
|
|
|
|
description = ''
|
|
|
|
Which OAuth2 backend to use.
|
|
|
|
'';
|
|
|
|
};
|
2024-07-09 09:16:40 +00:00
|
|
|
buildRetries = lib.mkOption {
|
2024-07-09 10:01:06 +00:00
|
|
|
type = lib.types.int;
|
2024-07-09 09:16:40 +00:00
|
|
|
default = 1;
|
|
|
|
description = "Number of times a build is retried";
|
|
|
|
};
|
2024-07-18 15:39:36 +00:00
|
|
|
|
|
|
|
postBuildSteps = lib.mkOption {
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
A list of steps to execute after every successful build.
|
|
|
|
'';
|
|
|
|
type = lib.types.listOf (lib.types.submodule {
|
|
|
|
options = {
|
|
|
|
name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = ''
|
|
|
|
The name of the build step, will show up in Buildbot's UI.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
environment = lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf (oneOf [ interpolateType str ]);
|
|
|
|
description = ''
|
|
|
|
Extra environment variables to add to the environment of this build step.
|
|
|
|
The base environment is the environment of the `buildbot-worker` service.
|
|
|
|
|
|
|
|
To access the properties of a build, use the `interpolate` function defined in
|
|
|
|
`inputs.buildbot-nix.lib.interpolate` like so `(interpolate "result-%(prop:attr)s")`.
|
|
|
|
'';
|
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
|
|
|
|
command = lib.mkOption {
|
|
|
|
type = with lib.types; oneOf [ str (listOf (oneOf [ str interpolateType ])) ];
|
|
|
|
description = ''
|
|
|
|
The command to execute as part of the build step. Either a single string or
|
|
|
|
a list of strings. Be careful that neither variant is interpreted by a shell,
|
|
|
|
but is passed to `execve` verbatim. If you desire a shell, you must use
|
|
|
|
`writeShellScript` or similar functions.
|
|
|
|
|
|
|
|
To access the properties of a build, use the `interpolate` function defined in
|
|
|
|
`inputs.buildbot-nix.lib.interpolate` like so `(interpolate "result-%(prop:attr)s")`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
[
|
|
|
|
name = "upload-to-s3";
|
|
|
|
environment = {
|
2024-07-19 15:16:48 +00:00
|
|
|
S3_TOKEN = "%(secret:s3-token)";
|
2024-07-18 15:39:36 +00:00
|
|
|
S3_BUCKET = "bucket";
|
|
|
|
};
|
|
|
|
command = [ "nix" "copy" "%result%" ];
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-12-23 18:54:42 +00:00
|
|
|
cachix = {
|
2024-07-19 20:20:42 +00:00
|
|
|
enable = lib.mkEnableOption "Enable Cachix integration";
|
|
|
|
|
2023-12-23 18:54:42 +00:00
|
|
|
name = lib.mkOption {
|
2024-07-19 20:20:42 +00:00
|
|
|
type = lib.types.str;
|
2023-12-23 18:54:42 +00:00
|
|
|
description = "Cachix name";
|
|
|
|
};
|
|
|
|
|
|
|
|
signingKeyFile = lib.mkOption {
|
2024-07-19 20:20:42 +00:00
|
|
|
type = lib.types.path;
|
2023-12-23 18:54:42 +00:00
|
|
|
description = "Cachix signing key";
|
|
|
|
};
|
|
|
|
|
|
|
|
authTokenFile = lib.mkOption {
|
2024-07-19 20:20:42 +00:00
|
|
|
type = lib.types.str;
|
2023-12-23 18:54:42 +00:00
|
|
|
description = "Cachix auth token";
|
|
|
|
};
|
|
|
|
};
|
2024-04-27 15:06:17 +00:00
|
|
|
gitea = {
|
2024-04-30 13:45:39 +00:00
|
|
|
enable = lib.mkEnableOption "Enable Gitea integration" // {
|
|
|
|
default = cfg.authBackend == "gitea";
|
|
|
|
};
|
2024-04-27 15:06:17 +00:00
|
|
|
|
|
|
|
tokenFile = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
|
|
|
description = "Gitea token file";
|
|
|
|
};
|
|
|
|
webhookSecretFile = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
2024-04-30 13:45:39 +00:00
|
|
|
description = "Gitea webhook secret file";
|
2024-04-27 15:06:17 +00:00
|
|
|
};
|
|
|
|
oauthSecretFile = lib.mkOption {
|
2024-04-30 13:45:39 +00:00
|
|
|
type = lib.types.nullOr lib.types.path;
|
|
|
|
default = null;
|
2024-04-27 15:06:17 +00:00
|
|
|
description = "Gitea oauth secret file";
|
|
|
|
};
|
|
|
|
|
2024-04-30 13:45:39 +00:00
|
|
|
instanceUrl = lib.mkOption {
|
2024-04-27 15:06:17 +00:00
|
|
|
type = lib.types.str;
|
|
|
|
description = "Gitea instance URL";
|
|
|
|
};
|
|
|
|
oauthId = lib.mkOption {
|
2024-04-30 13:45:39 +00:00
|
|
|
type = lib.types.nullOr lib.types.str;
|
|
|
|
default = null;
|
2024-04-27 15:06:17 +00:00
|
|
|
description = "Gitea oauth id. Used for the login button";
|
|
|
|
};
|
|
|
|
topic = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
|
|
|
default = "build-with-buildbot";
|
|
|
|
description = ''
|
|
|
|
Projects that have this topic will be built by buildbot.
|
|
|
|
If null, all projects that the buildbot Gitea user has access to, are built.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2023-09-10 08:53:04 +00:00
|
|
|
github = {
|
2024-04-30 13:45:39 +00:00
|
|
|
enable = lib.mkEnableOption "Enable GitHub integration" // {
|
|
|
|
default = cfg.authBackend == "github";
|
|
|
|
};
|
2024-04-27 15:06:17 +00:00
|
|
|
|
2024-06-02 14:13:38 +00:00
|
|
|
authType = lib.mkOption {
|
|
|
|
type = lib.types.attrTag {
|
|
|
|
legacy = lib.mkOption {
|
|
|
|
description = "GitHub legacy auth backend";
|
|
|
|
type = lib.types.submodule {
|
|
|
|
options.tokenFile = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
|
|
|
description = "Github token file";
|
|
|
|
};
|
|
|
|
};
|
2024-05-18 19:36:22 +00:00
|
|
|
};
|
|
|
|
|
2024-06-02 14:13:38 +00:00
|
|
|
app = lib.mkOption {
|
|
|
|
description = "GitHub legacy auth backend";
|
|
|
|
type = lib.types.submodule {
|
|
|
|
options.id = lib.mkOption {
|
|
|
|
type = lib.types.int;
|
|
|
|
description = ''
|
|
|
|
GitHub app ID.
|
|
|
|
'';
|
|
|
|
};
|
2024-05-18 19:36:22 +00:00
|
|
|
|
2024-06-02 14:13:38 +00:00
|
|
|
options.secretKeyFile = lib.mkOption {
|
2024-06-25 14:42:24 +00:00
|
|
|
type = lib.types.nullOr lib.types.path;
|
2024-06-02 14:13:38 +00:00
|
|
|
description = ''
|
|
|
|
GitHub app secret key file location.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2024-05-18 19:36:22 +00:00
|
|
|
};
|
|
|
|
};
|
2023-09-10 08:53:04 +00:00
|
|
|
};
|
2024-05-18 19:36:22 +00:00
|
|
|
|
2023-09-10 08:53:04 +00:00
|
|
|
webhookSecretFile = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
|
|
|
description = "Github webhook secret file";
|
|
|
|
};
|
|
|
|
oauthSecretFile = lib.mkOption {
|
2024-04-30 13:45:39 +00:00
|
|
|
type = lib.types.nullOr lib.types.path;
|
|
|
|
default = null;
|
2023-09-10 08:53:04 +00:00
|
|
|
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 {
|
2024-04-30 13:45:39 +00:00
|
|
|
type = lib.types.nullOr lib.types.str;
|
|
|
|
default = null;
|
2023-09-10 08:53:04 +00:00
|
|
|
description = "Github oauth id. Used for the login button";
|
|
|
|
};
|
2023-10-12 13:20:50 +00:00
|
|
|
topic = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
|
|
|
default = "build-with-buildbot";
|
|
|
|
description = ''
|
|
|
|
Projects that have this topic will be built by buildbot.
|
|
|
|
If null, all projects that the buildbot github user has access to, are built.
|
|
|
|
'';
|
|
|
|
};
|
2023-09-10 08:53:04 +00:00
|
|
|
};
|
2024-04-27 15:06:17 +00:00
|
|
|
admins = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
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 {
|
2024-07-19 20:20:42 +00:00
|
|
|
type = lib.types.int;
|
|
|
|
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
|
|
|
|
2024-05-08 15:15:31 +00:00
|
|
|
webhookBaseUrl = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "URL base for the webhook endpoint that will be registered for github or gitea repos.";
|
|
|
|
example = "https://buildbot-webhooks.numtide.com/";
|
2024-05-08 16:18:58 +00:00
|
|
|
default = config.services.buildbot-master.buildbotUrl;
|
2024-05-08 15:15:31 +00:00
|
|
|
};
|
2024-05-09 13:52:20 +00:00
|
|
|
useHTTPS = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If buildbot is setup behind a reverse proxy other than the configured nginx set this to true
|
|
|
|
to force the endpoint to use https:// instead of http://.
|
|
|
|
'';
|
|
|
|
};
|
2024-05-08 15:15:31 +00:00
|
|
|
|
2024-07-13 06:34:04 +00:00
|
|
|
buildbotNixpkgs = lib.mkOption {
|
|
|
|
type = lib.types.raw;
|
|
|
|
description = "Nixpkgs to use for buildbot packages";
|
|
|
|
};
|
|
|
|
|
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";
|
|
|
|
};
|
2024-07-12 14:44:02 +00:00
|
|
|
|
|
|
|
jobReportLimit = lib.mkOption {
|
2024-07-15 10:08:36 +00:00
|
|
|
type = lib.types.nullOr lib.types.ints.unsigned;
|
2024-07-12 14:44:02 +00:00
|
|
|
description = ''
|
|
|
|
The max number of build jobs per `nix-eval` `buildbot-nix` will report to backends (GitHub, Gitea, etc.).
|
2024-07-15 10:08:36 +00:00
|
|
|
If set to `null`, report everything, if set to `n` (some unsiggned intereger), report builds individually
|
2024-07-12 14:44:02 +00:00
|
|
|
as long as the number of builds is less than or equal to `n`, then report builds using a combined
|
|
|
|
`nix-build-combined` build.
|
|
|
|
'';
|
|
|
|
default = 50;
|
|
|
|
};
|
2023-09-10 08:53:04 +00:00
|
|
|
};
|
2023-09-10 08:11:56 +00:00
|
|
|
};
|
2024-07-12 10:47:18 +00:00
|
|
|
config = lib.mkMerge [
|
|
|
|
(lib.mkIf cfg.enable {
|
|
|
|
# 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.
|
2023-11-04 08:19:56 +00:00
|
|
|
|
2024-07-12 10:47:18 +00:00
|
|
|
users.users.buildbot = {
|
|
|
|
isNormalUser = lib.mkForce false;
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
2023-11-04 08:19:56 +00:00
|
|
|
|
2024-07-12 10:47:18 +00:00
|
|
|
assertions = [
|
2024-07-26 10:17:56 +00:00
|
|
|
{
|
|
|
|
assertion =
|
|
|
|
let
|
|
|
|
optionsCachix = options.services.buildbot-nix.master.cachix;
|
|
|
|
allIsNull = lib.all (x: x == null);
|
|
|
|
in
|
|
|
|
optionsCachix.enable.value || lib.foldr (a: b: a && b) true [
|
|
|
|
(optionsCachix.name.isDefined -> allIsNull optionsCachix.name.definitions)
|
|
|
|
(optionsCachix.signingKeyFile.isDefined -> allIsNull optionsCachix.signingKeyFile.definitions)
|
|
|
|
(optionsCachix.authTokenFile.isDefined -> allIsNull optionsCachix.authTokenFile.definitions)
|
|
|
|
];
|
|
|
|
message = ''
|
|
|
|
The semantics of `options.services.buildbot-nix.master.cachix` recently changed slightly, the options
|
|
|
|
`name`, `signingKeyFile`, and `authTokenFile` are no longer null-able. To enable Cachix support use:
|
|
|
|
`options.services.buildbot-nix.master.cachix.enable = True`.
|
|
|
|
'';
|
|
|
|
}
|
2024-07-12 10:47:18 +00:00
|
|
|
{
|
|
|
|
assertion =
|
2024-07-13 06:34:04 +00:00
|
|
|
lib.versionAtLeast cfg.buildbotNixpkgs.buildbot.version "4.0.0";
|
|
|
|
message = ''
|
|
|
|
`buildbot-nix` requires `buildbot` 4.0.0 or greater to function.
|
|
|
|
Set services.buildbot-nix.master.buildbotNixpkgs to a nixpkgs with buildbot >= 4.0.0,
|
|
|
|
i.e. nixpkgs-unstable.
|
|
|
|
'';
|
2024-07-12 10:47:18 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion =
|
2024-07-19 20:20:42 +00:00
|
|
|
cfg.authBackend == "github" -> (cfg.github.oauthId != null && cfg.github.oauthSecretFile != null);
|
|
|
|
message = ''If config.services.buildbot-nix.master.authBackend is set to "github", then config.services.buildbot-nix.master.github.oauthId and config.services.buildbot-nix.master.github.oauthSecretFile have to be set.'';
|
2024-07-12 10:47:18 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion =
|
2024-07-19 20:20:42 +00:00
|
|
|
cfg.authBackend == "gitea" -> (cfg.gitea.oauthId != null && cfg.gitea.oauthSecretFile != null);
|
|
|
|
message = ''config.services.buildbot-nix.master.authBackend is set to "gitea", then config.services.buildbot-nix.master.gitea.oauthId and config.services.buildbot-nix.master.gitea.oauthSecretFile have to be set.'';
|
2024-07-12 10:47:18 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion =
|
2024-07-19 20:20:42 +00:00
|
|
|
cfg.authBackend == "github" -> cfg.github.enable;
|
|
|
|
message = ''
|
|
|
|
If `cfg.authBackend` is set to `"github"` the GitHub backend must be enabled with `cfg.github.enable`;
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion =
|
|
|
|
cfg.authBackend == "gitea" -> cfg.gitea.enable;
|
|
|
|
message = ''
|
|
|
|
If `cfg.authBackend` is set to `"gitea"` the GitHub backend must be enabled with `cfg.gitea.enable`;
|
|
|
|
'';
|
2024-07-12 10:47:18 +00:00
|
|
|
}
|
|
|
|
];
|
2023-12-23 18:54:42 +00:00
|
|
|
|
2024-07-12 10:47:18 +00:00
|
|
|
services.buildbot-master = {
|
|
|
|
enable = true;
|
2023-11-04 10:25:33 +00:00
|
|
|
|
2024-07-12 10:47:18 +00:00
|
|
|
# disable example workers from nixpkgs
|
|
|
|
builders = [ ];
|
|
|
|
schedulers = [ ];
|
|
|
|
workers = [ ];
|
2023-11-04 10:25:33 +00:00
|
|
|
|
2024-07-12 10:47:18 +00:00
|
|
|
home = "/var/lib/buildbot";
|
|
|
|
extraImports = ''
|
|
|
|
from datetime import timedelta
|
|
|
|
from buildbot_nix import (
|
|
|
|
NixConfigurator,
|
2024-07-19 20:20:42 +00:00
|
|
|
BuildbotNixConfig,
|
2024-07-12 10:47:18 +00:00
|
|
|
)
|
2024-07-19 20:20:42 +00:00
|
|
|
from pathlib import Path
|
|
|
|
import json
|
2024-07-12 10:47:18 +00:00
|
|
|
'';
|
|
|
|
configurators = [
|
|
|
|
''
|
|
|
|
util.JanitorConfigurator(logHorizon=timedelta(weeks=4), hour=12, dayOfWeek=6)
|
|
|
|
''
|
|
|
|
''
|
|
|
|
NixConfigurator(
|
2024-07-19 20:20:42 +00:00
|
|
|
BuildbotNixConfig.model_validate(json.loads(Path("${(pkgs.formats.json {}).generate "buildbot-nix-config.json" {
|
|
|
|
db_url = cfg.dbUrl;
|
|
|
|
auth_backend = cfg.authBackend;
|
|
|
|
build_retries = cfg.buildRetries;
|
|
|
|
cachix = if !cfg.cachix.enable then
|
|
|
|
null
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name = cfg.cachix.name;
|
|
|
|
signing_key_file = cfg.cachix.signingKeyFile;
|
|
|
|
auth_token_file = cfg.cachix.authTokenFile;
|
|
|
|
};
|
|
|
|
gitea = if !cfg.gitea.enable then
|
|
|
|
null
|
|
|
|
else
|
|
|
|
{
|
|
|
|
token_file = "gitea-token";
|
|
|
|
webhook_secret_file = "gitea-webhook-secret";
|
|
|
|
project_cache_file = "gitea-project-cache.json";
|
|
|
|
oauth_secret_file = "gitea-oauth-secret";
|
|
|
|
instance_url = cfg.gitea.instanceUrl;
|
|
|
|
oauth_id = cfg.gitea.oauthId;
|
|
|
|
topic = cfg.gitea.topic;
|
|
|
|
};
|
|
|
|
github = if !cfg.github.enable then
|
|
|
|
null
|
|
|
|
else {
|
|
|
|
auth_type = if (cfg.github.authType ? "legacy") then
|
|
|
|
{
|
|
|
|
token_file = "github-token";
|
|
|
|
}
|
|
|
|
else if (cfg.github.authType ? "app") then
|
|
|
|
{
|
|
|
|
id = cfg.github.authType.app.id;
|
2024-07-24 15:21:52 +00:00
|
|
|
secret_key_file = "github-app-secret-key";
|
2024-07-19 20:20:42 +00:00
|
|
|
installation_token_map_file = "github-app-installation-token-map.json";
|
|
|
|
project_id_map_file = "github-app-project-id-map-name.json";
|
|
|
|
jwt_token_map = "github-app-jwt-token";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw "authType is neither \"legacy\" nor \"app\"";
|
|
|
|
project_cache_file = "github-project-cache-v1.json";
|
|
|
|
webhook_secret_file = "github-webhook-secret";
|
|
|
|
oauth_secret_file = "github-oauth-secret";
|
|
|
|
oauth_id = cfg.github.oauthId;
|
|
|
|
topic = cfg.github.topic;
|
|
|
|
};
|
|
|
|
admins = cfg.admins;
|
|
|
|
workers_file = cfg.workersFile;
|
|
|
|
build_systems = cfg.buildSystems;
|
|
|
|
eval_max_memory_size = cfg.evalMaxMemorySize;
|
|
|
|
eval_worker_count = cfg.evalWorkerCount;
|
|
|
|
domain = cfg.domain;
|
|
|
|
webhook_base_url = cfg.webhookBaseUrl;
|
|
|
|
use_https = cfg.useHTTPS;
|
|
|
|
outputs_path = cfg.outputsPath;
|
|
|
|
url = config.services.buildbot-nix.master.webhookBaseUrl;
|
|
|
|
post_build_steps = cfg.postBuildSteps;
|
2024-07-12 14:44:02 +00:00
|
|
|
job_report_limit=if cfg.jobReportLimit == null then "None" else builtins.toJSON cfg.jobReportLimit;
|
2024-07-19 20:20:42 +00:00
|
|
|
}}").read_text()))
|
2024-07-12 10:47:18 +00:00
|
|
|
)
|
|
|
|
''
|
|
|
|
];
|
|
|
|
buildbotUrl =
|
|
|
|
let
|
|
|
|
host = config.services.nginx.virtualHosts.${cfg.domain};
|
|
|
|
hasSSL = host.forceSSL || host.addSSL || cfg.useHTTPS;
|
|
|
|
in
|
|
|
|
"${if hasSSL then "https" else "http"}://${cfg.domain}/";
|
|
|
|
dbUrl = config.services.buildbot-nix.master.dbUrl;
|
2024-07-13 06:34:04 +00:00
|
|
|
|
|
|
|
package = cfg.buildbotNixpkgs.buildbot.overrideAttrs (old: {
|
2024-07-11 18:56:15 +00:00
|
|
|
patches = old.patches ++ [
|
|
|
|
./0001-master-reporters-github-render-token-for-each-reques.patch
|
|
|
|
];
|
2024-07-13 06:34:04 +00:00
|
|
|
});
|
2024-07-16 13:06:13 +00:00
|
|
|
pythonPackages =
|
|
|
|
let
|
|
|
|
buildbot-gitea = (cfg.buildbotNixpkgs.python3.pkgs.callPackage ./buildbot-gitea.nix {
|
|
|
|
inherit (cfg.buildbotNixpkgs) buildbot;
|
|
|
|
}).overrideAttrs (old: {
|
|
|
|
patches = old.patches ++ [
|
|
|
|
./0002-GiteaHandler-set-branch-to-the-PR-branch-not-the-bas.patch
|
|
|
|
./0001-GiteaHandler-set-the-category-of-PR-changes-to-pull-.patch
|
|
|
|
];
|
|
|
|
});
|
|
|
|
in
|
|
|
|
ps: [
|
2024-07-19 20:20:42 +00:00
|
|
|
ps.pydantic
|
2024-07-16 13:06:13 +00:00
|
|
|
pkgs.nix
|
|
|
|
ps.requests
|
|
|
|
ps.treq
|
|
|
|
ps.psycopg2
|
|
|
|
(ps.toPythonModule cfg.buildbotNixpkgs.buildbot-worker)
|
|
|
|
cfg.buildbotNixpkgs.buildbot-plugins.www
|
|
|
|
(cfg.buildbotNixpkgs.python3.pkgs.callPackage ../default.nix { })
|
|
|
|
buildbot-gitea
|
|
|
|
];
|
2024-07-12 10:47:18 +00:00
|
|
|
};
|
2023-09-10 08:11:56 +00:00
|
|
|
|
2024-07-12 10:47:18 +00:00
|
|
|
systemd.services.buildbot-master = {
|
|
|
|
after = [ "postgresql.service" ];
|
|
|
|
path = [
|
|
|
|
pkgs.openssl
|
|
|
|
];
|
|
|
|
serviceConfig = {
|
|
|
|
# in master.py we read secrets from $CREDENTIALS_DIRECTORY
|
|
|
|
LoadCredential =
|
|
|
|
[ "buildbot-nix-workers:${cfg.workersFile}" ]
|
2024-07-19 20:20:42 +00:00
|
|
|
++ lib.optionals cfg.github.enable ([
|
2024-07-12 10:47:18 +00:00
|
|
|
"github-webhook-secret:${cfg.github.webhookSecretFile}"
|
|
|
|
]
|
2024-07-19 20:20:42 +00:00
|
|
|
++ lib.optional (cfg.github.authType ? "legacy")
|
2024-07-12 10:47:18 +00:00
|
|
|
"github-token:${cfg.github.authType.legacy.tokenFile}"
|
2024-07-19 20:20:42 +00:00
|
|
|
++ lib.optional (cfg.github.authType ? "app")
|
2024-07-12 10:47:18 +00:00
|
|
|
"github-app-secret-key:${cfg.github.authType.app.secretKeyFile}"
|
2024-07-19 20:20:42 +00:00
|
|
|
)
|
|
|
|
++ lib.optional (cfg.authBackend == "gitea") "gitea-oauth-secret:${cfg.gitea.oauthSecretFile}"
|
|
|
|
++ lib.optional (cfg.authBackend == "github") "github-oauth-secret:${cfg.github.oauthSecretFile}"
|
|
|
|
++ lib.optionals cfg.cachix.enable [
|
|
|
|
"cachix-signing-key:${builtins.toString cfg.cachix.signingKeyFile}"
|
|
|
|
"cachix-auth-token:${builtins.toString cfg.cachix.authTokenFile}"
|
|
|
|
]
|
2024-07-12 10:47:18 +00:00
|
|
|
++ lib.optionals cfg.gitea.enable [
|
|
|
|
"gitea-token:${cfg.gitea.tokenFile}"
|
|
|
|
"gitea-webhook-secret:${cfg.gitea.webhookSecretFile}"
|
|
|
|
];
|
|
|
|
};
|
2023-09-10 08:53:04 +00:00
|
|
|
};
|
|
|
|
|
2024-07-12 10:47:18 +00:00
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
|
|
|
ensureDatabases = [ "buildbot" ];
|
|
|
|
ensureUsers = [
|
|
|
|
{
|
|
|
|
name = "buildbot";
|
|
|
|
ensureDBOwnership = true;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2023-09-10 08:11:56 +00:00
|
|
|
|
2024-07-12 10:47:18 +00:00
|
|
|
services.nginx.enable = true;
|
|
|
|
services.nginx.virtualHosts.${cfg.domain} = {
|
|
|
|
locations = {
|
|
|
|
"/".proxyPass = "http://127.0.0.1:${builtins.toString config.services.buildbot-master.port}/";
|
|
|
|
"/sse" = {
|
|
|
|
proxyPass = "http://127.0.0.1:${builtins.toString config.services.buildbot-master.port}/sse";
|
|
|
|
# proxy buffering will prevent sse to work
|
|
|
|
extraConfig = "proxy_buffering off;";
|
|
|
|
};
|
|
|
|
"/ws" = {
|
|
|
|
proxyPass = "http://127.0.0.1:${builtins.toString config.services.buildbot-master.port}/ws";
|
|
|
|
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:11:56 +00:00
|
|
|
|
2024-07-12 10:47:18 +00:00
|
|
|
systemd.tmpfiles.rules =
|
|
|
|
[
|
|
|
|
# delete legacy gcroot location, can be dropped after 2024-06-01
|
|
|
|
"R /var/lib/buildbot-worker/gcroot - - - - -"
|
|
|
|
]
|
|
|
|
++ lib.optional (cfg.outputsPath != null)
|
|
|
|
# Allow buildbot-master to write to this directory
|
|
|
|
"d ${cfg.outputsPath} 0755 buildbot buildbot - -";
|
|
|
|
})
|
|
|
|
];
|
2023-09-10 08:11:56 +00:00
|
|
|
}
|