Fix actions runner in macos
This commit is contained in:
parent
9f3f835253
commit
1d31f870c5
@ -30,7 +30,7 @@
|
||||
networking.hostName = "mac-demarco-mini";
|
||||
imports = [ (import ./gitea-actions-runner.nix) ];
|
||||
services.gitea-actions-runner = {
|
||||
user = "gitearunner";
|
||||
user = "gitea-runner";
|
||||
instances.nix = {
|
||||
enable = true;
|
||||
name = config.networking.hostName;
|
||||
@ -55,7 +55,9 @@
|
||||
curl
|
||||
direnv
|
||||
gawk
|
||||
just
|
||||
git-lfs
|
||||
isort
|
||||
gitFull
|
||||
gnused
|
||||
ncdu
|
||||
@ -70,7 +72,44 @@
|
||||
launchd.daemons.gitea-runner-nix.serviceConfig.EnvironmentVariables = {
|
||||
XDG_CONFIG_HOME = "/var/lib/gitea-runner";
|
||||
XDG_CACHE_HOME = "/var/lib/gitea-runner/.cache";
|
||||
XDG_RUNTIME_DIR = "/var/lib/gitea-runner/tmp";
|
||||
};
|
||||
|
||||
# launchd.daemons.gitea-runner-restarter = {
|
||||
# serviceConfig = {
|
||||
# ProgramArguments = [
|
||||
# "/usr/bin/env"
|
||||
# "bash"
|
||||
# "-c"
|
||||
# ''
|
||||
# SERVICE_NAME="org.nixos.gitea-runner-nix"
|
||||
# while true; do
|
||||
# # Check the second column of launchctl list output for our service
|
||||
# EXIT_CODE=$(sudo launchctl list | grep "$SERVICE_NAME" | awk '{print $2}')
|
||||
# if [ -z "$EXIT_CODE" ]; then
|
||||
# echo "$(date): $SERVICE_NAME is running correctly. Terminating the restarter."
|
||||
# exit 0
|
||||
# else
|
||||
# echo "$(date): $SERVICE_NAME is not running or in error state. Attempting to restart..."
|
||||
# sudo launchctl bootout system/$SERVICE_NAME 2>/dev/null || true
|
||||
# sudo launchctl load /Library/LaunchDaemons/$SERVICE_NAME.plist
|
||||
# sleep 2 # Give the service some time to start
|
||||
# fi
|
||||
# done
|
||||
# ''
|
||||
# ];
|
||||
# RunAtLoad = true;
|
||||
# ThrottleInterval = 300;
|
||||
# };
|
||||
# };
|
||||
|
||||
launchd.daemons.does-anything-work = {
|
||||
serviceConfig = {
|
||||
ProgramArguments = ["/usr/bin/env" "bash" "-c" "date > /var/log/does-anything-work"];
|
||||
RunAtLoad = true;
|
||||
};
|
||||
};
|
||||
|
||||
nixpkgs.overlays = [(import ../nixos/overlay.nix)];
|
||||
environment.systemPackages = with pkgs; [
|
||||
python-with-my-packages
|
||||
@ -150,6 +189,7 @@
|
||||
programs.starship = {
|
||||
enable = true;
|
||||
};
|
||||
programs.zsh.enable = true;
|
||||
home.stateVersion = "24.05";
|
||||
};
|
||||
};
|
||||
|
@ -1,8 +1,10 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.services.gitea-actions-runner;
|
||||
|
||||
settingsFormat = pkgs.formats.yaml {};
|
||||
@ -14,9 +16,8 @@ let
|
||||
hasHostScheme = instance: any (label: hasSuffix ":host" label) instance.labels;
|
||||
|
||||
tokenXorTokenFile = instance:
|
||||
(instance.token == null && instance.tokenFile != null) ||
|
||||
(instance.token != null && instance.tokenFile == null);
|
||||
|
||||
(instance.token == null && instance.tokenFile != null)
|
||||
|| (instance.token != null && instance.tokenFile == null);
|
||||
in {
|
||||
options.services.gitea-actions-runner = {
|
||||
package = mkOption {
|
||||
@ -111,25 +112,49 @@ in {
|
||||
description = "Gitea Actions Runner user";
|
||||
};
|
||||
|
||||
launchd.daemons = mapAttrs' (name: instance:
|
||||
launchd.daemons =
|
||||
(mapAttrs' (
|
||||
name: instance:
|
||||
nameValuePair "gitea-runner-${name}" {
|
||||
serviceConfig = {
|
||||
ProgramArguments = [
|
||||
"${pkgs.writeShellScript "gitea-runner-start-${name}" ''
|
||||
echo "home is $HOME"
|
||||
mkdir -p /var/log/gitea-runner/
|
||||
chown -R ${cfg.user} /var/log/gitea-runner
|
||||
chmod 755 /var/log/gitea-runner
|
||||
|
||||
"/usr/bin/env"
|
||||
"bash"
|
||||
"-c"
|
||||
''
|
||||
cd /var/lib/gitea-runner/${name}
|
||||
exec ${cfg.package}/bin/act_runner daemon --config ${settingsFormat.generate "config.yaml" instance.settings}
|
||||
''
|
||||
];
|
||||
KeepAlive = true;
|
||||
ThrottleInterval = 5;
|
||||
SessionCreate = true;
|
||||
UserName = cfg.user;
|
||||
GroupName = "staff";
|
||||
WorkingDirectory = "/var/lib/gitea-runner/${name}";
|
||||
EnvironmentVariables = {
|
||||
PATH = (lib.makeBinPath (instance.hostPackages ++ [cfg.package])) + ":/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin";
|
||||
};
|
||||
};
|
||||
}
|
||||
)
|
||||
cfg.instances)
|
||||
// (mapAttrs' (
|
||||
name: instance:
|
||||
nameValuePair "gitea-runner-setup-${name}"
|
||||
{
|
||||
serviceConfig = {
|
||||
EnvironmentVariables =
|
||||
{}
|
||||
// optionalAttrs (instance.token != null) {
|
||||
TOKEN = instance.token;
|
||||
};
|
||||
RunAtLoad = true;
|
||||
ProgramArguments = [
|
||||
"${pkgs.writeShellScript "gitea-runner-setup-${name}" ''
|
||||
mkdir -p /var/lib/gitea-runner/${name}
|
||||
chown -R ${cfg.user} /var/lib/gitea-runner
|
||||
chmod 755 /var/lib/gitea-runner
|
||||
|
||||
sudo su - ${cfg.user}
|
||||
echo "STARTING"
|
||||
|
||||
# Register the runner if not already registered
|
||||
if [ ! -e "$HOME/.runner" ]; then
|
||||
cd /var/lib/gitea-runner/${name}
|
||||
if [ ! -e "/var/lib/gitea-runner/${name}/.runner" ]; then
|
||||
${cfg.package}/bin/act_runner register --no-interactive \
|
||||
--instance ${escapeShellArg instance.url} \
|
||||
--token "$TOKEN" \
|
||||
@ -139,36 +164,13 @@ in {
|
||||
fi
|
||||
|
||||
# Start the runner
|
||||
exec ${cfg.package}/bin/act_runner daemon --config ${settingsFormat.generate "config.yaml" instance.settings}
|
||||
chown -R ${cfg.user} /var/lib/gitea-runner
|
||||
chown -R ${cfg.user} /var/log/gitea-runner
|
||||
''}"
|
||||
];
|
||||
KeepAlive = true;
|
||||
RunAtLoad = true;
|
||||
SessionCreate = true;
|
||||
UserName = cfg.user;
|
||||
GroupName = "staff";
|
||||
WorkingDirectory = "/var/lib/gitea-runner/${name}";
|
||||
EnvironmentVariables = {
|
||||
PATH = (lib.makeBinPath (instance.hostPackages ++ [ cfg.package ])) + ":/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin";
|
||||
} // optionalAttrs (instance.token != null) {
|
||||
TOKEN = instance.token;
|
||||
};
|
||||
} // optionalAttrs (instance.tokenFile != null) {
|
||||
EnvironmentVariables.__TokenFile = instance.tokenFile;
|
||||
};
|
||||
}
|
||||
) cfg.instances;
|
||||
|
||||
system.activationScripts.gitea-runner-setup = {
|
||||
text = ''
|
||||
mkdir -p /var/log/gitea-runner/
|
||||
mkdir -p /var/lib/gitea-runner/${name}
|
||||
chown -R ${cfg.user} /var/log/gitea-runner
|
||||
chmod 755 /var/log/gitea-runner
|
||||
|
||||
chown -R ${cfg.user} /var/lib/gitea-runner
|
||||
chmod 755 /var/lib/gitea-runner
|
||||
'';
|
||||
};
|
||||
)
|
||||
cfg.instances);
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user