1 { config, lib, options, pkgs, ... }:
6 cfg = config.services.gocd-agent;
7 opt = options.services.gocd-agent;
10 services.gocd-agent = {
11 enable = mkEnableOption "gocd-agent";
14 default = "gocd-agent";
17 User the Go.CD agent should execute under.
22 default = "gocd-agent";
25 If the default user "gocd-agent" is configured then this is the primary
30 extraGroups = mkOption {
31 type = types.listOf types.str;
33 example = [ "wheel" "docker" ];
35 List of extra groups that the "gocd-agent" user should be a part of.
40 default = [ pkgs.stdenv pkgs.jre pkgs.git config.programs.ssh.package pkgs.nix ];
41 defaultText = literalExpression "[ pkgs.stdenv pkgs.jre pkgs.git config.programs.ssh.package pkgs.nix ]";
42 type = types.listOf types.package;
44 Packages to add to PATH for the Go.CD agent process.
48 agentConfig = mkOption {
52 agent.auto.register.resources=ant,java
53 agent.auto.register.environments=QA,Performance
54 agent.auto.register.hostname=Agent01
57 Agent registration configuration.
62 default = "https://127.0.0.1:8154/go";
65 URL of the GoCD Server to attach the Go.CD Agent to.
70 default = "/var/lib/go-agent";
73 Specifies the working directory in which the Go.CD agent java archive resides.
77 initialJavaHeapSize = mkOption {
81 Specifies the initial java heap memory size for the Go.CD agent java process.
85 maxJavaHeapMemory = mkOption {
89 Specifies the java maximum heap memory size for the Go.CD agent java process.
93 startupOptions = mkOption {
94 type = types.listOf types.str;
96 "-Xms${cfg.initialJavaHeapSize}"
97 "-Xmx${cfg.maxJavaHeapMemory}"
98 "-Djava.io.tmpdir=/tmp"
99 "-Dcruise.console.publish.interval=10"
100 "-Djava.security.egd=file:/dev/./urandom"
102 defaultText = literalExpression ''
104 "-Xms''${config.${opt.initialJavaHeapSize}}"
105 "-Xmx''${config.${opt.maxJavaHeapMemory}}"
106 "-Djava.io.tmpdir=/tmp"
107 "-Dcruise.console.publish.interval=10"
108 "-Djava.security.egd=file:/dev/./urandom"
112 Specifies startup command line arguments to pass to Go.CD agent
117 extraOptions = mkOption {
119 type = types.listOf types.str;
122 "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5006"
124 "-Xloggc:go-agent-gc.log"
125 "-XX:+PrintGCTimeStamps"
126 "-XX:+PrintTenuringDistribution"
127 "-XX:+PrintGCDetails"
131 Specifies additional command line arguments to pass to Go.CD agent
132 java process. Example contains debug and gcLog arguments.
136 environment = mkOption {
138 type = with types; attrsOf str;
140 Additional environment variables to be passed to the Go.CD agent process.
141 As a base environment, Go.CD agent receives NIX_PATH from
142 {option}`environment.sessionVariables`, NIX_REMOTE is set to
149 config = mkIf cfg.enable {
150 users.groups = optionalAttrs (cfg.group == "gocd-agent") {
151 gocd-agent.gid = config.ids.gids.gocd-agent;
154 users.users = optionalAttrs (cfg.user == "gocd-agent") {
156 description = "gocd-agent user";
160 extraGroups = cfg.extraGroups;
161 useDefaultShell = true;
162 uid = config.ids.uids.gocd-agent;
166 systemd.services.gocd-agent = {
167 description = "GoCD Agent";
168 after = [ "network.target" ];
169 wantedBy = [ "multi-user.target" ];
173 selectedSessionVars =
174 lib.filterAttrs (n: v: builtins.elem n [ "NIX_PATH" ])
175 config.environment.sessionVariables;
177 selectedSessionVars //
179 NIX_REMOTE = "daemon";
180 AGENT_WORK_DIR = cfg.workDir;
181 AGENT_STARTUP_ARGS = ''${concatStringsSep " " cfg.startupOptions}'';
182 LOG_DIR = cfg.workDir;
183 LOG_FILE = "${cfg.workDir}/go-agent-start.log";
192 export PATH="''${MPATH}:''${PATH}";
194 if ! test -f ~/.nixpkgs/config.nix; then
196 echo "{ allowUnfree = true; }" > ~/.nixpkgs/config.nix
200 rm -f config/autoregister.properties
201 ln -s "${pkgs.writeText "autoregister.properties" cfg.agentConfig}" config/autoregister.properties
203 ${pkgs.git}/bin/git config --global --add http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
204 ${pkgs.jre}/bin/java ${concatStringsSep " " cfg.startupOptions} \
205 ${concatStringsSep " " cfg.extraOptions} \
206 -jar ${pkgs.gocd-agent}/go-agent/agent-bootstrapper.jar \
207 -serverUrl ${cfg.goServer}
212 WorkingDirectory = cfg.workDir;
214 Restart = "on-failure";