Fix actions runner in macos
This commit is contained in:
parent
9f3f835253
commit
1d31f870c5
@ -30,7 +30,7 @@
|
|||||||
networking.hostName = "mac-demarco-mini";
|
networking.hostName = "mac-demarco-mini";
|
||||||
imports = [ (import ./gitea-actions-runner.nix) ];
|
imports = [ (import ./gitea-actions-runner.nix) ];
|
||||||
services.gitea-actions-runner = {
|
services.gitea-actions-runner = {
|
||||||
user = "gitearunner";
|
user = "gitea-runner";
|
||||||
instances.nix = {
|
instances.nix = {
|
||||||
enable = true;
|
enable = true;
|
||||||
name = config.networking.hostName;
|
name = config.networking.hostName;
|
||||||
@ -55,7 +55,9 @@
|
|||||||
curl
|
curl
|
||||||
direnv
|
direnv
|
||||||
gawk
|
gawk
|
||||||
|
just
|
||||||
git-lfs
|
git-lfs
|
||||||
|
isort
|
||||||
gitFull
|
gitFull
|
||||||
gnused
|
gnused
|
||||||
ncdu
|
ncdu
|
||||||
@ -70,7 +72,44 @@
|
|||||||
launchd.daemons.gitea-runner-nix.serviceConfig.EnvironmentVariables = {
|
launchd.daemons.gitea-runner-nix.serviceConfig.EnvironmentVariables = {
|
||||||
XDG_CONFIG_HOME = "/var/lib/gitea-runner";
|
XDG_CONFIG_HOME = "/var/lib/gitea-runner";
|
||||||
XDG_CACHE_HOME = "/var/lib/gitea-runner/.cache";
|
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)];
|
nixpkgs.overlays = [(import ../nixos/overlay.nix)];
|
||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [
|
||||||
python-with-my-packages
|
python-with-my-packages
|
||||||
@ -113,11 +152,11 @@
|
|||||||
nixpkgs.hostPlatform = "aarch64-darwin";
|
nixpkgs.hostPlatform = "aarch64-darwin";
|
||||||
users.users.kat.openssh.authorizedKeys.keys = inputs.railbird-secrets.keys.kanivanKeys;
|
users.users.kat.openssh.authorizedKeys.keys = inputs.railbird-secrets.keys.kanivanKeys;
|
||||||
users.users.gitea-runner = {
|
users.users.gitea-runner = {
|
||||||
name = "gitea-runner";
|
name = "gitea-runner";
|
||||||
isHidden = false;
|
isHidden = false;
|
||||||
home = "/Users/gitea-runner";
|
home = "/Users/gitea-runner";
|
||||||
createHome = false;
|
createHome = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true;
|
home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true;
|
||||||
|
|
||||||
@ -150,6 +189,7 @@
|
|||||||
programs.starship = {
|
programs.starship = {
|
||||||
enable = true;
|
enable = true;
|
||||||
};
|
};
|
||||||
|
programs.zsh.enable = true;
|
||||||
home.stateVersion = "24.05";
|
home.stateVersion = "24.05";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{
|
||||||
|
config,
|
||||||
with lib;
|
lib,
|
||||||
|
pkgs,
|
||||||
let
|
...
|
||||||
|
}:
|
||||||
|
with lib; let
|
||||||
cfg = config.services.gitea-actions-runner;
|
cfg = config.services.gitea-actions-runner;
|
||||||
|
|
||||||
settingsFormat = pkgs.formats.yaml { };
|
settingsFormat = pkgs.formats.yaml {};
|
||||||
|
|
||||||
hasDockerScheme = instance:
|
hasDockerScheme = instance:
|
||||||
instance.labels == [] || any (label: hasInfix ":docker:" label) instance.labels;
|
instance.labels == [] || any (label: hasInfix ":docker:" label) instance.labels;
|
||||||
@ -14,9 +16,8 @@ let
|
|||||||
hasHostScheme = instance: any (label: hasSuffix ":host" label) instance.labels;
|
hasHostScheme = instance: any (label: hasSuffix ":host" label) instance.labels;
|
||||||
|
|
||||||
tokenXorTokenFile = instance:
|
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 {
|
in {
|
||||||
options.services.gitea-actions-runner = {
|
options.services.gitea-actions-runner = {
|
||||||
package = mkOption {
|
package = mkOption {
|
||||||
@ -66,7 +67,7 @@ in {
|
|||||||
labels = mkOption {
|
labels = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
default = [];
|
default = [];
|
||||||
example = [ "macos:host" "x86_64:host" ];
|
example = ["macos:host" "x86_64:host"];
|
||||||
description = "Labels used to map jobs to their runtime environment.";
|
description = "Labels used to map jobs to their runtime environment.";
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ in {
|
|||||||
type = types.submodule {
|
type = types.submodule {
|
||||||
freeformType = settingsFormat.type;
|
freeformType = settingsFormat.type;
|
||||||
};
|
};
|
||||||
default = { };
|
default = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
hostPackages = mkOption {
|
hostPackages = mkOption {
|
||||||
@ -111,64 +112,65 @@ in {
|
|||||||
description = "Gitea Actions Runner user";
|
description = "Gitea Actions Runner user";
|
||||||
};
|
};
|
||||||
|
|
||||||
launchd.daemons = mapAttrs' (name: instance:
|
launchd.daemons =
|
||||||
nameValuePair "gitea-runner-${name}" {
|
(mapAttrs' (
|
||||||
serviceConfig = {
|
name: instance:
|
||||||
ProgramArguments = [
|
nameValuePair "gitea-runner-${name}" {
|
||||||
"${pkgs.writeShellScript "gitea-runner-start-${name}" ''
|
serviceConfig = {
|
||||||
echo "home is $HOME"
|
ProgramArguments = [
|
||||||
mkdir -p /var/log/gitea-runner/
|
"/usr/bin/env"
|
||||||
chown -R ${cfg.user} /var/log/gitea-runner
|
"bash"
|
||||||
chmod 755 /var/log/gitea-runner
|
"-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}
|
||||||
|
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" \
|
||||||
|
--name ${escapeShellArg instance.name} \
|
||||||
|
--labels ${escapeShellArg (concatStringsSep "," instance.labels)} \
|
||||||
|
--config ${settingsFormat.generate "config.yaml" instance.settings}
|
||||||
|
fi
|
||||||
|
|
||||||
mkdir -p /var/lib/gitea-runner/${name}
|
# Start the runner
|
||||||
chown -R ${cfg.user} /var/lib/gitea-runner
|
chown -R ${cfg.user} /var/lib/gitea-runner
|
||||||
chmod 755 /var/lib/gitea-runner
|
chown -R ${cfg.user} /var/log/gitea-runner
|
||||||
|
''}"
|
||||||
sudo su - ${cfg.user}
|
];
|
||||||
echo "STARTING"
|
};
|
||||||
|
}
|
||||||
# Register the runner if not already registered
|
)
|
||||||
if [ ! -e "$HOME/.runner" ]; then
|
cfg.instances);
|
||||||
${cfg.package}/bin/act_runner register --no-interactive \
|
|
||||||
--instance ${escapeShellArg instance.url} \
|
|
||||||
--token "$TOKEN" \
|
|
||||||
--name ${escapeShellArg instance.name} \
|
|
||||||
--labels ${escapeShellArg (concatStringsSep "," instance.labels)} \
|
|
||||||
--config ${settingsFormat.generate "config.yaml" instance.settings}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Start the runner
|
|
||||||
exec ${cfg.package}/bin/act_runner daemon --config ${settingsFormat.generate "config.yaml" instance.settings}
|
|
||||||
''}"
|
|
||||||
];
|
|
||||||
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
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user