Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cplex: init at 12.8 #44029

Merged
merged 8 commits into from Aug 16, 2018
Merged

cplex: init at 12.8 #44029

merged 8 commits into from Aug 16, 2018

Conversation

bfortz
Copy link
Contributor

@bfortz bfortz commented Jul 23, 2018

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

nativeBuildInputs = [ coreutils makeWrapper ];
buildInputs = [ openjdk gtk2 xorg.libXtst glibcLocales ];

phases = "installPhase";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't assign phases directly, instead assign the parts of the script the role they have: The first sed is patchPhase, the sh buildPhase, put the ln's in installPhase and the patchelf/wrapProgram in fixupPhase.

for pgm in $out/opl/bin/x86-64_linux/oplrun $out/opl/bin/x86-64_linux/oplrunjava $out/opl/oplide/oplide;
do
patchelf --set-interpreter "$interpreter" $pgm;
wrapProgram $pgm --prefix LD_LIBRARY_PATH : $out/opl/bin/x86-64_linux:${stdenv.lib.makeLibraryPath [ stdenv.cc.cc gtk2 xorg.libXtst ]} --set LOCALE_ARCHIVE ${glibcLocales}/lib/locale/locale-archive;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use \ to break lines and put a libraryPath = stdenv.lib.makeLibraryPath [ ... ]; definition in a let in to keep the line length short:

fixupPhase = let libraryPath = ...
  in ''
    ...
    wrapProgram $pgm \
      --prefix LD_LIBRARY_PATH : $out/opl/bin/x86-64_linux:${libraryPath} \
      --set LOCALE_ARCHIVE ${glibcLocales}/lib/locale/locale-archive;

do
if grep ELF $pgm > /dev/null;
then
patchelf --set-interpreter "$interpreter" $pgm;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure patchelf already checks whether it's an ELF binary or not. You could also then merge the patchelf loops.

installer = "cplex_studio${version}.linux-x86-64.bin";

src = requireFile rec {
name = "${installer}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just assign name = "cplex_studio${version}.linux-x86-64.bin"; directly here. And there's no need to use the $installer variable down below I'd think

@bfortz
Copy link
Contributor Author

bfortz commented Aug 3, 2018

@infinisil thanks for the suggestions, indeed the code is much better now. I also changed the source definition, copying from what is done in the renoise build, because the dowloaded archive is likely to be personalized and sha256 check would fail. Note that patchelf fails on non-ELF files.

nativeBuildInputs = [ coreutils makeWrapper ];
buildInputs = [ openjdk gtk2 xorg.libXtst glibcLocales ];

phases = "patchPhase buildPhase installPhase fixupPhase";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to remove this line completely, these phases are set like this automatically

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I disable unpackPhase? I tried to define an empty one, but it did not work (and it complains it does not know how to unpack the cplex bin archive if I do not remove the phase completely).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe unpackPhase = "cp $src ." will work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cp $src $name

else
releasePath;

nativeBuildInputs = [ coreutils makeWrapper ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure coreutils are present by default, no need to add them here

throw ''
This nix expression requires that the cplex installer is already
downloaded to your machine. Get it from IBM and override the
releasePath attribute to point to the location of the file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the link to where one can download it in this error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

phases = "patchPhase buildPhase installPhase fixupPhase";

patchPhase = ''
sed -e 's|/usr/bin/tr"|tr" |' $src > $name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use sed -i to modify the file inplace, no need to > $name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But $src is the original file, I don't want to modify that one. (The other option would be to first copy the file in the unpack phase...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the cp in the unpackPhase, sed -i does the job. (BTW, I did not use the builtin substituteInPlace because it is way too slow on such a large file).

for pgm in $out/opl/bin/x86-64_linux/oplrun $out/opl/bin/x86-64_linux/oplrunjava $out/opl/oplide/oplide $out/cplex/bin/x86-64_linux/cplex $out/cpoptimizer/bin/x86-64_linux/cpoptimizer;
do
ln -s $pgm $out/bin;
done
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make this a single command and use some newlines:

ln -s $out/opl/bin/x86-64_linux/oplrun \
  $out/opl/bin/x86-64_linux/oplrunjava \
  ... \
  $out/bin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,75 @@
{ stdenv, coreutils, requireFile, patchelf, makeWrapper, openjdk, gtk2, xorg, glibcLocales, releasePath ? null }:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove patchelf, coreutils and requireFile from here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long review process, I hope you don't mind! I asked around, and apparently some people are against including derivations that need such special ways of fetching sources: #13625. I think it's alright for this one though :)

@@ -0,0 +1,81 @@
{ stdenv, makeWrapper, openjdk, gtk2, xorg, glibcLocales, releasePath ? null }:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternate suggestion I think I'd prefer: Use the config attribute here instead, and use config.cplex.releasePath to get the path. Then users using nix-env will have it easy to make it work, it just needs a { cplex.releasePath = ...; } in their ~/.config/nixpkgs/config.nix. This could then also be documented in the error message: "Set cplex.releasePath = /path/to/download; in your ~/.config/nixpkgs/config.nix for nix-* commands, or config.cplex.releasePath = /path/to/download; in your configuration.nix for NixOS ..."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to apologize, I appreciate the feedback as I am quite a newbie here, and is good to have some mentoring. I like the config idea, it should also be ported to renoise to imho (I inspired myself from the renoise build for this one).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it is. I hope I did it the right way...

@infinisil
Copy link
Member

Thanks! The only thing left to do is squash all commits into one

@matthewbauer matthewbauer merged commit 22c15ab into NixOS:master Aug 16, 2018
@bfortz bfortz deleted the cplex branch August 16, 2018 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants