2023-09-10 08:11:56 +00:00
|
|
|
# Buildbot-nix
|
|
|
|
|
2023-12-24 07:12:42 +00:00
|
|
|
Buildbot-nix is a NixOS module designed to integrate
|
|
|
|
[Buildbot](https://www.buildbot.net/), a continuous integration (CI) framework,
|
|
|
|
into the Nix ecosystem. This module is under active development, and while it's
|
|
|
|
generally stable and widely used, please be aware that some APIs may change over
|
|
|
|
time.
|
2023-09-10 08:11:56 +00:00
|
|
|
|
2023-12-24 07:12:42 +00:00
|
|
|
## Getting Started with Buildbot Setup
|
2023-09-14 09:11:10 +00:00
|
|
|
|
2023-12-24 07:12:42 +00:00
|
|
|
To set up Buildbot using Buildbot-nix, you can start by exploring the provided
|
|
|
|
examples:
|
2023-11-05 05:45:16 +00:00
|
|
|
|
2023-12-24 07:12:42 +00:00
|
|
|
- Check out the basic setup in [example](./examples/default.nix).
|
|
|
|
- Learn about configuring the Buildbot master in
|
|
|
|
[master module](./nix/master.nix).
|
|
|
|
- Understand how to set up a Buildbot worker in
|
|
|
|
[worker module](./nix/worker.nix).
|
2023-11-05 05:45:16 +00:00
|
|
|
|
2023-12-24 07:12:42 +00:00
|
|
|
Additionally, you can find real-world examples at the end of this document.
|
2023-11-05 05:45:16 +00:00
|
|
|
|
2023-12-24 07:12:42 +00:00
|
|
|
Buildbot masters and workers can be deployed either on the same machine or on
|
|
|
|
separate machines. To support multiple architectures, configure them as
|
|
|
|
[nix remote builders](https://nixos.org/manual/nix/stable/advanced-topics/distributed-builds).
|
|
|
|
For a practical NixOS example, see
|
|
|
|
[this remote builder configuration](https://github.com/Mic92/dotfiles/blob/main/nixos/eve/modules/remote-builder.nix).
|
2023-11-05 05:45:16 +00:00
|
|
|
|
2023-12-24 07:12:42 +00:00
|
|
|
## Using Buildbot in Your Project
|
2023-11-05 05:45:16 +00:00
|
|
|
|
2023-12-24 07:12:42 +00:00
|
|
|
Buildbot-nix automatically triggers builds for your project under these
|
|
|
|
conditions:
|
2023-11-05 05:45:16 +00:00
|
|
|
|
2023-12-24 07:12:42 +00:00
|
|
|
- When a pull request is opened.
|
|
|
|
- When a commit is pushed to the default git branch.
|
2023-11-05 05:45:16 +00:00
|
|
|
|
2023-12-24 07:12:42 +00:00
|
|
|
It does this by evaluating the `.#checks` attribute of your project's flake in
|
|
|
|
parallel. Each attribute found results in a separate build step. You can test
|
|
|
|
these builds locally using `nix flake check -L` or
|
|
|
|
[nix-fast-build](https://github.com/Mic92/nix-fast-build).
|
2023-11-05 05:45:16 +00:00
|
|
|
|
2023-12-24 07:12:42 +00:00
|
|
|
If you need to build other parts of your flake, such as packages or NixOS
|
|
|
|
machines, you should re-export these into the `.#checks` output. Here are two
|
|
|
|
examples to guide you:
|
|
|
|
|
|
|
|
- Using
|
|
|
|
[flake-parts](https://github.com/Mic92/dotfiles/blob/10890601a02f843b49fe686d7bc19cb66a04e3d7/flake.nix#L139).
|
|
|
|
- A
|
|
|
|
[plain flake example](https://github.com/nix-community/nixos-images/blob/56b52791312edeade1e6bd853ce56c778f363d50/flake.nix#L53).
|
|
|
|
|
2024-05-04 21:50:19 +00:00
|
|
|
### Authentication backend
|
|
|
|
|
|
|
|
At the moment all projects are visible without authentication.
|
|
|
|
|
|
|
|
For some actions a login is required. This login can either be based on GitHub
|
|
|
|
or on Gitea (more logins may follow). The backend is set by the
|
2024-06-25 14:43:50 +00:00
|
|
|
`services.buildbot-nix.master.authBackend` NixOS option ("gitea"/"github",
|
|
|
|
"github" by default).
|
2023-12-24 07:12:42 +00:00
|
|
|
|
2024-05-04 21:50:19 +00:00
|
|
|
We have the following two roles:
|
|
|
|
|
|
|
|
- Admins:
|
|
|
|
- The list of admin usernames is hard-coded in the NixOS configuration.
|
|
|
|
- admins can reload the project list
|
|
|
|
- Organisation member:
|
|
|
|
- All member of the organisation where this repository is located
|
|
|
|
- They can restart builds
|
|
|
|
|
|
|
|
### Integration with GitHub
|
2023-12-24 07:12:42 +00:00
|
|
|
|
2024-06-15 13:22:22 +00:00
|
|
|
#### GitHub App
|
2024-06-13 10:50:23 +00:00
|
|
|
|
2024-06-25 14:29:14 +00:00
|
|
|
This is the preferred option to setup buildbot-nix for GitHub.
|
2024-06-02 14:13:38 +00:00
|
|
|
|
|
|
|
To integrate with GitHub using app authentication:
|
|
|
|
|
2024-06-25 14:29:14 +00:00
|
|
|
1. **GitHub App**:
|
2024-06-25 14:43:50 +00:00
|
|
|
1. Create a new GitHub app by navigating to
|
|
|
|
`https://github.com/settings/apps/new` for single-user installations or
|
|
|
|
`https://github.com/organizations/<org>/settings/apps/new` for
|
|
|
|
organisations where `<org>` is the name of your GitHub organizaction.
|
|
|
|
2. GitHub App Name: "buildbox-nix <org>"
|
|
|
|
3. Homepage URL: `https://buildbot.<your-domain>`
|
|
|
|
4. Callback URL: `https://buildbot.<your-domain>/auth/login`.
|
|
|
|
5. Disable the Webhook
|
|
|
|
6. Repository Permissions:
|
|
|
|
- Contents: Read-only
|
|
|
|
- Commit statuses: Read and write
|
|
|
|
- Metadata: Read-only
|
|
|
|
- Webhooks: Read and write
|
2024-07-05 12:45:11 +00:00
|
|
|
7. Organisation Permissions (only if you create this app for an
|
|
|
|
organisation):
|
|
|
|
- Members: Read-only
|
2024-06-02 14:13:38 +00:00
|
|
|
2. **GitHub App private key**: Get the app private key and app ID from GitHub,
|
|
|
|
configure using the buildbot-nix NixOS module.
|
2024-06-25 14:43:50 +00:00
|
|
|
- Set
|
|
|
|
`services.buildbot-nix.master.github.authType.app.id = <your-github-id>;`
|
|
|
|
- Set
|
|
|
|
`services.buildbot-nix.master.github.authType.app.secretKeyFile = "/path/to.pem";`
|
2024-06-07 08:08:12 +00:00
|
|
|
3. **Install App**: Install the app for an organization or specific user.
|
2024-06-02 14:13:38 +00:00
|
|
|
4. **Refresh GitHub Projects**: Currently buildbot-nix doesn't respond to
|
|
|
|
changes (new repositories or installations) automatically, it is therefore
|
|
|
|
necessary to manually trigger a reload or wait for the next periodic reload.
|
|
|
|
|
2024-06-15 13:22:22 +00:00
|
|
|
#### Token Auth
|
|
|
|
|
|
|
|
To integrate with GitHub using legacy token authentication:
|
|
|
|
|
|
|
|
1. **GitHub Token**: Obtain a GitHub token with `admin:repo_hook` and `repo`
|
|
|
|
permissions. For GitHub organizations, it's advisable to create a separate
|
|
|
|
GitHub user for managing repository webhooks.
|
|
|
|
|
2024-06-02 14:13:38 +00:00
|
|
|
### Optional when using GitHub login
|
2024-05-04 21:50:19 +00:00
|
|
|
|
2023-12-24 07:12:42 +00:00
|
|
|
1. **GitHub App**: Set up a GitHub app for Buildbot to enable GitHub user
|
2024-06-02 14:13:38 +00:00
|
|
|
authentication on the Buildbot dashboard. (can be the same as for GitHub App
|
|
|
|
auth)
|
2023-12-24 07:12:42 +00:00
|
|
|
2. **OAuth Credentials**: After installing the app, generate OAuth credentials
|
2024-04-15 13:28:27 +00:00
|
|
|
and configure them in the buildbot-nix NixOS module. Set the callback url to
|
|
|
|
`https://<your-domain>/auth/login`.
|
2024-05-04 21:50:19 +00:00
|
|
|
|
|
|
|
Afterwards add the configured github topic to every project that should build
|
|
|
|
with buildbot-nix. Notice that the buildbot user needs to have admin access to
|
|
|
|
this repository because it needs to install a webhook.
|
|
|
|
|
|
|
|
### Integration with Gitea
|
|
|
|
|
|
|
|
To integrate with Gitea
|
|
|
|
|
2024-05-04 21:55:24 +00:00
|
|
|
1. **Gitea Token** Obtain a Gitea token with the following permissions
|
|
|
|
`write:repository` and `write:user` permission. For Gitea organizations, it's
|
|
|
|
advisable to create a separate Gitea user. Buildbot-nix will use this token
|
|
|
|
to automatically setup a webhook in the repository.
|
|
|
|
2. **Gitea App**: (optional). This is optional, when using GitHub as the
|
|
|
|
authentication backend for buildbot. Set up a OAuth2 app for Buildbot in the
|
|
|
|
Applications section. This can be done in the global "Site adminstration"
|
|
|
|
settings (only available for admins) or in a Gitea organisation or in your
|
|
|
|
personal settings. As redirect url set
|
|
|
|
`https://buildbot.your-buildbot-domain.com/auth/login`, where
|
|
|
|
`buildbot.your-buildbot-domain.com` should be replaced with the actual domain
|
|
|
|
that your buildbot is running on.
|
|
|
|
|
|
|
|
Afterwards add the configured gitea topic to every project that should build
|
|
|
|
with buildbot-nix. Notice that the buildbot user needs to have repository write
|
|
|
|
access to this repository because it needs to install a webhook in the
|
|
|
|
repository.
|
2023-12-24 07:12:42 +00:00
|
|
|
|
2024-05-11 08:29:09 +00:00
|
|
|
## Binary caches
|
2024-04-23 16:48:36 +00:00
|
|
|
|
2024-04-29 11:27:35 +00:00
|
|
|
To access the build results on other machines there are two options at the
|
|
|
|
moment
|
2024-04-23 16:48:36 +00:00
|
|
|
|
|
|
|
#### Local binary cache (harmonia)
|
|
|
|
|
2024-04-29 11:27:35 +00:00
|
|
|
You can set up a binary cache on your buildbot-worker machine to make its nix
|
|
|
|
store accessible from other machines. Check out the README of the
|
|
|
|
[project](https://github.com/nix-community/harmonia/?tab=readme-ov-file#configuration-for-public-binary-cache-on-nixos),
|
2024-04-23 16:48:36 +00:00
|
|
|
for an example configuration
|
|
|
|
|
|
|
|
#### Cachix
|
|
|
|
|
2024-04-29 11:27:35 +00:00
|
|
|
Buildbot-nix also supports pushing packages to cachix. Check out the comment out
|
|
|
|
[example configuration](https://github.com/Mic92/buildbot-nix/blob/main/examples/master.nix)
|
2024-04-23 16:48:36 +00:00
|
|
|
in our repository.
|
|
|
|
|
2024-06-14 09:38:45 +00:00
|
|
|
#### Attic
|
|
|
|
|
|
|
|
Buildbot-nix does not have native support for pushing packages to
|
|
|
|
[attic](https://github.com/zhaofengli/attic) yet. However it's possible to
|
|
|
|
integrate run a systemd service as described in
|
|
|
|
[this example configuration](./examples/attic-watch-store.nix). The systemd
|
|
|
|
service watches for changes in the local buildbot-nix store and uploads the
|
|
|
|
contents to the attic cache.
|
|
|
|
|
2024-05-11 08:29:09 +00:00
|
|
|
## Real-World Deployments
|
2023-12-24 07:12:42 +00:00
|
|
|
|
|
|
|
See Buildbot-nix in action in these deployments:
|
|
|
|
|
2024-05-04 21:53:43 +00:00
|
|
|
The following instances run on GitHub:
|
|
|
|
|
2024-06-12 07:49:39 +00:00
|
|
|
- [**Nix-community infra**](https://nix-community.org/):
|
2023-12-24 07:12:42 +00:00
|
|
|
[Configuration](https://github.com/nix-community/infra/tree/master/modules/nixos)
|
|
|
|
| [Instance](https://buildbot.nix-community.org/)
|
2024-06-12 07:49:39 +00:00
|
|
|
- [**Mic92's dotfiles**](https://github.com/Mic92/dotfiles):
|
2023-12-24 07:12:42 +00:00
|
|
|
[Configuration](https://github.com/Mic92/dotfiles/blob/main/nixos/eve/modules/buildbot.nix)
|
|
|
|
| [Instance](https://buildbot.thalheim.io/)
|
2024-06-12 07:49:39 +00:00
|
|
|
- [**Technical University Munich**](https://dse.in.tum.de/):
|
2023-12-24 07:12:42 +00:00
|
|
|
[Configuration](https://github.com/TUM-DSE/doctor-cluster-config/tree/master/modules/buildbot)
|
|
|
|
| [Instance](https://buildbot.dse.in.tum.de/)
|
2024-06-12 07:49:39 +00:00
|
|
|
- [**Numtide**](https://numtide.com/): [Instance](https://buildbot.numtide.com)
|
|
|
|
- [**Ngi0**](https://www.ngi.eu/ngi-projects/ngi-zero/):
|
|
|
|
[Instance](https://buildbot.ngi.nixos.org/#/projects)
|
2024-05-04 21:53:43 +00:00
|
|
|
|
|
|
|
The following instances integrated with Gitea:
|
|
|
|
|
|
|
|
- **Clan infra**:
|
|
|
|
[Configuration](https://git.clan.lol/clan/clan-infra/src/branch/main/modules/buildbot.nix)
|
|
|
|
| [Instance](https://buildbot.clan.lol/)
|
2024-05-11 08:29:09 +00:00
|
|
|
|
|
|
|
## Get in touch
|
|
|
|
|
2024-05-16 22:43:09 +00:00
|
|
|
We have a matrix channel at
|
|
|
|
[buildbot-nix](https://matrix.to/#/#buildbot-nix:thalheim.io).
|