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
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
default = 8080;
|
|
|
|
type = types.uniq types.int;
|
|
|
|
description = ''
|
2014-04-11 16:15:56 +01:00
|
|
|
Specifies port number on which the jenkins HTTP interface listens. The default is 8080.
|
2014-02-10 20:07:12 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
packages = mkOption {
|
|
|
|
default = [ pkgs.stdenv pkgs.git pkgs.jdk pkgs.openssh pkgs.nix ];
|
|
|
|
type = types.listOf types.package;
|
|
|
|
description = ''
|
|
|
|
Packages to add to PATH for the jenkins process.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
environment = mkOption {
|
|
|
|
default = { NIX_REMOTE = "daemon"; };
|
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.
|
|
|
|
The environment will always include JENKINS_HOME.
|
|
|
|
'';
|
|
|
|
};
|
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 = [ ];
|
|
|
|
example = [ "--debug=9" "--httpListenAddress=localhost" ];
|
|
|
|
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" ];
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
JENKINS_HOME = cfg.home;
|
|
|
|
} // cfg.environment;
|
|
|
|
|
|
|
|
path = cfg.packages;
|
|
|
|
|
|
|
|
script = ''
|
2014-09-09 16:38:40 +01:00
|
|
|
${pkgs.jdk}/bin/java -jar ${pkgs.jenkins} --httpPort=${toString cfg.port} ${concatStringsSep " " cfg.extraOptions}
|
2014-02-10 20:07:12 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
postStart = ''
|
2014-02-25 23:44:07 +00:00
|
|
|
until ${pkgs.curl}/bin/curl -s -L localhost:${toString cfg.port} ; do
|
2014-02-10 20:07:12 +00:00
|
|
|
sleep 10
|
|
|
|
done
|
|
|
|
while true ; do
|
2014-02-25 23:44:07 +00:00
|
|
|
index=`${pkgs.curl}/bin/curl -s -L localhost:${toString cfg.port}`
|
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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|