aboutsummaryrefslogtreecommitdiff
path: root/modules/pkgs/jenkinsWithPlugins/default.nix
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2016-10-11 22:15:42 +0300
committerIgor Pashev <pashev.igor@gmail.com>2016-10-11 22:19:48 +0300
commit592dee8bef92debede3724bf5ddbf8249c30c488 (patch)
treeff712306134e04625938ef112a3a3f8084c65c3d /modules/pkgs/jenkinsWithPlugins/default.nix
parent1a4d734a4110a05e08b88b539b7ea4939d2d1c36 (diff)
downloadnixsap-592dee8bef92debede3724bf5ddbf8249c30c488.tar.gz
Added Jenkins package composable with plugins
Diffstat (limited to 'modules/pkgs/jenkinsWithPlugins/default.nix')
-rw-r--r--modules/pkgs/jenkinsWithPlugins/default.nix97
1 files changed, 97 insertions, 0 deletions
diff --git a/modules/pkgs/jenkinsWithPlugins/default.nix b/modules/pkgs/jenkinsWithPlugins/default.nix
new file mode 100644
index 0000000..4a8e0ce
--- /dev/null
+++ b/modules/pkgs/jenkinsWithPlugins/default.nix
@@ -0,0 +1,97 @@
+{ pkgs, lib, stdenv, fetchurl }:
+
+/*
+
+ This is a function that should return a list of plugins to be included in the WAR.
+ Example: pkgs.jenkinsWithPlugins (plugins: [ plugins.BlameSubversion ... ])
+
+ Non-optional dependencies, if any, are automatically added. Optional
+ dependencies are ignored, you have to added them explicitly.
+
+*/
+
+pluginsFunc:
+
+let
+
+ inherit (builtins) fromJSON readFile;
+ fromBase64 = import ./fromBase64.nix;
+
+ inherit (lib)
+ concatMapStrings filter flatten unique ;
+
+ /*
+ jq to make it human readable:
+ curl https://updates.jenkins-ci.org/current/update-center.actual.json | jq . > update-center.actual.json
+ */
+
+ # capture into nix store to track changes:
+ updateCenter = fromJSON (readFile "${./update-center.actual.json}");
+
+ core = with updateCenter.core; fetchurl {
+ inherit url;
+ name = "jenkins-${version}-core.war";
+ sha1 = fromBase64 sha1;
+ };
+
+ plugin = p: fetchurl {
+ inherit (p) url;
+ sha1 = fromBase64 p.sha1;
+ name = "jenkins-plugin-${p.name}-${p.version}.hpi";
+ };
+
+ pluginsPack = list: stdenv.mkDerivation {
+ name = "jenkins-plugins-pack";
+ phases = [ "installPhase" ];
+ installPhase = ''
+ mkdir -p $out
+ ${concatMapStrings (p: ''
+ ln -svf "${plugin p}" "$out/${p.name}.hpi"
+ '') list}
+ '';
+ };
+
+ requestedPlugins =
+ let
+ explicit = pluginsFunc updateCenter.plugins;
+ deps = map (p: map (d: updateCenter.plugins.${d.name})
+ (filter (d: ! d.optional) p.dependencies)
+ ) explicit;
+ in unique ( explicit ++ flatten deps );
+
+ pack = stdenv.mkDerivation rec {
+ name = "jenkins-${updateCenter.core.version}+plugins.war";
+
+ # https://wiki.jenkins-ci.org/display/JENKINS/Bundling+plugins+with+Jenkins
+ build-xml = pkgs.writeXML "jenkins.build.xml"
+ ''
+ <?xml version="1.0" encoding="UTF-8"?>
+ <project basedir="." name="Jenkins-Bundle">
+ <target name="bundle" description="Merge plugins into jenkins.war">
+ <zip destfile="jenkins.war" level="9">
+ <zipfileset src="${core}" />
+ <zipfileset dir="${pluginsPack requestedPlugins}" prefix="WEB-INF/plugins" />
+ </zip>
+ </target>
+ </project>
+ '';
+
+ meta = with stdenv.lib; {
+ description = "An extendable open source continuous integration server";
+ homepage = http://jenkins-ci.org;
+ license = licenses.mit;
+ platforms = platforms.all;
+ };
+
+ buildInputs = with pkgs; [ ant jdk ];
+
+ phases = [ "buildPhase" "installPhase" ];
+ buildPhase = ''
+ ln -sf ${build-xml} build.xml
+ ant bundle
+ '';
+ installPhase = "cp jenkins.war $out";
+ };
+
+in if requestedPlugins == [] then core else pack
+