Skip to content

Commit

Permalink
Actions runner working
Browse files Browse the repository at this point in the history
  • Loading branch information
katandtonic committed Oct 9, 2024
1 parent 066902e commit 9f3f835
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 38 deletions.
33 changes: 15 additions & 18 deletions nix-darwin/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,52 +30,43 @@
networking.hostName = "mac-demarco-mini";
imports = [ (import ./gitea-actions-runner.nix) ];
services.gitea-actions-runner = {
user = "kat";
user = "gitearunner";
instances.nix = {
enable = true;
name = config.networking.hostName;
url = "https://dev.railbird.ai";
token = "kf8TgHEf2JwWiusV80ZWo3t7lkEyB1pVgqRdK5ES";
token = "H0A7YXAWsKSp9QzvMymfJI12hbxwR7UerEHpCJUe";
labels = [
"nix-darwin-${pkgs.system}:host"
"macos-aarch64-darwin"
"nix:host"
];
settings = {
cache = {
enabled = true;
};
container = {
workdir_parent = "/var/lib/gitea-runner/workspace";
};
host = {
workdir_parent = "/var/lib/gitea-runner/action-cache-dir";
};
};
hostPackages = with pkgs; [
bash
direnv
coreutils
curl
direnv
gawk
git-lfs
nixFlakes
gitFull
gnused
ncdu
nixFlakes
nodejs
openssh
wget
];
};
};

# 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 = {
XDG_CONFIG_HOME = "/var/lib/gitea-runner";
XDG_CACHE_HOME = "/var/lib/gitea-runner/.cache";
Expand All @@ -89,6 +80,7 @@
gitFull
just
tmux
htop
nodePackages.prettier
nodejs
ripgrep
Expand Down Expand Up @@ -120,9 +112,14 @@
# The platform the configuration will be used on.
nixpkgs.hostPlatform = "aarch64-darwin";
users.users.kat.openssh.authorizedKeys.keys = inputs.railbird-secrets.keys.kanivanKeys;

home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
users.users.gitea-runner = {
name = "gitea-runner";
isHidden = false;
home = "/Users/gitea-runner";
createHome = false;
};

home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true;

users.users.kat = {
name = "kat";
Expand Down
37 changes: 17 additions & 20 deletions nix-darwin/gitea-actions-runner.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ in {
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 {
default = {};
description = "Gitea Actions Runner instances.";
Expand Down Expand Up @@ -117,18 +111,22 @@ in {
description = "Gitea Actions Runner user";
};

users.groups.${cfg.group} = {};

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
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}
export HOME="/var/lib/gitea-runner/${name}"
mkdir -p "$HOME"
cd "$HOME"
touch run_started
echo "STARTING"
# Register the runner if not already registered
if [ ! -e "$HOME/.runner" ]; then
Expand All @@ -146,10 +144,10 @@ in {
];
KeepAlive = true;
RunAtLoad = true;
WorkingDirectory = "/var/lib/gitea-runner/${name}";
StandardOutPath = "/var/log/gitea-runner/${name}.log";
StandardErrorPath = "/var/log/gitea-runner/${name}.error.log";
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) {
Expand All @@ -161,15 +159,14 @@ in {
}
) cfg.instances;

# Ensure the log directory exists and has correct permissions
system.activationScripts.gitea-runner-setup = {
text = ''
mkdir -p /var/log/gitea-runner
chown ${cfg.user}:${cfg.group} /var/log/gitea-runner
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
mkdir -p /var/lib/gitea-runner
chown ${cfg.user}:${cfg.group} /var/lib/gitea-runner
chown -R ${cfg.user} /var/lib/gitea-runner
chmod 755 /var/lib/gitea-runner
'';
};
Expand Down

0 comments on commit 9f3f835

Please sign in to comment.