diff --git a/nixos/modules/services/continuous-integration/github-runner/options.nix b/nixos/modules/services/continuous-integration/github-runner/options.nix index e021127a979..ae89d3a3bfb 100644 --- a/nixos/modules/services/continuous-integration/github-runner/options.nix +++ b/nixos/modules/services/continuous-integration/github-runner/options.nix @@ -55,19 +55,23 @@ with lib; example = "/run/secrets/github-runner/nixos.token"; }; - name = mkOption { + name = let # Same pattern as for `networking.hostName` - type = types.strMatching "^$|^[[:alnum:]]([[:alnum:]_-]{0,61}[[:alnum:]])?$"; + baseType = types.strMatching "^$|^[[:alnum:]]([[:alnum:]_-]{0,61}[[:alnum:]])?$"; + in mkOption { + type = if includeNameDefault then baseType else types.nullOr baseType; description = lib.mdDoc '' Name of the runner to configure. Defaults to the hostname. Changing this option triggers a new runner registration. ''; example = "nixos"; - } // lib.optionalAttrs includeNameDefault { + } // (if includeNameDefault then { default = config.networking.hostName; defaultText = literalExpression "config.networking.hostName"; - }; + } else { + default = null; + }); runnerGroup = mkOption { type = types.nullOr types.str; diff --git a/nixos/modules/services/continuous-integration/github-runners.nix b/nixos/modules/services/continuous-integration/github-runners.nix index dfa37c1c76e..78b57f9c7a2 100644 --- a/nixos/modules/services/continuous-integration/github-runners.nix +++ b/nixos/modules/services/continuous-integration/github-runners.nix @@ -15,7 +15,7 @@ in options.services.github-runners = mkOption { default = {}; type = with types; attrsOf (submodule { options = import ./github-runner/options.nix (args // { - # services.github-runners.${name}.name doesn't have a default; instead it is set to ${name} below. + # services.github-runners.${name}.name doesn't have a default; it falls back to ${name} below. includeNameDefault = false; }); }); example = { @@ -39,15 +39,17 @@ in }; config = { - systemd.services = flip mapAttrs' cfg (name: v: + systemd.services = flip mapAttrs' cfg (n: v: let - svcName = "github-runner-${name}"; + svcName = "github-runner-${n}"; in nameValuePair svcName (import ./github-runner/service.nix (args // { inherit svcName; - cfg = v // { inherit name; }; - systemdDir = "github-runner/${name}"; + cfg = v // { + name = if v.name != null then v.name else n; + }; + systemdDir = "github-runner/${n}"; })) ); };