|
49 | 49 | { |
50 | 50 | meta.maintainers = teams.forgejo.members; |
51 | 51 |
|
52 | | - imports = [ |
53 | | - (mkRenamedOptionModule [ "services" "forgejo-runner" ] [ "services" "forgejo" "runner" ]) |
54 | | - ]; |
55 | | - |
56 | 52 | options.services.forgejo.runner = with types; { |
57 | 53 | package = mkPackageOption pkgs "forgejo-runner" { }; |
58 | 54 |
|
|
78 | 74 | }; |
79 | 75 |
|
80 | 76 | url = mkOption { |
81 | | - type = str; |
| 77 | + type = nullOr str; |
| 78 | + default = null; |
82 | 79 | example = "https://forge.example.com"; |
83 | 80 | description = '' |
84 | 81 | Base URL of your Forgejo instance. |
| 82 | +
|
| 83 | + Can also be specified in `settings.servier.connections` |
85 | 84 | ''; |
86 | 85 | }; |
87 | 86 |
|
88 | | - tokenFile = mkOption { |
| 87 | + registrationTokenFile = mkOption { |
89 | 88 | type = nullOr (either str path); |
90 | 89 | default = null; |
91 | 90 | description = '' |
92 | 91 | 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. |
94 | 109 | ''; |
95 | 110 | }; |
96 | 111 |
|
97 | 112 | labels = mkOption { |
98 | | - type = listOf str; |
| 113 | + type = nullOr (listOf str); |
99 | 114 | example = literalExpression '' |
100 | 115 | [ |
101 | 116 | # provide a debian base with nodejs for actions |
|
170 | 185 | assertion = wantsContainerRuntime -> hasDocker || hasPodman; |
171 | 186 | message = "Label configuration on forgejo.runner instance requires either docker or podman."; |
172 | 187 | } |
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); |
174 | 199 |
|
175 | 200 | systemd.services = |
176 | 201 | let |
|
208 | 233 | serviceConfig = { |
209 | 234 | MemoryDenyWriteExecute = !wantsHost; |
210 | 235 |
|
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; |
212 | 241 |
|
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) [ |
214 | 246 | (lib.getExe ( |
215 | 247 | pkgs.writeShellApplication { |
216 | 248 | name = "forgejo-register-runner-${escapedName}"; |
|
230 | 262 | ${cfg.package}/bin/forgejo-runner register \ |
231 | 263 | --no-interactive \ |
232 | 264 | --instance ${escapeShellArg instance.url} \ |
233 | | - --token "$(cat "$CREDENTIALS_DIRECTORY/TOKEN")" \ |
| 265 | + --token "$(cat "$CREDENTIALS_DIRECTORY/REGISTRATION_TOKEN")" \ |
234 | 266 | --name ${escapeShellArg instance.name} \ |
235 | 267 | --labels ${escapeShellArg (concatStringsSep "," instance.labels)} \ |
236 | 268 | --config ${configFile} |
|
241 | 273 | } |
242 | 274 | )) |
243 | 275 | ]; |
| 276 | + |
244 | 277 | 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}" ]; |
247 | 278 | }; |
248 | 279 | }; |
249 | 280 | in |
|
0 commit comments