Skip to content

Commit 75e99ac

Browse files
committed
nixos/forgejo.runner: make top-level labels optional
1 parent a9232b8 commit 75e99ac

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
let
1010
inherit (lib)
1111
any
12-
attrValues
1312
concatStringsSep
1413
escapeShellArg
1514
hasInfix
@@ -20,7 +19,6 @@ let
2019
mkIf
2120
mkOption
2221
mkPackageOption
23-
mkRenamedOptionModule
2422
nameValuePair
2523
optionalAttrs
2624
optionals
@@ -36,12 +34,19 @@ let
3634

3735
settingsFormat = pkgs.formats.yaml { };
3836

39-
# Empty label strings result in upstream default labels, which require docker.
40-
hasDockerScheme =
41-
instance: instance.labels == [ ] || any (label: hasInfix ":docker:" label) instance.labels;
42-
wantsContainerRuntime = any hasDockerScheme (attrValues cfg.instances);
37+
instanceLabels =
38+
instance:
39+
instance.labels
40+
++ lib.concatMap (connection: connection.labels or [ ]) (
41+
lib.attrValues (instance.settings.server.connections or { })
42+
);
4343

44-
hasHostScheme = instance: any (label: hasSuffix ":host" label) instance.labels;
44+
hasDockerScheme = labels: any (label: hasInfix ":docker:" label) labels;
45+
hasHostScheme = labels: any (label: hasSuffix ":host" label) labels;
46+
47+
wantsContainerRuntime = any (instance: hasDockerScheme (instanceLabels instance)) (
48+
lib.attrValues cfg.instances
49+
);
4550

4651
hasDocker = config.virtualisation.docker.enable;
4752
hasPodman = config.virtualisation.podman.enable;
@@ -110,7 +115,8 @@ in
110115
};
111116

112117
labels = mkOption {
113-
type = nullOr (listOf str);
118+
type = listOf str;
119+
default = [ ];
114120
example = literalExpression ''
115121
[
116122
# provide a debian base with nodejs for actions
@@ -202,9 +208,10 @@ in
202208
mkRunnerInstance =
203209
_: instance:
204210
let
211+
allLabels = instanceLabels instance;
205212
escapedName = escapeSystemdPath instance.name;
206-
wantsContainer = hasDockerScheme instance;
207-
wantsHost = hasHostScheme instance;
213+
wantsContainer = hasDockerScheme allLabels;
214+
wantsHost = hasHostScheme allLabels;
208215
wantsDocker = wantsContainer && hasDocker;
209216
wantsPodman = wantsContainer && hasPodman;
210217
configFile = settingsFormat.generate "forgejo-runner-${escapedName}.yaml" instance.settings;

0 commit comments

Comments
 (0)