This is a Nix flake template for setting up an IBM ILOG CPLEX Optimization Studio environment.
I had the need to create this because the nixpkgs cplex installer was failing during installPhase
with this error:
Running phase: installPhase
mv: cannot stat '/nix/store/rwnwq5m6fhc0vsyrzg9p890i40hbsjyr-cplex-22.12/doc': No such file or directory
> Running phase: installPhase
> mv: cannot stat '/nix/store/rwnwq5m6fhc0vsyrzg9p890i40hbsjyr-cplex-22.12/doc': No such file or directory
For full logs, run 'nix log /nix/store/333yavk6iq6442jwaci1bhwsrdny8x79-cplex-22.12.drv'.
Which seems to occur if doc
or license
directories are not found in the installation path. This issue has been addressed by conditionally checking their existance here as following:
if [ -d "$out/doc" ]; then
mkdir -p $out/share/doc
mv $out/doc $out/share/doc/$name
else
echo "No doc directory found, skipping doc installation"
fi
if [ -d "$out/license" ]; then
mkdir -p $out/share/licenses
mv $out/license $out/share/licenses/$name
else
echo "No license directory found, skipping license installation"
fi
Furthermore this also allows upgrading to cplex latest version (22.12).
- Nix with flakes enabled
- An IBM CPLEX installer (you need to download this yourself from IBM)
-
Initialize a new project from this template:
nix flake init -t github:elenaferr0/cplex-nix
-
Download your CPLEX installer from IBM: https://www.ibm.com/support/pages/downloading-ibm-ilog-cplex-optimization-studio-2212
-
Update the
flake.nix
file to point to your CPLEX installer:cplex = pkgs.callPackage ./cplex.nix { releasePath = ./path/to/your/cplex.bin; };
-
Update the
devShell
section to include the cplex package:buildInputs = [ cplex pkgs.curl pkgs.python3 # Other packages... ];
-
Enter the development environment:
nix develop -c $SHELL
In case you did not enable unfree packages you will need to run the following command instead:
NIXPKGS_ALLOW_UNFREE=1 nix develop --impure -c $SHELL
When properly configured, the environment sets up:
CPLEX_STUDIO_DIR
: Points to the CPLEX installationCPLEX_BIN_DIR
: Points to the CPLEX binary directoryLD_LIBRARY_PATH
: Includes the CPLEX library path
The CPLEX software requires a valid license from IBM. This template only helps with the Nix environment setup.