From a9c807496f102e37de0f8f88b8d8a72619c560e2 Mon Sep 17 00:00:00 2001 From: Vincent Haupert Date: Mon, 22 Jan 2024 13:29:45 +0100 Subject: nixos/github-runners: add `noDefaultLabels` option Add option `noDefaultLabels` which controls the `--no-default-labels` switch passed to the configure script. --- .../continuous-integration/github-runner/options.nix | 13 ++++++++++++- .../continuous-integration/github-runner/service.nix | 12 +++++++++++- .../services/continuous-integration/github-runners.nix | 7 +++++++ 3 files changed, 30 insertions(+), 2 deletions(-) (limited to 'nixos/modules/services/continuous-integration') 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}"; -- cgit 1.4.1