about summary refs log tree commit diff
path: root/nixos/modules/services/continuous-integration
diff options
context:
space:
mode:
authorVincent Haupert <vincent@yaxi.tech>2024-01-22 13:29:45 +0100
committerVincent Haupert <vincent@yaxi.tech>2024-02-09 15:14:32 +0100
commita9c807496f102e37de0f8f88b8d8a72619c560e2 (patch)
tree1ea864ee0dd73a8d90ad77a91fcbf4cd86b910c1 /nixos/modules/services/continuous-integration
parentae140cd468965f93baed78dd7be82dd8dfde179a (diff)
nixos/github-runners: add `noDefaultLabels` option
Add option `noDefaultLabels` which controls the `--no-default-labels`
switch passed to the configure script.
Diffstat (limited to 'nixos/modules/services/continuous-integration')
-rw-r--r--nixos/modules/services/continuous-integration/github-runner/options.nix13
-rw-r--r--nixos/modules/services/continuous-integration/github-runner/service.nix12
-rw-r--r--nixos/modules/services/continuous-integration/github-runners.nix7
3 files changed, 30 insertions, 2 deletions
diff --git a/nixos/modules/services/continuous-integration/github-runner/options.nix b/nixos/modules/services/continuous-integration/github-runner/options.nix
index c5ae101e66dd4..6507e4cc5be12 100644
--- a/nixos/modules/services/continuous-integration/github-runner/options.nix
+++ b/nixos/modules/services/continuous-integration/github-runner/options.nix
@@ -112,7 +112,8 @@ with lib;
   extraLabels = mkOption {
     type = types.listOf types.str;
     description = mdDoc ''
-      Extra labels in addition to the default (`["self-hosted", "Linux", "X64"]`).
+      Extra labels in addition to the default.
+      Requires a non-empty list if the `noDefaultLabels` option is used.
 
       Changing this option triggers a new runner registration.
     '';
@@ -120,6 +121,16 @@ with lib;
     default = [ ];
   };
 
+  noDefaultLabels = mkOption {
+    type = types.bool;
+    description = mdDoc ''
+      Disables adding the default labels. Also see the `extraLabels` option.
+
+      Changing this option triggers a new runner registration.
+    '';
+    default = false;
+  };
+
   replace = mkOption {
     type = types.bool;
     description = mdDoc ''
diff --git a/nixos/modules/services/continuous-integration/github-runner/service.nix b/nixos/modules/services/continuous-integration/github-runner/service.nix
index 784aea0edea7b..8895f4827bb12 100644
--- a/nixos/modules/services/continuous-integration/github-runner/service.nix
+++ b/nixos/modules/services/continuous-integration/github-runner/service.nix
@@ -76,7 +76,16 @@ in
 
             ${lines}
           '';
-          runnerRegistrationConfig = getAttrs [ "name" "tokenFile" "url" "runnerGroup" "extraLabels" "ephemeral" "workDir" ] cfg;
+          runnerRegistrationConfig = getAttrs [
+            "ephemeral"
+            "extraLabels"
+            "name"
+            "noDefaultLabels"
+            "runnerGroup"
+            "tokenFile"
+            "url"
+            "workDir"
+          ] cfg;
           newConfigPath = builtins.toFile "${svcName}-config.json" (builtins.toJSON runnerRegistrationConfig);
           currentConfigPath = "$STATE_DIRECTORY/.nixos-current-config.json";
           newConfigTokenPath = "$STATE_DIRECTORY/.new-token";
@@ -142,6 +151,7 @@ in
                 ${optionalString cfg.replace "--replace"}
                 ${optionalString (cfg.runnerGroup != null) "--runnergroup ${escapeShellArg cfg.runnerGroup}"}
                 ${optionalString cfg.ephemeral "--ephemeral"}
+                ${optionalString cfg.noDefaultLabels "--no-default-labels"}
               )
               # If the token file contains a PAT (i.e., it starts with "ghp_" or "github_pat_"), we have to use the --pat option,
               # if it is not a PAT, we assume it contains a registration token and use the --token option
diff --git a/nixos/modules/services/continuous-integration/github-runners.nix b/nixos/modules/services/continuous-integration/github-runners.nix
index 66ace9580eca5..ea3f192f63631 100644
--- a/nixos/modules/services/continuous-integration/github-runners.nix
+++ b/nixos/modules/services/continuous-integration/github-runners.nix
@@ -39,6 +39,13 @@ in
   };
 
   config = {
+    assertions = flatten (
+      flip mapAttrsToList config.services.github-runners (name: cfg: map (mkIf cfg.enable) [{
+        assertion = !cfg.noDefaultLabels || (cfg.extraLabels != [ ]);
+        message = "`services.github-runners.${name}`: The `extraLabels` option is mandatory if `noDefaultLabels` is set";
+      }])
+    );
+
     systemd.services = flip mapAttrs' cfg (n: v:
       let
         svcName = "github-runner-${n}";