Vendor buildbot from the nixpkgs input (nixpkgs-unstable-small)

Signed-off-by: magic_rb <richard@brezak.sk>
This commit is contained in:
magic_rb 2024-07-12 12:47:18 +02:00 committed by mergify[bot]
parent fade46ad70
commit 4b8c544db8
4 changed files with 258 additions and 200 deletions

View file

@ -25,6 +25,33 @@ separate machines. To support multiple architectures, configure them as
For a practical NixOS example, see
[this remote builder configuration](https://github.com/Mic92/dotfiles/blob/main/nixos/eve/modules/remote-builder.nix).
## Using `buildbot` with NixOS 24.05 (stable release)
The module applies custom patches that only apply to buildbot > 4.0.0. To use
buildbot-nix with NixOS 24.05, you should therefore not override the nixpkgs
input to your own stable version of buildbot-nix and leave it to the default
instead that is set to nixos-unstable-small.
So instead of using this in your flake
```
inputs = {
buildbot-nix.url = "github:nix-community/buildbot-nix";
buildbot-nix.inputs.nixpkgs.follows = "nixpkgs";
};
```
Just use:
```
inputs = {
buildbot-nix.url = "github:nix-community/buildbot-nix";
};
```
An alternative is to point nixpkgs to your own version of nixpkgs-unstable in
case you are already using it elsewhere.
## Using Buildbot in Your Project
Buildbot-nix automatically triggers builds for your project under these

View file

@ -20,8 +20,8 @@
] ++ inputs.nixpkgs.lib.optional (inputs.treefmt-nix ? flakeModule) ./nix/treefmt/flake-module.nix;
systems = [ "x86_64-linux" ];
flake = {
nixosModules.buildbot-master = ./nix/master.nix;
nixosModules.buildbot-worker = ./nix/worker.nix;
nixosModules.buildbot-master = import ./nix/master.nix inputs;
nixosModules.buildbot-worker = import ./nix/worker.nix inputs;
nixosConfigurations =
let

View file

@ -1,3 +1,4 @@
{ nixpkgs, ... }:
{ config
, pkgs
, lib
@ -8,6 +9,7 @@ let
inherit (lib) mkRemovedOptionModule mkRenamedOptionModule;
in
{
_file = ./master.nix;
imports = [
(mkRenamedOptionModule
[
@ -57,8 +59,17 @@ in
];
options = {
services.buildbot-nix.vendorBuildbot = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Whether to vendow `buildbot-master` from the `nixpkgs` input of the `buildbot-nix` flake.
`buildbot-nix` requires `buildbot-master` to be at least of version `4`.
'';
};
services.buildbot-nix.master = {
enable = lib.mkEnableOption "buildbot-master";
package = lib.mkPackageOption pkgs "buildbot" { };
dbUrl = lib.mkOption {
type = lib.types.str;
default = "postgresql://@/buildbot";
@ -263,7 +274,16 @@ in
};
};
};
config = lib.mkIf cfg.enable {
config = lib.mkMerge [
(lib.mkIf config.services.buildbot-nix.vendorBuildbot {
nixpkgs.overlays = [
(final: prev:
{
buildbotPackages = prev.python3.pkgs.callPackage "${nixpkgs}/pkgs/development/tools/continuous-integration/buildbot" { };
})
];
})
(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.
@ -274,6 +294,11 @@ in
};
assertions = [
{
assertion =
lib.versionAtLeast cfg.package.version "4.0.0";
message = "`buildbot-nix` requires `buildbot` 4.0.0 or greater to function";
}
{
assertion =
cfg.cachix.name != null -> cfg.cachix.signingKeyFile != null || cfg.cachix.authTokenFile != null;
@ -384,7 +409,7 @@ in
in
"${if hasSSL then "https" else "http"}://${cfg.domain}/";
dbUrl = config.services.buildbot-nix.master.dbUrl;
package = pkgs.buildbot;
package = cfg.package;
pythonPackages = ps: [
ps.requests
ps.treq
@ -392,7 +417,7 @@ in
(ps.toPythonModule pkgs.buildbot-worker)
pkgs.buildbot-plugins.www-react
(pkgs.python3.pkgs.callPackage ../default.nix { })
(pkgs.python3.pkgs.callPackage ./buildbot-gitea.nix { buildbot = pkgs.buildbot; })
(pkgs.python3.pkgs.callPackage ./buildbot-gitea.nix { buildbot = cfg.package; })
];
};
@ -468,5 +493,6 @@ in
++ lib.optional (cfg.outputsPath != null)
# Allow buildbot-master to write to this directory
"d ${cfg.outputsPath} 0755 buildbot buildbot - -";
};
})
];
}

View file

@ -1,3 +1,4 @@
{ ... }:
{ config
, pkgs
, lib
@ -10,6 +11,7 @@ let
python = cfg.package.pythonModule;
in
{
_file = ./worker.nix;
options = {
services.buildbot-nix.worker = {
enable = lib.mkEnableOption "buildbot-worker";
@ -86,7 +88,10 @@ in
# Restart buildbot with a delay. This time way we can use buildbot to deploy itself.
ExecReload = "+${config.systemd.package}/bin/systemd-run --on-active=60 ${config.systemd.package}/bin/systemctl restart buildbot-worker";
ExecStart = "${python.pkgs.twisted}/bin/twistd --nodaemon --pidfile= --logfile - --python ${../buildbot_nix}/worker.py";
ExecStart = lib.traceIf
(lib.versionOlder pkgs.buildbot-worker.version "4.0.0")
"`buildbot-nix` recommends `buildbot-worker` to be at least of version `4.0.0`"
"${python.pkgs.twisted}/bin/twistd --nodaemon --pidfile= --logfile - --python ${../buildbot_nix}/worker.py";
};
};
};