2024-10-28 14:38:29 +00:00
|
|
|
{ pkgs, config, lib, ... }:
|
2024-07-08 21:55:11 +00:00
|
|
|
|
|
|
|
let
|
2024-10-28 14:38:29 +00:00
|
|
|
inherit (lib) mkIf mkMerge;
|
2024-07-08 21:55:11 +00:00
|
|
|
cfg = config.bagel.services.ofborg;
|
|
|
|
|
|
|
|
amqpHost = "amqp.forkos.org";
|
|
|
|
amqpPort = 5671;
|
2024-10-28 14:38:29 +00:00
|
|
|
generators = pkgs.formats.json { };
|
|
|
|
configFile = generators.generate "ofborg-config.json" config.bagel.services.ofborg.settings;
|
|
|
|
mkOfborgWorker = binaryName: extra: extra // {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
description = "ofborg CI service - ${binaryName} worker";
|
|
|
|
after = [ "rabbitmq.service" ];
|
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
ExecStart = "${cfg.package}/bin/${binaryName} ${configFile}";
|
|
|
|
# TODO: more hardening.
|
|
|
|
StateDirectory = "ofborg";
|
|
|
|
LogsDirectory = "ofborg";
|
|
|
|
WorkingDirectory = "/var/lib/ofborg";
|
|
|
|
LoadCredential = [ "rabbitmq-password:${config.age.secrets.rabbitmq-password.path}" ];
|
|
|
|
};
|
|
|
|
};
|
2024-07-08 21:55:11 +00:00
|
|
|
in {
|
|
|
|
options.bagel.services.ofborg = with lib; {
|
2024-10-28 14:38:29 +00:00
|
|
|
rabbitmq.enable = mkEnableOption "ofborg AMQP queue";
|
|
|
|
builder.enable = mkEnableOption "ofborg builder worker";
|
2024-11-14 18:27:11 +00:00
|
|
|
pastebin.enable = mkEnableOption "ofborg pastebin service";
|
2024-11-14 22:05:23 +00:00
|
|
|
statcheck-worker.enable = mkEnableOption "ofborg status & checks worker";
|
2024-11-14 17:53:51 +00:00
|
|
|
mass-rebuilder.enable = mkEnableOption "ofborg evaluator worker for mass rebuilds jobs";
|
2024-10-28 17:12:41 +00:00
|
|
|
stats.enable = mkEnableOption "ofborg prometheus worker";
|
2024-07-08 21:55:11 +00:00
|
|
|
|
2024-11-14 22:04:42 +00:00
|
|
|
gerrit-events-streamer.enable = mkEnableOption "ofborg's Gerrit event streamer";
|
|
|
|
|
2024-10-28 14:38:29 +00:00
|
|
|
package = mkPackageOption pkgs "ofborg" { };
|
2024-07-08 21:55:11 +00:00
|
|
|
|
2024-10-28 14:38:29 +00:00
|
|
|
settings = mkOption {
|
|
|
|
type = generators.type;
|
2024-07-08 21:55:11 +00:00
|
|
|
};
|
2024-10-28 14:38:29 +00:00
|
|
|
};
|
2024-07-08 21:55:11 +00:00
|
|
|
|
2024-10-28 14:38:29 +00:00
|
|
|
config = mkMerge [
|
|
|
|
{
|
|
|
|
age.secrets.rabbitmq-password.file = ../../secrets/floral/rabbitmq-password.age;
|
|
|
|
# TODO: move this to global.
|
|
|
|
bagel.services.ofborg.settings = {
|
|
|
|
rabbitmq = {
|
|
|
|
ssl = true;
|
|
|
|
host = "amqp.forkos.org";
|
|
|
|
virtualhost = "amqp.forkos.org";
|
|
|
|
username = "worker";
|
|
|
|
password_file = "$CREDENTIALS_DIRECTORY/rabbitmq-password";
|
|
|
|
};
|
|
|
|
feedback.full_logs = lib.mkDefault true;
|
|
|
|
log_storage.path = lib.mkDefault "/var/log/ofborg";
|
|
|
|
runner = {
|
|
|
|
identity = config.networking.fqdn;
|
|
|
|
repos = lib.mkDefault [
|
|
|
|
"nixpkgs"
|
|
|
|
"ofborg"
|
|
|
|
];
|
2024-11-17 11:48:08 +00:00
|
|
|
|
2024-10-28 14:38:29 +00:00
|
|
|
disable_trusted_users = true;
|
|
|
|
};
|
|
|
|
checkout.root = lib.mkDefault "/var/lib/ofborg/checkouts";
|
|
|
|
nix = {
|
|
|
|
system = "x86_64-linux";
|
|
|
|
remote = "daemon";
|
|
|
|
build_timeout_seconds = 3600;
|
|
|
|
initial_heap_size = "4g";
|
|
|
|
};
|
2024-11-14 18:27:11 +00:00
|
|
|
|
|
|
|
pastebin = {
|
|
|
|
root = "$STATE_DIRECTORY/pastebins";
|
|
|
|
db = "$STATE_DIRECTORY/db.json";
|
|
|
|
};
|
2024-11-14 17:53:51 +00:00
|
|
|
|
2024-11-14 22:05:23 +00:00
|
|
|
statcheck = {
|
|
|
|
db = "$STATE_DIRECTORY/db.sqlite";
|
|
|
|
};
|
|
|
|
|
2024-11-14 17:53:51 +00:00
|
|
|
# We use Gerrit.
|
|
|
|
vcs = "Gerrit";
|
|
|
|
gerrit = {
|
|
|
|
instance_uri = "cl.forkos.org";
|
|
|
|
ssh_private_key_file = "$CREDENTIALS_DIRECTORY/gerrit-ssh-key";
|
|
|
|
ssh_port = 29418;
|
|
|
|
};
|
2024-10-28 14:38:29 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
(mkIf cfg.rabbitmq.enable {
|
|
|
|
services.nginx.enable = true;
|
|
|
|
services.rabbitmq = {
|
|
|
|
enable = true;
|
|
|
|
configItems = {
|
|
|
|
"listeners.tcp" = "none";
|
|
|
|
"listeners.ssl.default" = builtins.toString amqpPort;
|
|
|
|
"ssl_options.certfile" = "${config.security.acme.certs.${amqpHost}.directory}/cert.pem";
|
|
|
|
"ssl_options.keyfile" = "${config.security.acme.certs.${amqpHost}.directory}/key.pem";
|
|
|
|
};
|
|
|
|
};
|
2024-07-08 21:55:11 +00:00
|
|
|
|
2024-10-28 14:38:29 +00:00
|
|
|
security.acme.certs.${amqpHost} = {
|
|
|
|
webroot = "/var/lib/acme/.challenges";
|
|
|
|
group = "rabbitmq";
|
|
|
|
};
|
|
|
|
services.nginx.virtualHosts.${amqpHost}.locations."/.well-known/acme-challenge".root =
|
|
|
|
"/var/lib/acme/.challenges";
|
|
|
|
systemd.services.rabbitmq.requires = ["acme-finished-${amqpHost}.target"];
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [ amqpPort ];
|
|
|
|
})
|
2024-11-14 18:27:11 +00:00
|
|
|
(mkIf cfg.pastebin.enable {
|
|
|
|
systemd.services.ofborg-pastebin = mkOfborgWorker "pastebin-worker" { };
|
|
|
|
})
|
2024-11-14 22:05:23 +00:00
|
|
|
(mkIf cfg.statcheck-worker.enable {
|
|
|
|
systemd.services.ofborg-statcheck-worker = mkOfborgWorker "statcheck-worker" { };
|
|
|
|
})
|
2024-11-14 22:04:42 +00:00
|
|
|
(mkIf cfg.gerrit-events-streamer.enable {
|
|
|
|
systemd.services.ofborg-gerrit-streamer = mkOfborgWorker "gerrit-events-streamer" { };
|
|
|
|
})
|
2024-11-14 17:53:51 +00:00
|
|
|
(mkIf cfg.mass-rebuilder.enable {
|
|
|
|
systemd.services.ofborg-mass-rebuilder = mkOfborgWorker "mass-rebuilder" { };
|
|
|
|
})
|
2024-10-28 14:38:29 +00:00
|
|
|
(mkIf cfg.builder.enable {
|
|
|
|
systemd.services.ofborg-builder = mkOfborgWorker "builder" { };
|
|
|
|
})
|
2024-10-28 17:12:41 +00:00
|
|
|
(mkIf cfg.stats.enable {
|
|
|
|
systemd.services.ofborg-stats = mkOfborgWorker "stats" { };
|
|
|
|
})
|
2024-10-28 14:38:29 +00:00
|
|
|
];
|
|
|
|
# systemd.services.ofborg-log-message-collector = {};
|
|
|
|
# systemd.services.ofborg-evaluation-filter = {};
|
|
|
|
# systemd.services.ofborg-vcs-comment-filter = {};
|
|
|
|
# systemd.services.ofborg-vcs-comment-poster = {};
|
2024-07-08 21:55:11 +00:00
|
|
|
}
|