
Jenkins gets (by default) an additional environment of { NIX_REMOTE = "daemon"; } This has the following problems: 1. NIX_REMOTE disappears when users specify additional environment variables, because defaults have low merge priority. 2. nix cannot be used without additional NIX_PATH envvar, which is currently missing. 3. If you try to use HTTPS, you'll see that jenkins lacks SSL_CERT_FILE envvar, causing it to fail. This commit adds config.environment.sessionVariables and NIX_REMOTE to the set of variables that are always there for jenkins, making nix and HTTPS work out of the box. services.jenkins.environment is now empty by default.
145 lines
4.0 KiB
Nix
145 lines
4.0 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
with lib;
|
|
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";
|
|
type = types.str;
|
|
description = ''
|
|
User the jenkins server should execute under.
|
|
'';
|
|
};
|
|
|
|
group = mkOption {
|
|
default = "jenkins";
|
|
type = types.str;
|
|
description = ''
|
|
If the default user "jenkins" is configured then this is the primary
|
|
group of that user.
|
|
'';
|
|
};
|
|
|
|
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.
|
|
'';
|
|
};
|
|
|
|
home = mkOption {
|
|
default = "/var/lib/jenkins";
|
|
type = types.path;
|
|
description = ''
|
|
The path to use as JENKINS_HOME. If the default user "jenkins" is configured then
|
|
this is the home of the "jenkins" user.
|
|
'';
|
|
};
|
|
|
|
port = mkOption {
|
|
default = 8080;
|
|
type = types.int;
|
|
description = ''
|
|
Specifies port number on which the jenkins HTTP interface listens. The default is 8080.
|
|
'';
|
|
};
|
|
|
|
packages = mkOption {
|
|
default = [ pkgs.stdenv pkgs.git pkgs.jdk config.programs.ssh.package pkgs.nix ];
|
|
type = types.listOf types.package;
|
|
description = ''
|
|
Packages to add to PATH for the jenkins process.
|
|
'';
|
|
};
|
|
|
|
environment = mkOption {
|
|
default = { };
|
|
type = with types; attrsOf str;
|
|
description = ''
|
|
Additional environment variables to be passed to the jenkins process.
|
|
This setting will merge with everything in
|
|
<option>config.environment.sessionVariables</option>,
|
|
JENKINS_HOME and NIX_REMOTE. This option takes precedence and can
|
|
override any previously set environment variable.
|
|
'';
|
|
};
|
|
|
|
extraOptions = mkOption {
|
|
type = types.listOf types.str;
|
|
default = [ ];
|
|
example = [ "--debug=9" "--httpListenAddress=localhost" ];
|
|
description = ''
|
|
Additional command line arguments to pass to Jenkins.
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
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;
|
|
extraGroups = cfg.extraGroups;
|
|
useDefaultShell = true;
|
|
uid = config.ids.uids.jenkins;
|
|
};
|
|
|
|
systemd.services.jenkins = {
|
|
description = "Jenkins Continuous Integration Server";
|
|
after = [ "network.target" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
environment =
|
|
config.environment.sessionVariables //
|
|
{ JENKINS_HOME = cfg.home;
|
|
NIX_REMOTE = "daemon";
|
|
} //
|
|
cfg.environment;
|
|
|
|
path = cfg.packages;
|
|
|
|
script = ''
|
|
${pkgs.jdk}/bin/java -jar ${pkgs.jenkins} --httpPort=${toString cfg.port} ${concatStringsSep " " cfg.extraOptions}
|
|
'';
|
|
|
|
postStart = ''
|
|
until ${pkgs.curl}/bin/curl -s -L localhost:${toString cfg.port} ; do
|
|
sleep 10
|
|
done
|
|
while true ; do
|
|
index=`${pkgs.curl}/bin/curl -s -L localhost:${toString cfg.port}`
|
|
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;
|
|
};
|
|
};
|
|
};
|
|
}
|