Use config name by default, falling back to attr name

This commit is contained in:
Tom McLaughlin 2022-10-19 02:35:44 -07:00
parent 5221e7af04
commit c2cc9aeafd
2 changed files with 15 additions and 9 deletions

View File

@ -55,19 +55,23 @@ with lib;
example = "/run/secrets/github-runner/nixos.token"; example = "/run/secrets/github-runner/nixos.token";
}; };
name = mkOption { name = let
# Same pattern as for `networking.hostName` # 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 '' description = lib.mdDoc ''
Name of the runner to configure. Defaults to the hostname. Name of the runner to configure. Defaults to the hostname.
Changing this option triggers a new runner registration. Changing this option triggers a new runner registration.
''; '';
example = "nixos"; example = "nixos";
} // lib.optionalAttrs includeNameDefault { } // (if includeNameDefault then {
default = config.networking.hostName; default = config.networking.hostName;
defaultText = literalExpression "config.networking.hostName"; defaultText = literalExpression "config.networking.hostName";
}; } else {
default = null;
});
runnerGroup = mkOption { runnerGroup = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;

View File

@ -15,7 +15,7 @@ in
options.services.github-runners = mkOption { options.services.github-runners = mkOption {
default = {}; default = {};
type = with types; attrsOf (submodule { options = import ./github-runner/options.nix (args // { 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; includeNameDefault = false;
}); }); }); });
example = { example = {
@ -39,15 +39,17 @@ in
}; };
config = { config = {
systemd.services = flip mapAttrs' cfg (name: v: systemd.services = flip mapAttrs' cfg (n: v:
let let
svcName = "github-runner-${name}"; svcName = "github-runner-${n}";
in in
nameValuePair svcName nameValuePair svcName
(import ./github-runner/service.nix (args // { (import ./github-runner/service.nix (args // {
inherit svcName; inherit svcName;
cfg = v // { inherit name; }; cfg = v // {
systemdDir = "github-runner/${name}"; name = if v.name != null then v.name else n;
};
systemdDir = "github-runner/${n}";
})) }))
); );
}; };