8 cfg = config.services.woodpecker-agents;
10 agentModule = lib.types.submodule {
12 enable = lib.mkEnableOption "this Woodpecker-Agent. Agents execute tasks generated by a Server, every install will need one server and at least one agent";
14 package = lib.mkPackageOption pkgs "woodpecker-agent" { };
16 environment = lib.mkOption {
18 type = lib.types.attrsOf lib.types.str;
19 example = lib.literalExpression ''
21 WOODPECKER_SERVER = "localhost:9000";
22 WOODPECKER_BACKEND = "docker";
23 DOCKER_HOST = "unix:///run/podman/podman.sock";
26 description = "woodpecker-agent config environment variables, for other options read the [documentation](https://woodpecker-ci.org/docs/administration/agent-config)";
29 extraGroups = lib.mkOption {
30 type = lib.types.listOf lib.types.str;
32 example = [ "podman" ];
34 Additional groups for the systemd service.
39 type = lib.types.listOf lib.types.package;
43 Additional packages that should be added to the agent's `PATH`.
44 Mostly useful for the `local` backend.
48 environmentFile = lib.mkOption {
49 type = lib.types.listOf lib.types.path;
51 example = [ "/var/secrets/woodpecker-agent.env" ];
53 File to load environment variables
54 from. This is helpful for specifying secrets.
55 Example content of environmentFile:
57 WOODPECKER_AGENT_SECRET=your-shared-secret-goes-here
64 mkAgentService = name: agentCfg: {
65 name = "woodpecker-agent-${name}";
67 description = "Woodpecker-Agent Service - ${name}";
68 wantedBy = [ "multi-user.target" ];
69 after = [ "network-online.target" ];
70 wants = [ "network-online.target" ];
73 SupplementaryGroups = agentCfg.extraGroups;
74 EnvironmentFile = agentCfg.environmentFile;
75 ExecStart = lib.getExe agentCfg.package;
76 Restart = "on-failure";
78 CapabilityBoundingSet = "";
79 NoNewPrivileges = true;
80 ProtectSystem = "strict";
82 PrivateDevices = true;
84 ProtectHostname = true;
86 ProtectKernelTunables = true;
87 ProtectKernelModules = true;
88 ProtectKernelLogs = true;
89 ProtectControlGroups = true;
90 RestrictAddressFamilies = [ "AF_UNIX AF_INET AF_INET6" ];
91 LockPersonality = true;
92 MemoryDenyWriteExecute = true;
93 RestrictRealtime = true;
94 RestrictSUIDSGID = true;
96 SystemCallArchitectures = "native";
97 SystemCallFilter = "~@clock @privileged @cpu-emulation @debug @keyring @module @mount @obsolete @raw-io @reboot @setuid @swap";
100 "-/etc/nsswitch.conf"
102 "-/etc/static/ssl/certs"
107 inherit (agentCfg) environment path;
112 meta.maintainers = with lib.maintainers; [ ambroisie ];
115 services.woodpecker-agents = {
116 agents = lib.mkOption {
118 type = lib.types.attrsOf agentModule;
119 example = lib.literalExpression ''
123 WOODPECKER_SERVER = "localhost:9000";
124 WOODPECKER_BACKEND = "docker";
125 DOCKER_HOST = "unix:///run/podman/podman.sock";
128 extraGroups = [ "podman" ];
130 environmentFile = [ "/run/secrets/woodpecker/agent-secret.txt" ];
135 WOODPECKER_SERVER = "localhost:9000";
136 WOODPECKER_BACKEND = "local";
139 environmentFile = [ "/run/secrets/woodpecker/agent-secret.txt" ];
142 # Needed to clone repos
145 woodpecker-plugin-git
146 # Used by the runner as the default shell
148 # Most likely to be used in pipeline definitions
154 description = "woodpecker-agents configurations";
162 mkServices = lib.mapAttrs' mkAgentService;
163 enabledAgents = lib.filterAttrs (_: agent: agent.enable) cfg.agents;
165 mkServices enabledAgents;