9 cfg = config.services.gocd-agent;
10 opt = options.services.gocd-agent;
14 services.gocd-agent = {
15 enable = lib.mkEnableOption "gocd-agent";
18 default = "gocd-agent";
21 User the Go.CD agent should execute under.
25 group = lib.mkOption {
26 default = "gocd-agent";
29 If the default user "gocd-agent" is configured then this is the primary
34 extraGroups = lib.mkOption {
35 type = lib.types.listOf lib.types.str;
42 List of extra groups that the "gocd-agent" user should be a part of.
46 packages = lib.mkOption {
51 config.programs.ssh.package
54 defaultText = lib.literalExpression "[ pkgs.stdenv pkgs.jre pkgs.git config.programs.ssh.package pkgs.nix ]";
55 type = lib.types.listOf lib.types.package;
57 Packages to add to PATH for the Go.CD agent process.
61 agentConfig = lib.mkOption {
65 agent.auto.register.resources=ant,java
66 agent.auto.register.environments=QA,Performance
67 agent.auto.register.hostname=Agent01
70 Agent registration configuration.
74 goServer = lib.mkOption {
75 default = "https://127.0.0.1:8154/go";
78 URL of the GoCD Server to attach the Go.CD Agent to.
82 workDir = lib.mkOption {
83 default = "/var/lib/go-agent";
86 Specifies the working directory in which the Go.CD agent java archive resides.
90 initialJavaHeapSize = lib.mkOption {
94 Specifies the initial java heap memory size for the Go.CD agent java process.
98 maxJavaHeapMemory = lib.mkOption {
100 type = lib.types.str;
102 Specifies the java maximum heap memory size for the Go.CD agent java process.
106 startupOptions = lib.mkOption {
107 type = lib.types.listOf lib.types.str;
109 "-Xms${cfg.initialJavaHeapSize}"
110 "-Xmx${cfg.maxJavaHeapMemory}"
111 "-Djava.io.tmpdir=/tmp"
112 "-Dcruise.console.publish.interval=10"
113 "-Djava.security.egd=file:/dev/./urandom"
115 defaultText = lib.literalExpression ''
117 "-Xms''${config.${opt.initialJavaHeapSize}}"
118 "-Xmx''${config.${opt.maxJavaHeapMemory}}"
119 "-Djava.io.tmpdir=/tmp"
120 "-Dcruise.console.publish.interval=10"
121 "-Djava.security.egd=file:/dev/./urandom"
125 Specifies startup command line arguments to pass to Go.CD agent
130 extraOptions = lib.mkOption {
132 type = lib.types.listOf lib.types.str;
135 "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5006"
137 "-Xloggc:go-agent-gc.log"
138 "-XX:+PrintGCTimeStamps"
139 "-XX:+PrintTenuringDistribution"
140 "-XX:+PrintGCDetails"
144 Specifies additional command line arguments to pass to Go.CD agent
145 java process. Example contains debug and gcLog arguments.
149 environment = lib.mkOption {
151 type = with lib.types; attrsOf str;
153 Additional environment variables to be passed to the Go.CD agent process.
154 As a base environment, Go.CD agent receives NIX_PATH from
155 {option}`environment.sessionVariables`, NIX_REMOTE is set to
162 config = lib.mkIf cfg.enable {
163 users.groups = lib.optionalAttrs (cfg.group == "gocd-agent") {
164 gocd-agent.gid = config.ids.gids.gocd-agent;
167 users.users = lib.optionalAttrs (cfg.user == "gocd-agent") {
169 description = "gocd-agent user";
173 extraGroups = cfg.extraGroups;
174 useDefaultShell = true;
175 uid = config.ids.uids.gocd-agent;
179 systemd.services.gocd-agent = {
180 description = "GoCD Agent";
181 after = [ "network.target" ];
182 wantedBy = [ "multi-user.target" ];
186 selectedSessionVars = lib.filterAttrs (
187 n: v: builtins.elem n [ "NIX_PATH" ]
188 ) config.environment.sessionVariables;
192 NIX_REMOTE = "daemon";
193 AGENT_WORK_DIR = cfg.workDir;
194 AGENT_STARTUP_ARGS = ''${lib.concatStringsSep " " cfg.startupOptions}'';
195 LOG_DIR = cfg.workDir;
196 LOG_FILE = "${cfg.workDir}/go-agent-start.log";
205 export PATH="''${MPATH}:''${PATH}";
207 if ! test -f ~/.nixpkgs/config.nix; then
209 echo "{ allowUnfree = true; }" > ~/.nixpkgs/config.nix
213 rm -f config/autoregister.properties
214 ln -s "${pkgs.writeText "autoregister.properties" cfg.agentConfig}" config/autoregister.properties
216 ${pkgs.git}/bin/git config --global --add http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
217 ${pkgs.jre}/bin/java ${lib.concatStringsSep " " cfg.startupOptions} \
218 ${lib.concatStringsSep " " cfg.extraOptions} \
219 -jar ${pkgs.gocd-agent}/go-agent/agent-bootstrapper.jar \
220 -serverUrl ${cfg.goServer}
225 WorkingDirectory = cfg.workDir;
227 Restart = "on-failure";