Skip to content

Commit 4f6d08a

Browse files
MagicRBMic92
authored andcommitted
Improve Nix code and docs
Signed-off-by: magic_rb <richard@brezak.sk>
1 parent 475fbf3 commit 4f6d08a

File tree

4 files changed

+53
-29
lines changed

4 files changed

+53
-29
lines changed

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,32 @@ We have the following two roles:
6666

6767
### Integration with GitHub
6868

69-
To integrate with GitHub:
69+
#### GitHub App
70+
71+
To integrate with GitHub using app authentication:
72+
73+
1. **GitHub App**: Set up a GitHub app for Buildbot to enable GitHub user
74+
authentication on the Buildbot dashboard.
75+
2. **GitHub App private key**: Get the app private key and app ID from GitHub,
76+
configure using the buildbot-nix NixOS module.
77+
3. **Install App**: Install the for an organization or specific user.
78+
4. **Refresh GitHub Projects**: Currently buildbot-nix doesn't respond to
79+
changes (new repositories or installations) automatically, it is therefore
80+
necessary to manually trigger a reload or wait for the next periodic reload.
81+
82+
#### Legacy Token Auth
83+
84+
To integrate with GitHub using legacy token authentication:
7085

7186
1. **GitHub Token**: Obtain a GitHub token with `admin:repo_hook` and `repo`
7287
permissions. For GitHub organizations, it's advisable to create a separate
7388
GitHub user for managing repository webhooks.
7489

75-
#### Optional when using GitHub login
90+
### Optional when using GitHub login
7691

7792
1. **GitHub App**: Set up a GitHub app for Buildbot to enable GitHub user
78-
authentication on the Buildbot dashboard.
93+
authentication on the Buildbot dashboard. (can be the same as for GitHub App
94+
auth)
7995
2. **OAuth Credentials**: After installing the app, generate OAuth credentials
8096
and configure them in the buildbot-nix NixOS module. Set the callback url to
8197
`https://<your-domain>/auth/login`.

examples/master.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@
2222
# Github user used as a CI identity
2323
user = "mic92-buildbot";
2424
authType.legacy = {
25-
enable = true;
2625
# Github token of the same user
2726
tokenFile = pkgs.writeText "github-token" "ghp_000000000000000000000000000000000000"; # FIXME: replace this with a secret not stored in the nix store
2827
};
28+
# authType.app = {
29+
# id = "00000000000000000"; # FIXME: replace with App ID obtained from GitHub
30+
# secretKeyFile = pkgs.writeText "app-secret.key" "00000000000000000000"; # FIXME: replace with App secret key obtained from GitHub
31+
# };
2932
# A random secret used to verify incoming webhooks from GitHub
3033
# buildbot-nix will set up a webhook for each project in the organization
3134
webhookSecretFile = pkgs.writeText "webhookSecret" "00000000000000000000"; # FIXME: replace this with a secret not stored in the nix store

nix/checks/master.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
admins = [ "Mic92" ];
1818
github = {
1919
authType.legacy = {
20-
enable = true;
2120
tokenFile = pkgs.writeText "github-token" "ghp_000000000000000000000000000000000000";
2221
};
2322
webhookSecretFile = pkgs.writeText "webhookSecret" "00000000000000000000";

nix/master.nix

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,29 +124,35 @@ in
124124
default = cfg.authBackend == "github";
125125
};
126126

127-
authType = {
128-
legacy = {
129-
enable = lib.mkEnableOption "";
130-
tokenFile = lib.mkOption {
131-
type = lib.types.path;
132-
description = "Github token file";
127+
authType = lib.mkOption {
128+
type = lib.types.attrTag {
129+
legacy = lib.mkOption {
130+
description = "GitHub legacy auth backend";
131+
type = lib.types.submodule {
132+
options.tokenFile = lib.mkOption {
133+
type = lib.types.path;
134+
description = "Github token file";
135+
};
136+
};
133137
};
134-
};
135138

136-
app = {
137-
enable = lib.mkEnableOption "";
138-
id = lib.mkOption {
139-
type = lib.types.int;
140-
description = ''
141-
GitHub app ID.
142-
'';
143-
};
139+
app = lib.mkOption {
140+
description = "GitHub legacy auth backend";
141+
type = lib.types.submodule {
142+
options.id = lib.mkOption {
143+
type = lib.types.int;
144+
description = ''
145+
GitHub app ID.
146+
'';
147+
};
144148

145-
secretKeyFile = lib.mkOption {
146-
type = lib.types.str;
147-
description = ''
148-
GitHub app secret key file location.
149-
'';
149+
options.secretKeyFile = lib.mkOption {
150+
type = lib.types.str;
151+
description = ''
152+
GitHub app secret key file location.
153+
'';
154+
};
155+
};
150156
};
151157
};
152158
};
@@ -311,9 +317,9 @@ in
311317
buildbot_user=${builtins.toJSON cfg.github.user},
312318
topic=${builtins.toJSON cfg.github.topic},
313319
auth_type=${
314-
if cfg.github.authType.legacy.enable then
320+
if cfg.github.authType ? "legacy" then
315321
''AuthTypeLegacy()''
316-
else if cfg.github.authType.app.enable then
322+
else if cfg.github.authType ? "app" then
317323
''
318324
AuthTypeApp(
319325
app_id=${toString cfg.github.authType.app.id},
@@ -405,10 +411,10 @@ in
405411
++ lib.optionals (cfg.github.enable) ([
406412
"github-webhook-secret:${cfg.github.webhookSecretFile}"
407413
]
408-
++ lib.optionals (cfg.github.authType.legacy.enable) [
414+
++ lib.optionals (cfg.github.authType ? "legacy") [
409415
"github-token:${cfg.github.authType.legacy.tokenFile}"
410416
]
411-
++ lib.optionals (cfg.github.authType.app.enable) [
417+
++ lib.optionals (cfg.github.authType ? "app") [
412418
"github-app-secret-key:${cfg.github.authType.app.secretKeyFile}"
413419
])
414420
++ lib.optionals cfg.gitea.enable [

0 commit comments

Comments
 (0)