9 cfg = config.services.woodpecker-agents;
11 agentModule = lib.types.submodule {
13 enable = lib.mkEnableOption "this Woodpecker-Agent. Agents execute tasks generated by a Server, every install will need one server and at least one agent";
15 package = lib.mkPackageOption pkgs "woodpecker-agent" { };
17 environment = lib.mkOption {
19 type = lib.types.attrsOf lib.types.str;
20 example = lib.literalExpression ''
22 WOODPECKER_SERVER = "localhost:9000";
23 WOODPECKER_BACKEND = "docker";
24 DOCKER_HOST = "unix:///run/podman/podman.sock";
27 description = "woodpecker-agent config environment variables, for other options read the [documentation](https://woodpecker-ci.org/docs/administration/agent-config)";
30 extraGroups = lib.mkOption {
31 type = lib.types.listOf lib.types.str;
33 example = [ "podman" ];
35 Additional groups for the systemd service.
40 type = lib.types.listOf lib.types.package;
44 Additional packages that should be added to the agent's `PATH`.
45 Mostly useful for the `local` backend.
49 environmentFile = lib.mkOption {
50 type = lib.types.listOf lib.types.path;
52 example = [ "/var/secrets/woodpecker-agent.env" ];
54 File to load environment variables
55 from. This is helpful for specifying secrets.
56 Example content of environmentFile:
58 WOODPECKER_AGENT_SECRET=your-shared-secret-goes-here
65 mkAgentService = name: agentCfg: {
66 name = "woodpecker-agent-${name}";
68 description = "Woodpecker-Agent Service - ${name}";
69 wantedBy = [ "multi-user.target" ];
70 after = [ "network-online.target" ];
71 wants = [ "network-online.target" ];
74 SupplementaryGroups = agentCfg.extraGroups;
75 EnvironmentFile = agentCfg.environmentFile;
76 ExecStart = lib.getExe agentCfg.package;
77 Restart = "on-failure";
79 CapabilityBoundingSet = "";
80 NoNewPrivileges = true;
81 ProtectSystem = "strict";
83 PrivateDevices = true;
85 ProtectHostname = true;
87 ProtectKernelTunables = true;
88 ProtectKernelModules = true;
89 ProtectKernelLogs = true;
90 ProtectControlGroups = true;
91 RestrictAddressFamilies = [ "AF_UNIX AF_INET AF_INET6" ];
92 LockPersonality = true;
93 MemoryDenyWriteExecute = true;
94 RestrictRealtime = true;
95 RestrictSUIDSGID = true;
97 SystemCallArchitectures = "native";
98 SystemCallFilter = "~@clock @privileged @cpu-emulation @debug @keyring @module @mount @obsolete @raw-io @reboot @setuid @swap";
101 "-/etc/nsswitch.conf"
103 "-/etc/static/ssl/certs"
108 inherit (agentCfg) environment path;
113 meta.maintainers = with lib.maintainers; [ ambroisie ];
116 services.woodpecker-agents = {
117 agents = lib.mkOption {
119 type = lib.types.attrsOf agentModule;
120 example = lib.literalExpression ''
124 WOODPECKER_SERVER = "localhost:9000";
125 WOODPECKER_BACKEND = "docker";
126 DOCKER_HOST = "unix:///run/podman/podman.sock";
129 extraGroups = [ "podman" ];
131 environmentFile = [ "/run/secrets/woodpecker/agent-secret.txt" ];
136 WOODPECKER_SERVER = "localhost:9000";
137 WOODPECKER_BACKEND = "local";
140 environmentFile = [ "/run/secrets/woodpecker/agent-secret.txt" ];
143 # Needed to clone repos
146 woodpecker-plugin-git
147 # Used by the runner as the default shell
149 # Most likely to be used in pipeline definitions
155 description = "woodpecker-agents configurations";
163 mkServices = lib.mapAttrs' mkAgentService;
164 enabledAgents = lib.filterAttrs (_: agent: agent.enable) cfg.agents;
166 mkServices enabledAgents;