1{
2 lib,
3 stdenv,
4 autoPatchelfHook,
5 makeDesktopItem,
6 copyDesktopItems,
7 makeWrapper,
8 alsa-lib,
9 glib,
10 glib-networking,
11 gsettings-desktop-schemas,
12 gtk3,
13 libsecret,
14 openjdk,
15 sqlite,
16 unixODBC,
17 gtk2,
18 xorg,
19 glibcLocales,
20 releasePath ? null,
21}:
22
23# To use this package, you need to download your own cplex installer from IBM
24# and override the releasePath attribute to point to the location of the file.
25#
26# Note: cplex creates an individual build for each license which screws
27# somewhat with the use of functions like requireFile as the hash will be
28# different for every user.
29
30stdenv.mkDerivation rec {
31 pname = "cplex";
32 version = "22.11";
33
34 src =
35 if releasePath == null then
36 throw ''
37 This nix expression requires that the cplex installer is already
38 downloaded to your machine. Get it from IBM:
39 https://www.ibm.com/support/pages/downloading-ibm-ilog-cplex-optimization-studio-2211
40
41 Set `cplex.releasePath = /path/to/download;` in your
42 ~/.config/nixpkgs/config.nix for `nix-*` commands, or
43 `config.cplex.releasePath = /path/to/download;` in your
44 `configuration.nix` for NixOS.
45 ''
46 else
47 releasePath;
48
49 nativeBuildInputs = [
50 autoPatchelfHook
51 copyDesktopItems
52 makeWrapper
53 openjdk
54 ];
55 buildInputs = [
56 alsa-lib
57 gsettings-desktop-schemas
58 gtk2
59 sqlite
60 unixODBC
61 xorg.libXtst
62 glibcLocales
63 ];
64
65 unpackPhase = "cp $src $name";
66
67 postPatch = ''
68 sed -i -e 's|/usr/bin/tr"|tr" |' $name
69 '';
70
71 buildPhase = ''
72 runHook preBuild
73
74 export JAVA_TOOL_OPTIONS=-Djdk.util.zip.disableZip64ExtraFieldValidation=true
75 sh $name LAX_VM "$(command -v java)" -i silent -DLICENSE_ACCEPTED=TRUE -DUSER_INSTALL_DIR=$out
76
77 runHook postBuild
78 '';
79
80 installPhase =
81 let
82 libraryPath = lib.makeLibraryPath [
83 stdenv.cc.cc
84 glib
85 gtk2
86 gtk3
87 libsecret
88 xorg.libXtst
89 ];
90 in
91 ''
92 runHook preInstall
93
94 mkdir -p $out/bin
95
96 for pgm in \
97 $out/opl/bin/x86-64_linux/oplrun \
98 $out/opl/bin/x86-64_linux/oplrunjava \
99 $out/opl/oplide/oplide \
100 $out/cplex/bin/x86-64_linux/cplex \
101 $out/cpoptimizer/bin/x86-64_linux/cpoptimizer
102 do
103 makeWrapperArgs=(
104 --set-default LOCALE_ARCHIVE ${glibcLocales}/lib/locale/locale-archive
105 )
106
107 if [[ "$pgm" = "$out/opl/oplide/oplide" ]]; then
108 makeWrapperArgs+=(
109 --prefix LD_LIBRARY_PATH : ${libraryPath}
110 --prefix GIO_EXTRA_MODULES : "${glib-networking}/lib/gio/modules"
111 --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH"
112 )
113 fi
114
115 makeWrapper "$pgm" "$out/bin/$(basename "$pgm")" "''${makeWrapperArgs[@]}"
116 done
117
118 mkdir -p $out/share/pixmaps
119 ln -s $out/opl/oplide/icon.xpm $out/share/pixmaps/oplide.xpm
120
121 mkdir -p $out/share/doc
122 mv $out/doc $out/share/doc/$name
123
124 mkdir -p $out/share/licenses
125 mv $out/license $out/share/licenses/$name
126
127 runHook postInstall
128 '';
129
130 desktopItems = [
131 (makeDesktopItem {
132 name = "oplide";
133 desktopName = "IBM ILOG CPLEX Optimization Studio";
134 genericName = "Optimization Software";
135 icon = "oplide";
136 exec = "oplide";
137 categories = [
138 "Development"
139 "IDE"
140 "Math"
141 "Science"
142 ];
143 })
144 ];
145
146 fixupPhase = ''
147 runHook preFixup
148
149 rm -r $out/Uninstall
150
151 bins=(
152 $out/bin/*
153 $out/cplex/bin/x86-64_linux/cplex
154 $out/cplex/bin/x86-64_linux/cplexamp
155 $out/cpoptimizer/bin/x86-64_linux/cpoptimizer
156 $out/opl/bin/x86-64_linux/oplrun
157 $out/opl/bin/x86-64_linux/oplrunjava
158 $out/opl/oplide/jre/bin/*
159 $out/opl/oplide/oplide
160 )
161
162 find $out -type d -exec chmod 755 {} \;
163 find $out -type f -exec chmod 644 {} \;
164 chmod +111 "''${bins[@]}"
165
166 runHook postFixup
167 '';
168
169 passthru = {
170 libArch = "x86-64_linux";
171 libSuffix = "${version}0";
172 };
173
174 meta = with lib; {
175 description = "Optimization solver for mathematical programming";
176 homepage = "https://www.ibm.com/be-en/marketplace/ibm-ilog-cplex";
177 mainProgram = "cplex";
178 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
179 license = licenses.unfree;
180 platforms = [ "x86_64-linux" ];
181 maintainers = with maintainers; [ bfortz ];
182 };
183}