1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.gocd-server; 7in { 8 options = { 9 services.gocd-server = { 10 enable = mkEnableOption "gocd-server"; 11 12 user = mkOption { 13 default = "gocd-server"; 14 type = types.str; 15 description = '' 16 User the Go.CD server should execute under. 17 ''; 18 }; 19 20 group = mkOption { 21 default = "gocd-server"; 22 type = types.str; 23 description = '' 24 If the default user "gocd-server" is configured then this is the primary group of that user. 25 ''; 26 }; 27 28 extraGroups = mkOption { 29 default = [ ]; 30 example = [ "wheel" "docker" ]; 31 description = '' 32 List of extra groups that the "gocd-server" user should be a part of. 33 ''; 34 }; 35 36 listenAddress = mkOption { 37 default = "0.0.0.0"; 38 example = "localhost"; 39 type = types.str; 40 description = '' 41 Specifies the bind address on which the Go.CD server HTTP interface listens. 42 ''; 43 }; 44 45 port = mkOption { 46 default = 8153; 47 type = types.int; 48 description = '' 49 Specifies port number on which the Go.CD server HTTP interface listens. 50 ''; 51 }; 52 53 sslPort = mkOption { 54 default = 8154; 55 type = types.int; 56 description = '' 57 Specifies port number on which the Go.CD server HTTPS interface listens. 58 ''; 59 }; 60 61 workDir = mkOption { 62 default = "/var/lib/go-server"; 63 type = types.str; 64 description = '' 65 Specifies the working directory in which the Go.CD server java archive resides. 66 ''; 67 }; 68 69 packages = mkOption { 70 default = [ pkgs.stdenv pkgs.jre pkgs.git config.programs.ssh.package pkgs.nix ]; 71 type = types.listOf types.package; 72 description = '' 73 Packages to add to PATH for the Go.CD server's process. 74 ''; 75 }; 76 77 initialJavaHeapSize = mkOption { 78 default = "512m"; 79 type = types.str; 80 description = '' 81 Specifies the initial java heap memory size for the Go.CD server's java process. 82 ''; 83 }; 84 85 maxJavaHeapMemory = mkOption { 86 default = "1024m"; 87 type = types.str; 88 description = '' 89 Specifies the java maximum heap memory size for the Go.CD server's java process. 90 ''; 91 }; 92 93 extraOptions = mkOption { 94 default = [ 95 "-Xms${cfg.initialJavaHeapSize}" 96 "-Xmx${cfg.maxJavaHeapMemory}" 97 "-Dcruise.listen.host=${cfg.listenAddress}" 98 "-Duser.language=en" 99 "-Djruby.rack.request.size.threshold.bytes=30000000" 100 "-Duser.country=US" 101 "-Dcruise.config.dir=${cfg.workDir}/conf" 102 "-Dcruise.config.file=${cfg.workDir}/conf/cruise-config.xml" 103 "-Dcruise.server.port=${toString cfg.port}" 104 "-Dcruise.server.ssl.port=${toString cfg.sslPort}" 105 ]; 106 example = [ 107 "-X debug" 108 "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005" 109 "-verbose:gc" 110 "-Xloggc:go-server-gc.log" 111 "-XX:+PrintGCTimeStamps" 112 "-XX:+PrintTenuringDistribution" 113 "-XX:+PrintGCDetails" 114 "-XX:+PrintGC" 115 ]; 116 description = '' 117 Specifies additional command line arguments to pass to Go.CD server's 118 java process. Example contains debug and gcLog arguments. 119 ''; 120 }; 121 122 environment = mkOption { 123 default = { }; 124 type = with types; attrsOf str; 125 description = '' 126 Additional environment variables to be passed to the gocd-server process. 127 As a base environment, gocd-server receives NIX_PATH from 128 <option>environment.sessionVariables</option>, NIX_REMOTE is set to 129 "daemon". 130 ''; 131 }; 132 }; 133 }; 134 135 config = mkIf cfg.enable { 136 users.extraGroups = optional (cfg.group == "gocd-server") { 137 name = "gocd-server"; 138 gid = config.ids.gids.gocd-server; 139 }; 140 141 users.extraUsers = optional (cfg.user == "gocd-server") { 142 name = "gocd-server"; 143 description = "gocd-server user"; 144 createHome = true; 145 home = cfg.workDir; 146 group = cfg.group; 147 extraGroups = cfg.extraGroups; 148 useDefaultShell = true; 149 uid = config.ids.uids.gocd-server; 150 }; 151 152 systemd.services.gocd-server = { 153 description = "GoCD Server"; 154 after = [ "network.target" ]; 155 wantedBy = [ "multi-user.target" ]; 156 157 environment = 158 let 159 selectedSessionVars = 160 lib.filterAttrs (n: v: builtins.elem n [ "NIX_PATH" ]) 161 config.environment.sessionVariables; 162 in 163 selectedSessionVars // 164 { NIX_REMOTE = "daemon"; 165 } // 166 cfg.environment; 167 168 path = cfg.packages; 169 170 script = '' 171 ${pkgs.git}/bin/git config --global --add http.sslCAinfo /etc/ssl/certs/ca-certificates.crt 172 ${pkgs.jre}/bin/java -server ${concatStringsSep " " cfg.extraOptions} \ 173 -jar ${pkgs.gocd-server}/go-server/go.jar 174 ''; 175 176 serviceConfig = { 177 User = cfg.user; 178 Group = cfg.group; 179 WorkingDirectory = cfg.workDir; 180 }; 181 }; 182 }; 183}