diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2018-12-11 18:10:48 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2018-12-11 18:10:48 +0300 |
commit | 8b0968b2054d3bb8d90b5ac056727f7c2ebeaed3 (patch) | |
tree | d03b70f693463fc836a8dbe4240424d2547530c8 /pkgs/jenkinsWithPlugins | |
parent | c4273035cf5876e3ba8ed2c6b492d31c2de290ee (diff) | |
download | nixsap-8b0968b2054d3bb8d90b5ac056727f7c2ebeaed3.tar.gz |
(* HUGE *) Use nixpkgs overlays
Diffstat (limited to 'pkgs/jenkinsWithPlugins')
-rw-r--r-- | pkgs/jenkinsWithPlugins/default.nix | 128 | ||||
-rw-r--r-- | pkgs/jenkinsWithPlugins/fromBase64.nix | 74 |
2 files changed, 202 insertions, 0 deletions
diff --git a/pkgs/jenkinsWithPlugins/default.nix b/pkgs/jenkinsWithPlugins/default.nix new file mode 100644 index 0000000..ebc12db --- /dev/null +++ b/pkgs/jenkinsWithPlugins/default.nix @@ -0,0 +1,128 @@ +{ pkgs, lib, stdenv, fetchurl }: + +/* + + `pluginsFunc` is a function that should return an attribute set of plugins + to be included in the WAR. + + The plugins are provided by `pkgs.jenkinsUpdateCenter.plugins`. + Dependencies between those plugins are automatically resolved within the + same jenkinsUpdateCenter. + + Example: + + pkgs.jenkinsWithPlugins + (plugins: { + inherit (plugins) BlameSubversion ... ; + inherit (pkgs) my-plugin; + }) + + Each attribute of `plugins` is a derivation and you can return in + the set any other plugins that are not available in Jenkins registry + (https://updates.jenkins-ci.org/) or replacing plugins in the registry. + + Non-optional dependencies, if any, are automatically added. Optional + dependencies are ignored, you have to add them explicitly. + +*/ + +pluginsFunc: + +let + + inherit (builtins) + attrNames fromJSON readFile ; + + inherit (lib) + concatStrings filter filterAttrs flatten genAttrs mapAttrs + mapAttrsToList unique ; + + fromBase64 = import ./fromBase64.nix; + + updateCenter = + let + registry = fromJSON (readFile pkgs.jenkinsUpdateCenter); + in + registry // { + core = with registry.core; fetchurl { + inherit url; + name = "jenkins-core-${version}.war"; + sha1 = fromBase64 sha1; + meta = registry.core; + }; + + plugins = mapAttrs ( + _: plugin: fetchurl { + inherit (plugin) url; + sha1 = fromBase64 plugin.sha1; + name = "jenkins-plugin-${plugin.name}-${plugin.version}.hpi"; + meta = plugin; + } + ) registry.plugins; + }; + + inherit (updateCenter) core; + + neededPlugins = + let + rootPlugins = pluginsFunc updateCenter.plugins; + hasDeps = _: p: (p ? meta) && (p.meta ? dependencies); + directDeps = nn: + let + isRequired = d: ! (d ? optional && d.optional); + deps = p: map (d: d.name) (filter isRequired p.meta.dependencies); + in flatten (map (n: deps updateCenter.plugins.${n}) nn); + + getDepsRecursive = nn: if nn == [] then [] else nn ++ getDepsRecursive (directDeps nn); + depNames = unique (getDepsRecursive (attrNames (filterAttrs hasDeps rootPlugins))); + deps = genAttrs depNames (n: updateCenter.plugins.${n}); + in deps // rootPlugins; + + pluginsPack = stdenv.mkDerivation { + name = "jenkins-plugins-pack"; + phases = [ "installPhase" ]; + installPhase = '' + mkdir -p $out + ${concatStrings ( + mapAttrsToList (n: p: '' + ln -svf '${p}' "$out/${n}.hpi" + '') neededPlugins)} + ''; + }; + + pack = stdenv.mkDerivation rec { + name = "jenkins-${core.meta.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}" 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 neededPlugins == [] then core else pack + diff --git a/pkgs/jenkinsWithPlugins/fromBase64.nix b/pkgs/jenkinsWithPlugins/fromBase64.nix new file mode 100644 index 0000000..3130f9c --- /dev/null +++ b/pkgs/jenkinsWithPlugins/fromBase64.nix @@ -0,0 +1,74 @@ +strBase64: + +let + + inherit (builtins) + concatStringsSep genList stringLength substring trace ; + + base64 = { + # n=0; for l in {A..Z} {a..z} {0..9} + /; do printf '"%s" = %2s; ' $l $n; (( n++ )); (( n % 8 )) || echo; done + "A" = 0; "B" = 1; "C" = 2; "D" = 3; "E" = 4; "F" = 5; "G" = 6; "H" = 7; + "I" = 8; "J" = 9; "K" = 10; "L" = 11; "M" = 12; "N" = 13; "O" = 14; "P" = 15; + "Q" = 16; "R" = 17; "S" = 18; "T" = 19; "U" = 20; "V" = 21; "W" = 22; "X" = 23; + "Y" = 24; "Z" = 25; "a" = 26; "b" = 27; "c" = 28; "d" = 29; "e" = 30; "f" = 31; + "g" = 32; "h" = 33; "i" = 34; "j" = 35; "k" = 36; "l" = 37; "m" = 38; "n" = 39; + "o" = 40; "p" = 41; "q" = 42; "r" = 43; "s" = 44; "t" = 45; "u" = 46; "v" = 47; + "w" = 48; "x" = 49; "y" = 50; "z" = 51; "0" = 52; "1" = 53; "2" = 54; "3" = 55; + "4" = 56; "5" = 57; "6" = 58; "7" = 59; "8" = 60; "9" = 61; "+" = 62; "/" = 63; + }; + + quartet_to_int24 = q: + # https://en.wikipedia.org/wiki/Base64 + let + s = n: assert (stringLength q == 4); substring (3 - n) 1 q; + d = n: base64.${s n}; + in if s 0 != "=" then + 64 * (64 * (64 * (d 3) + (d 2)) + (d 1)) + (d 0) + else if s 1 != "=" then + 64 * (64 * (64 * (d 3) + (d 2)) + (d 1)) / 256 # right shift by 8 bits + else + 64 * (64 * (64 * (d 3) + (d 2))) / 65536 # right shift by 16 bits + ; + + int24_to_hex = i: # 16777215 (0xFFFFFF, 2^24-1) max + let + hex = "0123456789abcdef"; + toHex = n: + let + d = n / 16; + r = n - 16 * d; + in "${if d != 0 then toHex d else ""}${substring r 1 hex}"; + in assert (0 <= i && i <= 16777215); toHex i; + + quartets = s: + let + l = stringLength s; + h = substring 0 4 s; + t = substring 4 (l - 4) s; + in [h] ++ (if t != "" then quartets t else []); + + + quartet_to_hex = q: # base64 quartet into hex with padding + let + i = quartet_to_int24 q; + h = int24_to_hex i; + s = if substring 2 1 q == "=" then 1 + else if substring 3 1 q == "=" then 2 + else 3; # number of bytes + w = s * 2; # number of hexadecimal digits + filler = concatStringsSep "" (genList (_: "0") (w - stringLength h)); + in "${filler}${h}"; + +/* + + FIXME: usage of library functions like concatMapString + causes very cryptic errors: + + # nix-instantiate --eval --expr 'import ./fromBase64.nix "kjOzmCPxyw0bPciMsGSh5q+bT9g="' --show-trace + error: while evaluating anonymous function at .../fromBase64.nix:1:1, called from (string):1:18: + value is a function while a set was expected, at .../fromBase64.nix:3:4 + +*/ + +in concatStringsSep "" (map quartet_to_hex (quartets strBase64)) + |