Skip to content

Commit

Permalink
Merge pull request #1013 from Enzime/fix/github-runners-work-dir
Browse files Browse the repository at this point in the history
github-runnners: fix workDir missing on reboot
  • Loading branch information
emilazy committed Jul 23, 2024
2 parents 2ae24bc + fe99aa9 commit 884f3fe
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions modules/services/github-runner/service.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,15 @@ in
in
{
launchd = mkIf cfg.enable {
text = mkBefore (''
text = mkBefore ''
echo >&2 "setting up GitHub Runner '${cfg.name}'..."
${pkgs.coreutils}/bin/mkdir -p -m 0750 ${escapeShellArg (mkStateDir cfg)}
${pkgs.coreutils}/bin/chown ${user}:${group} ${escapeShellArg (mkStateDir cfg)}
${pkgs.coreutils}/bin/mkdir -p -m 0750 ${escapeShellArg (mkLogDir cfg)}
${pkgs.coreutils}/bin/chown ${user}:${group} ${escapeShellArg (mkLogDir cfg)}
'' + optionalString (cfg.workDir == null) ''
${pkgs.coreutils}/bin/mkdir -p -m 0750 ${escapeShellArg (mkWorkDir cfg)}
${pkgs.coreutils}/bin/chown ${user}:${group} ${escapeShellArg (mkWorkDir cfg)}
'');
'';
};
}));

Expand All @@ -62,6 +59,9 @@ in
stateDir = mkStateDir cfg;
logDir = mkLogDir cfg;
workDir = mkWorkDir cfg;
user = if (cfg.user != null) then cfg.user else "_github-runner";
# If both user and group are null then we manage the group, otherwise if only group is null then there's no group
group = if (cfg.group != null) then group else if (cfg.user == null) then "_github-runner" else "";
in
nameValuePair
(mkSvcName name)
Expand Down Expand Up @@ -116,6 +116,12 @@ in
''
echo "Configuring GitHub Actions Runner"
${optionalString (cfg.workDir == null) ''
# /var/run gets cleared every reboot so we need to create it before starting the service
${pkgs.coreutils}/bin/mkdir -p -m 0750 ${escapeShellArg workDir}
${pkgs.coreutils}/bin/chown ${user}:${group} ${escapeShellArg workDir}
''}
# Always clean the working directory
${pkgs.findutils}/bin/find ${escapeShellArg workDir} -mindepth 1 -delete
Expand Down Expand Up @@ -147,7 +153,7 @@ in
StandardErrorPath = "${logDir}/launchd-stderr.log";
StandardOutPath = "${logDir}/launchd-stdout.log";
ThrottleInterval = 30;
UserName = if (cfg.user != null) then cfg.user else "_github-runner";
UserName = user;
WatchPaths = [
"/etc/resolv.conf"
"/Library/Preferences/SystemConfiguration/NetworkInterfaces.plist"
Expand Down

0 comments on commit 884f3fe

Please sign in to comment.