Skip to content

Commit 15dfc39

Browse files
committed
nixos/forgejo.runner: rename registration token and make optional
1 parent 24a1a80 commit 15dfc39

2 files changed

Lines changed: 46 additions & 15 deletions

File tree

nixos/modules/services/continuous-integration/forgejo-runner.nix

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ in
4949
{
5050
meta.maintainers = teams.forgejo.members;
5151

52-
imports = [
53-
(mkRenamedOptionModule [ "services" "forgejo-runner" ] [ "services" "forgejo" "runner" ])
54-
];
55-
5652
options.services.forgejo.runner = with types; {
5753
package = mkPackageOption pkgs "forgejo-runner" { };
5854

@@ -78,24 +74,43 @@ in
7874
};
7975

8076
url = mkOption {
81-
type = str;
77+
type = nullOr str;
78+
default = null;
8279
example = "https://forge.example.com";
8380
description = ''
8481
Base URL of your Forgejo instance.
82+
83+
Can also be specified in `settings.servier.connections`
8584
'';
8685
};
8786

88-
tokenFile = mkOption {
87+
registrationTokenFile = mkOption {
8988
type = nullOr (either str path);
9089
default = null;
9190
description = ''
9291
Path to a file containing only the token that will be used to register
93-
with the the configured Forgejo instance.
92+
on start with the the configured Forgejo instance.
93+
94+
**Deprecated** Replaced by `settings.server.connections`
95+
96+
<https://forgejo.org/docs/latest/admin/actions/registration/>
97+
'';
98+
};
99+
100+
credentials = lib.mkOption {
101+
type = attrsOf lib.types.path;
102+
default = { };
103+
example = {
104+
WORKER1_TOKEN = "/run/keys/worker1";
105+
};
106+
description = ''
107+
Environment variables with absolute paths to credentials files to load
108+
on runner startup.
94109
'';
95110
};
96111

97112
labels = mkOption {
98-
type = listOf str;
113+
type = nullOr (listOf str);
99114
example = literalExpression ''
100115
[
101116
# provide a debian base with nodejs for actions
@@ -170,7 +185,17 @@ in
170185
assertion = wantsContainerRuntime -> hasDocker || hasPodman;
171186
message = "Label configuration on forgejo.runner instance requires either docker or podman.";
172187
}
173-
];
188+
]
189+
++ (lib.foldlAttrs (
190+
acc: _: instance:
191+
acc
192+
++ [
193+
{
194+
assertion = instance.registrationTokenFile != null -> instance.url != null;
195+
message = "forgejo.runner.instances.${instance.name}.registrationTokenFile requires `url` to be set.";
196+
}
197+
]
198+
) [ ] cfg.instances);
174199

175200
systemd.services =
176201
let
@@ -208,9 +233,16 @@ in
208233
serviceConfig = {
209234
MemoryDenyWriteExecute = !wantsHost;
210235

211-
LoadCredential = [ "TOKEN:${instance.tokenFile}" ];
236+
LoadCredential =
237+
lib.optionals (instance.registrationTokenFile != null) [
238+
"REGISTRATION_TOKEN:${instance.registrationTokenFile}"
239+
]
240+
++ lib.mapAttrsToList (name: value: "${name}:${value}") instance.credentials;
212241

213-
ExecStartPre = [
242+
SupplementaryGroups = optionals wantsDocker [ "docker" ] ++ optionals wantsPodman [ "podman" ];
243+
ExecPaths = lib.optionals wantsHost [ "/var/lib/forgejo-runner/${escapedName}" ];
244+
245+
ExecStartPre = lib.optionals (instance.registrationTokenFile != null) [
214246
(lib.getExe (
215247
pkgs.writeShellApplication {
216248
name = "forgejo-register-runner-${escapedName}";
@@ -230,7 +262,7 @@ in
230262
${cfg.package}/bin/forgejo-runner register \
231263
--no-interactive \
232264
--instance ${escapeShellArg instance.url} \
233-
--token "$(cat "$CREDENTIALS_DIRECTORY/TOKEN")" \
265+
--token "$(cat "$CREDENTIALS_DIRECTORY/REGISTRATION_TOKEN")" \
234266
--name ${escapeShellArg instance.name} \
235267
--labels ${escapeShellArg (concatStringsSep "," instance.labels)} \
236268
--config ${configFile}
@@ -241,9 +273,8 @@ in
241273
}
242274
))
243275
];
276+
244277
ExecStart = lib.mkForce "${cfg.package}/bin/forgejo-runner daemon --config ${configFile}";
245-
SupplementaryGroups = optionals wantsDocker [ "docker" ] ++ optionals wantsPodman [ "podman" ];
246-
ExecPaths = lib.optionals wantsHost [ "/var/lib/forgejo-runner/${escapedName}" ];
247278
};
248279
};
249280
in

nixos/tests/forgejo.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ let
7272
# type ":host" does not depend on docker/podman/lxc
7373
"native:host"
7474
];
75-
tokenFile = "/var/lib/forgejo/runner_token";
75+
registrationTokenFile = "/var/lib/forgejo/runner_token";
7676
};
7777
};
7878
};

0 commit comments

Comments
 (0)