2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
2014-02-10 20:07:12 +00:00
|
|
|
let
|
|
|
|
cfg = config.services.jenkins;
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.jenkins = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable the jenkins continuous integration server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
default = "jenkins";
|
2014-09-09 16:35:24 +01:00
|
|
|
type = types.str;
|
2014-02-10 20:07:12 +00:00
|
|
|
description = ''
|
2014-03-06 18:06:53 +00:00
|
|
|
User the jenkins server should execute under.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
default = "jenkins";
|
2014-09-09 16:35:24 +01:00
|
|
|
type = types.str;
|
2014-03-06 18:06:53 +00:00
|
|
|
description = ''
|
2014-04-09 20:04:49 +01:00
|
|
|
If the default user "jenkins" is configured then this is the primary
|
|
|
|
group of that user.
|
2014-02-10 20:07:12 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-09-12 14:22:25 +01:00
|
|
|
extraGroups = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "wheel" "dialout" ];
|
|
|
|
description = ''
|
|
|
|
List of extra groups that the "jenkins" user should be a part of.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-02-10 20:07:12 +00:00
|
|
|
home = mkOption {
|
2014-03-06 18:06:53 +00:00
|
|
|
default = "/var/lib/jenkins";
|
2014-09-09 16:35:24 +01:00
|
|
|
type = types.path;
|
2014-02-10 20:07:12 +00:00
|
|
|
description = ''
|
2014-03-06 18:06:53 +00:00
|
|
|
The path to use as JENKINS_HOME. If the default user "jenkins" is configured then
|
|
|
|
this is the home of the "jenkins" user.
|
2014-02-10 20:07:12 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-12-23 08:19:18 +00:00
|
|
|
host = mkOption {
|
|
|
|
default = "0.0.0.0";
|
|
|
|
example = "localhost";
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
Specifies the bind adress on which the jenkins HTTP interface listens.
|
|
|
|
The default is the wildcard adress.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-02-10 20:07:12 +00:00
|
|
|
port = mkOption {
|
|
|
|
default = 8080;
|
2015-06-15 17:11:32 +01:00
|
|
|
type = types.int;
|
2014-02-10 20:07:12 +00:00
|
|
|
description = ''
|
2015-12-23 08:19:18 +00:00
|
|
|
Specifies port number on which the jenkins HTTP interface listens.
|
|
|
|
The default is 8080.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
prefix = mkOption {
|
|
|
|
default = "";
|
|
|
|
example = "/jenkins";
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
Specifies a urlPrefix to use with jenkins.
|
|
|
|
If the example /jenkins is given, the jenkins server will be
|
|
|
|
accessible using localhost:8080/jenkins.
|
2014-02-10 20:07:12 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
packages = mkOption {
|
2015-06-27 01:09:58 +01:00
|
|
|
default = [ pkgs.stdenv pkgs.git pkgs.jdk config.programs.ssh.package pkgs.nix ];
|
2014-02-10 20:07:12 +00:00
|
|
|
type = types.listOf types.package;
|
|
|
|
description = ''
|
|
|
|
Packages to add to PATH for the jenkins process.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
environment = mkOption {
|
2015-10-04 15:11:28 +01:00
|
|
|
default = { };
|
2014-09-09 16:35:24 +01:00
|
|
|
type = with types; attrsOf str;
|
2014-02-10 20:07:12 +00:00
|
|
|
description = ''
|
|
|
|
Additional environment variables to be passed to the jenkins process.
|
2015-10-06 20:41:13 +01:00
|
|
|
As a base environment, jenkins receives NIX_PATH, SSL_CERT_FILE and
|
|
|
|
GIT_SSL_CAINFO from <option>environment.sessionVariables</option>,
|
|
|
|
NIX_REMOTE is set to "daemon" and JENKINS_HOME is set to
|
|
|
|
the value of <option>services.jenkins.home</option>. This option has
|
|
|
|
precedence and can be used to override those mentioned variables.
|
2014-02-10 20:07:12 +00:00
|
|
|
'';
|
|
|
|
};
|
2014-09-09 16:34:49 +01:00
|
|
|
|
2014-09-09 16:38:40 +01:00
|
|
|
extraOptions = mkOption {
|
2014-09-09 16:34:49 +01:00
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
2015-12-23 08:19:18 +00:00
|
|
|
example = [ "--debug=9" ];
|
2014-09-09 16:34:49 +01:00
|
|
|
description = ''
|
|
|
|
Additional command line arguments to pass to Jenkins.
|
|
|
|
'';
|
|
|
|
};
|
2014-02-10 20:07:12 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2014-03-06 18:06:53 +00:00
|
|
|
users.extraGroups = optional (cfg.group == "jenkins") {
|
|
|
|
name = "jenkins";
|
|
|
|
gid = config.ids.gids.jenkins;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraUsers = optional (cfg.user == "jenkins") {
|
|
|
|
name = "jenkins";
|
|
|
|
description = "jenkins user";
|
|
|
|
createHome = true;
|
|
|
|
home = cfg.home;
|
|
|
|
group = cfg.group;
|
2014-09-12 14:22:25 +01:00
|
|
|
extraGroups = cfg.extraGroups;
|
2014-03-06 18:06:53 +00:00
|
|
|
useDefaultShell = true;
|
|
|
|
uid = config.ids.uids.jenkins;
|
|
|
|
};
|
2014-02-10 20:07:12 +00:00
|
|
|
|
|
|
|
systemd.services.jenkins = {
|
2014-02-25 23:44:07 +00:00
|
|
|
description = "Jenkins Continuous Integration Server";
|
2014-02-10 20:07:12 +00:00
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
2015-10-04 15:11:28 +01:00
|
|
|
environment =
|
2015-10-06 20:41:13 +01:00
|
|
|
let
|
|
|
|
selectedSessionVars =
|
|
|
|
lib.filterAttrs (n: v: builtins.elem n
|
|
|
|
[ "NIX_PATH"
|
|
|
|
"SSL_CERT_FILE"
|
|
|
|
"GIT_SSL_CAINFO"
|
|
|
|
])
|
|
|
|
config.environment.sessionVariables;
|
|
|
|
in
|
|
|
|
selectedSessionVars //
|
|
|
|
{ JENKINS_HOME = cfg.home;
|
|
|
|
NIX_REMOTE = "daemon";
|
|
|
|
} //
|
|
|
|
cfg.environment;
|
2014-02-10 20:07:12 +00:00
|
|
|
|
|
|
|
path = cfg.packages;
|
|
|
|
|
2015-11-02 09:25:11 +00:00
|
|
|
# Force .war (re)extraction, or else we might run stale Jenkins.
|
|
|
|
preStart = ''
|
|
|
|
rm -rf ${cfg.home}/war
|
|
|
|
'';
|
|
|
|
|
2014-02-10 20:07:12 +00:00
|
|
|
script = ''
|
2015-12-23 08:19:18 +00:00
|
|
|
${pkgs.jdk}/bin/java -jar ${pkgs.jenkins} --httpListenAddress=${cfg.host} \
|
|
|
|
--httpPort=${toString cfg.port} \
|
|
|
|
--prefix=${cfg.prefix} \
|
|
|
|
${concatStringsSep " " cfg.extraOptions}
|
2014-02-10 20:07:12 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
postStart = ''
|
2015-12-23 08:19:18 +00:00
|
|
|
until ${pkgs.curl}/bin/curl -s -L ${cfg.host}:${toString cfg.port}${cfg.prefix} ; do
|
2014-02-10 20:07:12 +00:00
|
|
|
sleep 10
|
|
|
|
done
|
|
|
|
while true ; do
|
2015-12-23 08:19:18 +00:00
|
|
|
index=`${pkgs.curl}/bin/curl -s -L ${cfg.host}:${toString cfg.port}${cfg.prefix}`
|
2014-02-10 20:07:12 +00:00
|
|
|
if [[ !("$index" =~ 'Please wait while Jenkins is restarting' ||
|
|
|
|
"$index" =~ 'Please wait while Jenkins is getting ready to work') ]]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
sleep 30
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|