iac/nixos/hosts/asxpio-services/runner.nix
Sergei Poljanski b7414c2ad1
All checks were successful
nixos / nixos (push) Successful in 1m8s
runner: connect with UUID and token instead of registering
The runner's token was regenerated in Forgejo (runner asxpio-services,
same UUID), which also retires the registration-token route the NixOS
module used. Both runners now work the same way: settings from Nix, the
connection (URL, UUID, token from sops) merged in at start, no
registration step. A new token is a sops change and a deploy.

Corrects 0a54caa: `forgejo actions generate-runner-token` returned the
existing registration token, so that commit rotated nothing.

Assisted-by: Claude:opus-5-5
2026-11-17 10:57:02 +04:00

186 lines
5.8 KiB
Nix

# Forgejo Actions runners. Jobs are containers started through Podman's
# Docker-compatible socket.
#
# asxpio for git.asxp.io, reached over the private network
# interop for another-im/interop on dev.another.im
#
# Both connect with a UUID and token from Forgejo's "Create new runner"
# (or a token reset there); no registration step. The UUID is in the
# config, the token in sops; the connection is merged into the config at
# start. A new token means: put it in sops, deploy.
{
config,
lib,
pkgs,
...
}:
let
# Image behind the nix labels. Jobs mount a nix-store volume over /nix,
# seeded from this image on first use; the image's /bin/sh and
# /etc/nix/nix.conf link into that store, so a volume from another
# version breaks every job. Bumping this switches to a fresh volume;
# remove the old one afterwards (podman volume rm nix-store-<old>).
# renovate: datasource=docker depName=nixos/nix
nixVersion = "2.35.6";
yaml = pkgs.formats.yaml { };
# runner <name> <settings without server.connections> <sops secret> <url> <uuid>
runner =
{
name,
description,
settings,
tokenSecret,
url,
uuid,
}:
let
configFile = yaml.generate "runner-${name}.yaml" settings;
in
{
sops.secrets.${tokenSecret}.restartUnits = [ "forgejo-runner-${name}.service" ];
sops.templates."runner-${name}-server.yaml".content = ''
server:
connections:
${name}:
url: ${url}
uuid: ${uuid}
token: ${config.sops.placeholder.${tokenSecret}}
'';
systemd.services."forgejo-runner-${name}" = {
inherit description;
wantedBy = [ "multi-user.target" ];
after = [
"network-online.target"
"podman.socket"
];
wants = [
"network-online.target"
"podman.socket"
];
environment.DOCKER_HOST = "unix:///run/podman/podman.sock";
path = [
pkgs.forgejo-runner
pkgs.yq-go
];
serviceConfig = {
DynamicUser = true;
SupplementaryGroups = [ "podman" ];
StateDirectory = "forgejo-runner-${name}";
WorkingDirectory = "/var/lib/forgejo-runner-${name}";
RuntimeDirectory = "forgejo-runner-${name}";
LoadCredential = "server.yaml:${config.sops.templates."runner-${name}-server.yaml".path}";
Restart = "always";
RestartSec = 5;
};
script = ''
umask 077
yq eval-all '. as $i ireduce ({}; . * $i)' ${configFile} "$CREDENTIALS_DIRECTORY/server.yaml" \
> "$RUNTIME_DIRECTORY/config.yaml"
exec forgejo-runner daemon --config "$RUNTIME_DIRECTORY/config.yaml"
'';
};
};
asxpio = runner {
name = "asxpio";
description = "Forgejo Actions runner for git.asxp.io";
tokenSecret = "runner/token";
url = config.asxpio.runner.forgejoUrl;
uuid = "a41810d7-48a3-4004-aeba-2148704e4e99"; # runner "asxpio-services"
settings = {
log = {
level = "info";
job_level = "info";
};
runner = {
capacity = 4;
timeout = "3h";
shutdown_timeout = "3h";
fetch_timeout = "5s";
fetch_interval = "2s";
report_interval = "1s";
labels = [
"ubuntu-latest:docker://node:20.20.2-bookworm"
"ubuntu-22.04:docker://node:20.20.2-bookworm"
"ubuntu-24.04:docker://node:22.23.5-bookworm"
"debian-latest:docker://debian:12.15"
"debian-12:docker://debian:12.15"
"debian-11:docker://debian:11.11"
"arch-latest:docker://archlinux:base-20261108.0.623074"
"nginx-latest:docker://nginx:1.31.8"
"nginx-alpine:docker://nginx:1.31.8-alpine"
"node-20:docker://node:20.20.2"
"node-22:docker://node:22.23.5"
"python-3.11:docker://python:3.11.18"
"python-3.12:docker://python:3.12.16"
"alpine-latest:docker://alpine:3.24.4"
"nix-latest:docker://nixos/nix:${nixVersion}"
];
};
cache.enabled = true;
container = {
privileged = false;
options = "-v nix-store-${nixVersion}:/nix";
valid_volumes = [ "**" ];
docker_host = "automount"; # deploy jobs build and push images
force_pull = false;
};
};
};
interop = runner {
name = "interop";
description = "Forgejo Actions runner for another-im/interop";
tokenSecret = "runner/interop_token";
url = "https://dev.another.im/";
uuid = "dc326085-8420-4c33-8b88-a9ef46b3359b"; # interop's infra/runner.json
settings = {
log = {
level = "info";
job_level = "info";
};
runner = {
capacity = 3;
timeout = "5h";
shutdown_timeout = "5h";
fetch_interval = "5s";
envs.NIX_CONFIG = ''
experimental-features = nix-command flakes
build-users-group =
sandbox = false
'';
labels = [
"nix:docker://nixos/nix:${nixVersion}"
"docker:docker://node:22.23.5-bookworm"
"nix-host:docker://nixos/nix:${nixVersion}"
];
};
container = {
network = "bridge";
privileged = false;
docker_host = "-"; # its jobs get no container socket
valid_volumes = [ ];
force_pull = false;
};
};
};
in
{
options.asxpio.runner.forgejoUrl = lib.mkOption {
type = lib.types.str;
default = "http://10.10.0.10:3000"; # over the private network, not through Traefik
};
config = lib.mkMerge [
asxpio
interop
{
# The job cache server listens on a random port
asxpio.security.ports = [ "tcp/*/.forgejo-runner" ];
asxpio.security.containers."FORGEJO-ACTIONS-TASK-.*" = [ "docker-sock" ]; # docker_host: automount
}
];
}