1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-12-14 11:57:34 +00:00

Merge pull request #1218 from Enzime/push-rnmuskqvosws

github-runner: fix service not starting
This commit is contained in:
Domen Kožar 2024-12-07 11:26:48 +00:00 committed by GitHub
commit 9c3d8ff051
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 12 deletions

View file

@ -3,7 +3,9 @@
, ... , ...
}: }:
with lib; let
inherit (lib) literalExpression mkOption mkPackageOption types;
in
{ {
options.services.github-runners = mkOption { options.services.github-runners = mkOption {
description = '' description = ''
@ -88,6 +90,9 @@ with lib;
Changing this option or the `tokenFile`s content triggers a new runner registration. Changing this option or the `tokenFile`s content triggers a new runner registration.
You can also manually trigger a new runner registration by deleting
{file}`/var/lib/github-runners/<name>/.runner` and restarting the service.
We suggest using the fine-grained PATs. A runner registration token is valid We suggest using the fine-grained PATs. A runner registration token is valid
only for 1 hour after creation, so the next time the runner configuration changes only for 1 hour after creation, so the next time the runner configuration changes
this will give you hard-to-debug HTTP 404 errors in the configure step. this will give you hard-to-debug HTTP 404 errors in the configure step.

View file

@ -1,6 +1,10 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
with lib;
let let
inherit (lib) any attrValues boolToString concatStringsSep escapeShellArg
flatten flip getExe getExe' hasAttr hasPrefix mapAttrsToList mapAttrs' mkBefore
mkDefault mkIf mkMerge nameValuePair optionalAttrs optionalString replaceStrings;
mkSvcName = name: "github-runner-${name}"; mkSvcName = name: "github-runner-${name}";
mkStateDir = cfg: "/var/lib/github-runners/${cfg.name}"; mkStateDir = cfg: "/var/lib/github-runners/${cfg.name}";
mkLogDir = cfg: "/var/log/github-runners/${cfg.name}"; mkLogDir = cfg: "/var/log/github-runners/${cfg.name}";
@ -51,15 +55,17 @@ in
( (
umask -S u=rwx,g=rx,o= > /dev/null umask -S u=rwx,g=rx,o= > /dev/null
${pkgs.coreutils}/bin/mkdir -p ${escapeShellArg (mkStateDir cfg)} ${getExe' pkgs.coreutils "mkdir"} -p ${escapeShellArg (mkStateDir cfg)}
${pkgs.coreutils}/bin/chown ${user}:${group} ${escapeShellArg (mkStateDir cfg)} ${getExe' pkgs.coreutils "chown"} ${user}:${group} ${escapeShellArg (mkStateDir cfg)}
${pkgs.coreutils}/bin/mkdir -p ${escapeShellArg (mkLogDir cfg)} ${getExe' pkgs.coreutils "mkdir"} -p ${escapeShellArg (mkLogDir cfg)}
${pkgs.coreutils}/bin/chown ${user}:${group} ${escapeShellArg (mkLogDir cfg)} # launchd will fail to start the service if the outer direction doesn't have sufficient permissions
${getExe' pkgs.coreutils "chmod"} o+rx ${escapeShellArg (mkLogDir { name = ""; })}
${getExe' pkgs.coreutils "chown"} ${user}:${group} ${escapeShellArg (mkLogDir cfg)}
${optionalString (cfg.workDir == null) '' ${optionalString (cfg.workDir == null) ''
${pkgs.coreutils}/bin/mkdir -p ${escapeShellArg (mkWorkDir cfg)} ${getExe' pkgs.coreutils "mkdir"} -p ${escapeShellArg (mkWorkDir cfg)}
${pkgs.coreutils}/bin/chown ${user}:${group} ${escapeShellArg (mkWorkDir cfg)} ${getExe' pkgs.coreutils "chown"} ${user}:${group} ${escapeShellArg (mkWorkDir cfg)}
''} ''}
) )
''); '');
@ -123,7 +129,7 @@ in
else else
args+=(--token "$token") args+=(--token "$token")
fi fi
${package}/bin/config.sh "''${args[@]}" ${getExe' package "config.sh"} "''${args[@]}"
''; '';
}; };
in in
@ -131,12 +137,12 @@ in
echo "Configuring GitHub Actions Runner" echo "Configuring GitHub Actions Runner"
# Always clean the working directory # Always clean the working directory
${pkgs.findutils}/bin/find ${escapeShellArg workDir} -mindepth 1 -delete ${getExe pkgs.findutils} ${escapeShellArg workDir} -mindepth 1 -delete
# Clean the $RUNNER_ROOT if we are in ephemeral mode # Clean the $RUNNER_ROOT if we are in ephemeral mode
if ${boolToString cfg.ephemeral}; then if ${boolToString cfg.ephemeral}; then
echo "Cleaning $RUNNER_ROOT" echo "Cleaning $RUNNER_ROOT"
${pkgs.findutils}/bin/find "$RUNNER_ROOT" -mindepth 1 -delete ${getExe pkgs.findutils} "$RUNNER_ROOT" -mindepth 1 -delete
fi fi
# If the `.runner` file does not exist, we assume the runner is not configured # If the `.runner` file does not exist, we assume the runner is not configured
@ -145,7 +151,7 @@ in
fi fi
# Start the service # Start the service
${package}/bin/Runner.Listener run --startuptype service ${getExe' package "Runner.Listener"} run --startuptype service
''; '';
serviceConfig = mkMerge [ serviceConfig = mkMerge [