1{ lib, stdenv, makeWrapper, openjdk, gtk2, xorg, glibcLocales, releasePath ? null }:
2
3# To use this package, you need to download your own cplex installer from IBM
4# and override the releasePath attribute to point to the location of the file.
5#
6# Note: cplex creates an individual build for each license which screws
7# somewhat with the use of functions like requireFile as the hash will be
8# different for every user.
9
10stdenv.mkDerivation rec {
11 pname = "cplex";
12 version = "128";
13
14 src =
15 if releasePath == null then
16 throw ''
17 This nix expression requires that the cplex installer is already
18 downloaded to your machine. Get it from IBM:
19 https://developer.ibm.com/docloud/blog/2017/12/20/cplex-optimization-studio-12-8-now-available/
20
21 Set `cplex.releasePath = /path/to/download;` in your
22 ~/.config/nixpkgs/config.nix for `nix-*` commands, or
23 `config.cplex.releasePath = /path/to/download;` in your
24 `configuration.nix` for NixOS.
25 ''
26 else
27 releasePath;
28
29 nativeBuildInputs = [ makeWrapper ];
30 buildInputs = [ openjdk gtk2 xorg.libXtst glibcLocales ];
31
32 unpackPhase = "cp $src $name";
33
34 patchPhase = ''
35 sed -i -e 's|/usr/bin/tr"|tr" |' $name
36 '';
37
38 buildPhase = ''
39 sh $name -i silent -DLICENSE_ACCEPTED=TRUE -DUSER_INSTALL_DIR=$out
40 '';
41
42 installPhase = ''
43 mkdir -p $out/bin
44 ln -s $out/opl/bin/x86-64_linux/oplrun\
45 $out/opl/bin/x86-64_linux/oplrunjava\
46 $out/opl/oplide/oplide\
47 $out/cplex/bin/x86-64_linux/cplex\
48 $out/cpoptimizer/bin/x86-64_linux/cpoptimizer\
49 $out/bin
50 '';
51
52 fixupPhase =
53 let
54 libraryPath = lib.makeLibraryPath [ stdenv.cc.cc gtk2 xorg.libXtst ];
55 in ''
56 interpreter=${stdenv.cc.libc}/lib/ld-linux-x86-64.so.2
57
58 for pgm in $out/opl/bin/x86-64_linux/oplrun $out/opl/bin/x86-64_linux/oplrunjava $out/opl/oplide/oplide;
59 do
60 patchelf --set-interpreter "$interpreter" $pgm;
61 wrapProgram $pgm \
62 --prefix LD_LIBRARY_PATH : $out/opl/bin/x86-64_linux:${libraryPath} \
63 --set LOCALE_ARCHIVE ${glibcLocales}/lib/locale/locale-archive;
64 done
65
66 for pgm in $out/cplex/bin/x86-64_linux/cplex $out/cpoptimizer/bin/x86-64_linux/cpoptimizer $out/opl/oplide/jre/bin/*;
67 do
68 if grep ELF $pgm > /dev/null;
69 then
70 patchelf --set-interpreter "$interpreter" $pgm;
71 fi
72 done
73 '';
74
75 passthru = {
76 libArch = "x86-64_linux";
77 libSuffix = "${version}0";
78 };
79
80 meta = with lib; {
81 description = "Optimization solver for mathematical programming";
82 homepage = "https://www.ibm.com/be-en/marketplace/ibm-ilog-cplex";
83 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
84 license = licenses.unfree;
85 platforms = [ "x86_64-linux" ];
86 maintainers = with maintainers; [ bfortz ];
87 };
88}