Actions runner working

This commit is contained in:
Kat Huang 2024-08-18 12:22:08 -06:00
parent 12f673d13d
commit 4317b1fb3d
2 changed files with 31 additions and 37 deletions

View File

@ -30,37 +30,36 @@
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 = "kat"; user = "gitearunner";
instances.nix = { instances.nix = {
enable = true; enable = true;
name = config.networking.hostName; name = config.networking.hostName;
url = "https://dev.railbird.ai"; url = "https://dev.railbird.ai";
token = "kf8TgHEf2JwWiusV80ZWo3t7lkEyB1pVgqRdK5ES"; token = "H0A7YXAWsKSp9QzvMymfJI12hbxwR7UerEHpCJUe";
labels = [ labels = [
"nix-darwin-${pkgs.system}:host" "nix-darwin-${pkgs.system}:host"
"macos-aarch64-darwin"
"nix:host" "nix:host"
]; ];
settings = { settings = {
cache = { cache = {
enabled = true; enabled = true;
}; };
container = {
workdir_parent = "/var/lib/gitea-runner/workspace";
};
host = { host = {
workdir_parent = "/var/lib/gitea-runner/action-cache-dir"; workdir_parent = "/var/lib/gitea-runner/action-cache-dir";
}; };
}; };
hostPackages = with pkgs; [ hostPackages = with pkgs; [
bash bash
direnv
coreutils coreutils
curl curl
direnv
gawk gawk
git-lfs git-lfs
nixFlakes
gitFull gitFull
gnused gnused
ncdu
nixFlakes
nodejs nodejs
openssh openssh
wget wget
@ -68,14 +67,6 @@
}; };
}; };
# Create the necessary directories
system.activationScripts.giteaRunnerDirs = ''
mkdir -p /var/lib/gitea-runner/workspace
mkdir -p /var/lib/gitea-runner/action-cache-dir
chown -R kat:staff /var/lib/gitea-runner
'';
# Set environment variables
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";
@ -89,6 +80,7 @@
gitFull gitFull
just just
tmux tmux
htop
nodePackages.prettier nodePackages.prettier
nodejs nodejs
ripgrep ripgrep
@ -120,9 +112,14 @@
# The platform the configuration will be used on. # The platform the configuration will be used on.
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 = {
name = "gitea-runner";
isHidden = false;
home = "/Users/gitea-runner";
createHome = false;
};
home-manager.useGlobalPkgs = true; home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true;
home-manager.useUserPackages = true;
users.users.kat = { users.users.kat = {
name = "kat"; name = "kat";

View File

@ -32,12 +32,6 @@ in {
description = "The user account under which the Gitea Actions Runner should run."; description = "The user account under which the Gitea Actions Runner should run.";
}; };
group = mkOption {
type = types.str;
default = "gitea-runner";
description = "The group under which the Gitea Actions Runner should run.";
};
instances = mkOption { instances = mkOption {
default = {}; default = {};
description = "Gitea Actions Runner instances."; description = "Gitea Actions Runner instances.";
@ -117,18 +111,22 @@ in {
description = "Gitea Actions Runner user"; description = "Gitea Actions Runner user";
}; };
users.groups.${cfg.group} = {};
launchd.daemons = mapAttrs' (name: instance: launchd.daemons = mapAttrs' (name: instance:
nameValuePair "gitea-runner-${name}" { nameValuePair "gitea-runner-${name}" {
serviceConfig = { serviceConfig = {
ProgramArguments = [ ProgramArguments = [
"${pkgs.writeShellScript "gitea-runner-start-${name}" '' "${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
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} sudo su - ${cfg.user}
export HOME="/var/lib/gitea-runner/${name}" echo "STARTING"
mkdir -p "$HOME"
cd "$HOME"
touch run_started
# Register the runner if not already registered # Register the runner if not already registered
if [ ! -e "$HOME/.runner" ]; then if [ ! -e "$HOME/.runner" ]; then
@ -146,10 +144,10 @@ in {
]; ];
KeepAlive = true; KeepAlive = true;
RunAtLoad = true; RunAtLoad = true;
WorkingDirectory = "/var/lib/gitea-runner/${name}"; SessionCreate = true;
StandardOutPath = "/var/log/gitea-runner/${name}.log";
StandardErrorPath = "/var/log/gitea-runner/${name}.error.log";
UserName = cfg.user; UserName = cfg.user;
GroupName = "staff";
WorkingDirectory = "/var/lib/gitea-runner/${name}";
EnvironmentVariables = { EnvironmentVariables = {
PATH = (lib.makeBinPath (instance.hostPackages ++ [ cfg.package ])) + ":/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"; PATH = (lib.makeBinPath (instance.hostPackages ++ [ cfg.package ])) + ":/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin";
} // optionalAttrs (instance.token != null) { } // optionalAttrs (instance.token != null) {
@ -161,15 +159,14 @@ in {
} }
) cfg.instances; ) cfg.instances;
# Ensure the log directory exists and has correct permissions
system.activationScripts.gitea-runner-setup = { system.activationScripts.gitea-runner-setup = {
text = '' text = ''
mkdir -p /var/log/gitea-runner mkdir -p /var/log/gitea-runner/
chown ${cfg.user}:${cfg.group} /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 chmod 755 /var/log/gitea-runner
mkdir -p /var/lib/gitea-runner chown -R ${cfg.user} /var/lib/gitea-runner
chown ${cfg.user}:${cfg.group} /var/lib/gitea-runner
chmod 755 /var/lib/gitea-runner chmod 755 /var/lib/gitea-runner
''; '';
}; };