2023-03-27 19:17:25 +00:00
|
|
|
{ config
|
|
|
|
, lib
|
|
|
|
, pkgs
|
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.woodpecker-agents;
|
|
|
|
|
|
|
|
agentModule = lib.types.submodule {
|
|
|
|
options = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = lib.mkEnableOption "this Woodpecker-Agent. Agents execute tasks generated by a Server, every install will need one server and at least one agent";
|
2023-03-27 19:17:25 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = lib.mkPackageOption pkgs "woodpecker-agent" { };
|
2023-03-27 19:17:25 +00:00
|
|
|
|
|
|
|
environment = lib.mkOption {
|
|
|
|
default = { };
|
|
|
|
type = lib.types.attrsOf lib.types.str;
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
{
|
|
|
|
WOODPECKER_SERVER = "localhost:9000";
|
|
|
|
WOODPECKER_BACKEND = "docker";
|
|
|
|
DOCKER_HOST = "unix:///run/podman/podman.sock";
|
|
|
|
}
|
|
|
|
'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "woodpecker-agent config environment variables, for other options read the [documentation](https://woodpecker-ci.org/docs/administration/agent-config)";
|
2023-03-27 19:17:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraGroups = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "podman" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-03-27 19:17:25 +00:00
|
|
|
Additional groups for the systemd service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
path = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.package;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-10-09 19:29:22 +00:00
|
|
|
Additional packages that should be added to the agent's `PATH`.
|
|
|
|
Mostly useful for the `local` backend.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-03-27 19:17:25 +00:00
|
|
|
environmentFile = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.path;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "/var/secrets/woodpecker-agent.env" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-03-27 19:17:25 +00:00
|
|
|
File to load environment variables
|
|
|
|
from. This is helpful for specifying secrets.
|
|
|
|
Example content of environmentFile:
|
|
|
|
```
|
|
|
|
WOODPECKER_AGENT_SECRET=your-shared-secret-goes-here
|
|
|
|
```
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
mkAgentService = name: agentCfg: {
|
|
|
|
name = "woodpecker-agent-${name}";
|
|
|
|
value = {
|
|
|
|
description = "Woodpecker-Agent Service - ${name}";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
SupplementaryGroups = agentCfg.extraGroups;
|
|
|
|
EnvironmentFile = agentCfg.environmentFile;
|
|
|
|
ExecStart = lib.getExe agentCfg.package;
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = 15;
|
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
RestrictAddressFamilies = [ "AF_UNIX AF_INET AF_INET6" ];
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
PrivateMounts = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = "~@clock @privileged @cpu-emulation @debug @keyring @module @mount @obsolete @raw-io @reboot @setuid @swap";
|
|
|
|
BindReadOnlyPaths = [
|
|
|
|
"-/etc/resolv.conf"
|
|
|
|
"-/etc/nsswitch.conf"
|
|
|
|
"-/etc/ssl/certs"
|
|
|
|
"-/etc/static/ssl/certs"
|
|
|
|
"-/etc/hosts"
|
|
|
|
"-/etc/localtime"
|
|
|
|
];
|
|
|
|
};
|
2023-10-09 19:29:22 +00:00
|
|
|
inherit (agentCfg) environment path;
|
2023-03-27 19:17:25 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
2024-07-27 06:49:29 +00:00
|
|
|
meta.maintainers = with lib.maintainers; [ ambroisie ];
|
2023-03-27 19:17:25 +00:00
|
|
|
|
|
|
|
options = {
|
|
|
|
services.woodpecker-agents = {
|
|
|
|
agents = lib.mkOption {
|
|
|
|
default = { };
|
|
|
|
type = lib.types.attrsOf agentModule;
|
2023-10-09 19:29:22 +00:00
|
|
|
example = lib.literalExpression ''
|
|
|
|
{
|
|
|
|
podman = {
|
|
|
|
environment = {
|
|
|
|
WOODPECKER_SERVER = "localhost:9000";
|
|
|
|
WOODPECKER_BACKEND = "docker";
|
|
|
|
DOCKER_HOST = "unix:///run/podman/podman.sock";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraGroups = [ "podman" ];
|
|
|
|
|
|
|
|
environmentFile = [ "/run/secrets/woodpecker/agent-secret.txt" ];
|
2023-03-27 19:17:25 +00:00
|
|
|
};
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
exec = {
|
|
|
|
environment = {
|
|
|
|
WOODPECKER_SERVER = "localhost:9000";
|
|
|
|
WOODPECKER_BACKEND = "local";
|
|
|
|
};
|
2023-03-27 19:17:25 +00:00
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
environmentFile = [ "/run/secrets/woodpecker/agent-secret.txt" ];
|
2023-03-27 19:17:25 +00:00
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
path = [
|
|
|
|
# Needed to clone repos
|
|
|
|
git
|
|
|
|
git-lfs
|
|
|
|
woodpecker-plugin-git
|
|
|
|
# Used by the runner as the default shell
|
|
|
|
bash
|
|
|
|
# Most likely to be used in pipeline definitions
|
|
|
|
coreutils
|
|
|
|
];
|
2023-03-27 19:17:25 +00:00
|
|
|
};
|
2023-10-09 19:29:22 +00:00
|
|
|
}
|
|
|
|
'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "woodpecker-agents configurations";
|
2023-03-27 19:17:25 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
systemd.services =
|
|
|
|
let
|
|
|
|
mkServices = lib.mapAttrs' mkAgentService;
|
|
|
|
enabledAgents = lib.filterAttrs (_: agent: agent.enable) cfg.agents;
|
|
|
|
in
|
|
|
|
mkServices enabledAgents;
|
|
|
|
};
|
|
|
|
}
|