summary refs log tree commit diff
path: root/nixos/modules/services/continuous-integration/jenkins/default.nix
diff options
context:
space:
mode:
authorCorey O'Connor <coreyoconnor@gmail.com>2014-02-10 12:07:12 -0800
committerCorey O'Connor <coreyoconnor@gmail.com>2014-03-13 13:01:49 -0700
commit9b79d5b298ead3bfdc14e32b179aec1b08434c10 (patch)
tree3038c355c4617ddd46591fd801e6da815ac0bd44 /nixos/modules/services/continuous-integration/jenkins/default.nix
parent0f72effdd96e46401b5c3c3a6839f9c880822585 (diff)
downloadnixpkgs-9b79d5b298ead3bfdc14e32b179aec1b08434c10.tar
nixpkgs-9b79d5b298ead3bfdc14e32b179aec1b08434c10.tar.gz
nixpkgs-9b79d5b298ead3bfdc14e32b179aec1b08434c10.tar.bz2
nixpkgs-9b79d5b298ead3bfdc14e32b179aec1b08434c10.tar.lz
nixpkgs-9b79d5b298ead3bfdc14e32b179aec1b08434c10.tar.xz
nixpkgs-9b79d5b298ead3bfdc14e32b179aec1b08434c10.tar.zst
nixpkgs-9b79d5b298ead3bfdc14e32b179aec1b08434c10.zip
Add jenkins continuous integration server and user.
By default the jenkins server is executed under the user "jenkins". Which can be configured using
users.jenkins.* options. If a different user is requested by changing services.jenkins.user then
none of the users.jenkins options apply.

This patch does not include jenkins slave configuration. Some config options will probably change
when this is implemented.

Aspects like the user and environment are typically identical between slave and master. The service
configs are different. The design is for users.jenkins to cover the shared aspects while
services.jenkins and services.jenkins-slave cover the master and slave specific aspects,
respectively.

Another option would be to place everything under services.jenkins and have a config that selects
master vs slave.
Diffstat (limited to 'nixos/modules/services/continuous-integration/jenkins/default.nix')
-rw-r--r--nixos/modules/services/continuous-integration/jenkins/default.nix97
1 files changed, 97 insertions, 0 deletions
diff --git a/nixos/modules/services/continuous-integration/jenkins/default.nix b/nixos/modules/services/continuous-integration/jenkins/default.nix
new file mode 100644
index 00000000000..330dbab14e7
--- /dev/null
+++ b/nixos/modules/services/continuous-integration/jenkins/default.nix
@@ -0,0 +1,97 @@
+{ config, pkgs, ... }:
+with pkgs.lib;
+let
+  cfg = config.services.jenkins;
+  userCfg = config.users.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 = with types; string;
+        description = ''
+          User the jenkins server should execute under. Defaults to the "jenkins" user.
+        '';
+      };
+
+      home = mkOption {
+        default = userCfg.home;
+        type = with types; string;
+        description = ''
+          The path to use as JENKINS_HOME. Defaults to the home of the "jenkins" user.
+        '';
+      };
+
+      port = mkOption {
+        default = 8080;
+        type = types.uniq 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 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"; };
+        type = with types; attrsOf string;
+        description = ''
+          Additional environment variables to be passed to the jenkins process.
+          The environment will always include JENKINS_HOME.
+        '';
+      };
+    };
+  };
+
+  config = mkIf cfg.enable {
+    users.jenkins.enable = true;
+
+    systemd.services.jenkins = {
+      description = "jenkins continuous integration server";
+      after = [ "network.target" ];
+      wantedBy = [ "multi-user.target" ];
+
+      environment = {
+        JENKINS_HOME = cfg.home;
+      } // cfg.environment;
+
+      path = cfg.packages;
+
+      script = ''
+        ${pkgs.jdk}/bin/java -jar ${pkgs.jenkins} --httpPort=${toString cfg.port}
+      '';
+
+      postStart = ''
+        until ${pkgs.curl}/bin/curl -L localhost:${toString cfg.port} ; do
+          sleep 10
+        done
+        while true ; do
+          index=`${pkgs.curl}/bin/curl -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;
+      };
+    };
+  };
+}