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

gams: init at 25.02 #39603

Merged
merged 1 commit into from May 23, 2018
Merged

gams: init at 25.02 #39603

merged 1 commit into from May 23, 2018

Conversation

Scriptkiddi
Copy link
Contributor

@Scriptkiddi Scriptkiddi commented Apr 27, 2018

Motivation for this change

I need to use gams for my work so I thought I would package it.
Since this is my first nix package I really would appreciate feedback.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-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/)
  • Fits CONTRIBUTING.md.

@@ -637,6 +637,11 @@ with pkgs;

genymotion = callPackage ../development/mobile/genymotion { };

gams = callPackage ../tools/misc/gams {
license = config.gams.license;
Copy link
Member

Choose a reason for hiding this comment

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

why is the license configurable? where does config.gams come from?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, its the license file for running the software. You should add a module (take a look at nixos/modules/programs) to document the option.

Copy link
Member

Choose a reason for hiding this comment

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

This config option is also ok. It can be overwritten in ~/.nixpkgs/config.nix and also work on non-nixos systems.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still doesn't eval if the two config options aren't set (like on ofborg). You need to define safe defaults for both of them, as in license = config.gams.license or "someSensibleDefaultValue";. Please verify that the package builds with these default values, in this case it should result in an unlicensed demo version using default options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for noticing, I added a option that if the variable should be undefined that its set to null
I was wondering where I should check if the var is defined right now im doing it in all-packages.nix since the chromium.nix is doing the same, but is that the right way to do it?

'';
homepage = https://www.gams.com/;
license = stdenv.lib.licenses.unfree;
maintainers = [ "Scriptkiddi" ];
Copy link
Member

Choose a reason for hiding this comment

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

you should add yourself to maintainers/maintainer.list and reference the attribute here (look at other packages as an example)

'';
homepage = https://www.gams.com/;
license = stdenv.lib.licenses.unfree;
maintainers = [ maintainers.scriptkiddi ];
Copy link
Contributor

Choose a reason for hiding this comment

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

Eval fails, this should read [ stdenv.lib.maintainers.scriptkiddi ] to work.

An even nicer way to fix it if you write meta = with stdenv.lib; { above, then you don't need to repeat that prefix for license, maintainers and platforms.

'';
homepage = https://www.gams.com/;
license = licenses.unfree;
maintainers = [ maintainers.scriptkiddi ];
Copy link
Member

Choose a reason for hiding this comment

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

In the file above, you have a capitalized S.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for noticing I fixed it

(concatMapStringsSep "\n" (prog: "ln -s $out/${prog} $out/bin/${prog}") binaries)
];

postFixup = with lib; concatMapStringsSep "\n" (prog: "patchelf --set-interpreter \"$(cat $NIX_CC/nix-support/dynamic-linker)\" $out/${prog}") binaries;
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 check if adding autoPatchelfHook makes this code unnecessarily. example: ea5787a

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the autoPatchelfHook does not work, but i dont know why

Copy link
Member

@Mic92 Mic92 May 1, 2018

Choose a reason for hiding this comment

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

The reason is that it still misses libraries: gdxWhos.mexa64 needs more libraries:

libmx.so -> not found!
libmex.so -> not found!
libmat.so -> not found!

These are apparently included in the matlab compiler runtime: https://stackoverflow.com/questions/15922862/where-to-get-matlab-libraries-libmat-and-libmx

Copy link
Member

Choose a reason for hiding this comment

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

I also had to add bzip2 for libbz2 somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I looked into it, gams ships all dependencies with the binary file, so if its ok I would not run autoPatchelfHook, because with that I would need to get the matlab libs from somewhere and that kind of out of scope. I would change it as soon as a matlab package for nixos is available if thats ok?

@Mic92
Copy link
Member

Mic92 commented May 5, 2018

I made some changes to make it easier to maintain.

diff --git a/pkgs/tools/misc/gams/default.nix b/pkgs/tools/misc/gams/default.nix
index 0ef1df89113..613fdc0f455 100644
--- a/pkgs/tools/misc/gams/default.nix
+++ b/pkgs/tools/misc/gams/default.nix
@@ -1,4 +1,6 @@
-{ stdenv, fetchurl, unzip, lib, file, license, optgams}:
+{ stdenv, fetchurl, unzip, lib, file, licenseFile, optgamsFile}:
+
+assert licenseFile != null;
 
 stdenv.mkDerivation rec {
   version = "25.0.2";
@@ -10,22 +12,28 @@ stdenv.mkDerivation rec {
   unpackCmd = "unzip $src";
   buildInputs = [ unzip file ];
   dontBuild = true;
-  binaries = [ "decisc" "gmsbncux.out" "eigenvalue" "mcfilter" "gmsptnux.out" "csv2gdx" "gdx2veda" "endecrypt" "eigenvector" "gmsderux.out" "gmsba_ux.out" "gmsdi_ux.out" "gmssb_ux.out" "sqlite3" "gamskeep" "gmsck_ux.out" "gmsgewux.out" "finlib" "apilib" "noalib" "gmsls_ux.out" "gmsdetux.out" "gmsxa_ux.out" "gmscr_ux.out" "gmsunzip" "scenred2" "mps2gms" "gdxrename" "gmscvpux.out" "gmsckbux.out" "bib2gms" "gmsbaxux.out" "gmszip" "gmscvlux.out" "decism" "gmsecpux.out" "gmsbd_ux.out" "gdxdiff" "gamscmex.out" "gamsinst" "invert" "gmscv_ux.out" "chk4upd" "gdxmerge" "gmscvnux.out" "gmsmd_ux.out" "cholesky" "gmsunpack" "gdxdump" "gmsge_ux.out" "gamslib" "gdxcopy" "gmsgenux.out" "gmsex_ux.out" "gdx2sqlite" "hexdump" "gmsja_ux.out" "datalib" "gmscvaux.out" "testlib" "gdxrank" "gmsdesux.out" "gmsmceux.out" "scenred" "gdxtroll" "csdp" "gmsmn_ux.out" "emplib" "gams" ];
-  installPhase = with lib;
-      concatStrings [''
-        mkdir -p "$out/bin"
-        cp -a * "$out/"
-        ${if license != null then "cp ${license} \"$out/gamslice.txt\"" else ""}
-        ${if optgams != null then "cp ${optgams} \"$out/optgams.def\"" else ""}
-        ln -s $out/optgams.def $out/bin/optgams.def
-        ln -s $out/libjoatdclib64.so $out/bin/libjoatdclib64.so
-        ln -s $out/libgmdcclib64.so $out/bin/libgmdcclib64.so
-        ln -s $out/libgdxdclib64.so $out/bin/libgdxdclib64.so
-        ''
-        (concatMapStringsSep "\n" (prog: "ln -s $out/${prog} $out/bin/${prog}") binaries)
-      ];
 
-  postFixup = with lib; concatMapStringsSep "\n" (prog: "patchelf --set-interpreter \"$(cat $NIX_CC/nix-support/dynamic-linker)\" $out/${prog}") binaries;
+  installPhase = ''
+    mkdir -p "$out/bin" "$out/share/gams"
+    cp -a * "$out/share/gams"
+
+    cp ${licenseFile} $out/share/gamslice.txt
+  '' + stdenv.lib.optionalString (optgamsFile != null) ''
+    cp ${optgamsFile} $out/share/optgams.def
+    ln -s $out/share/gams/optgams.def $out/bin/optgams.def
+  '';
+
+  postFixup = ''
+    for f in $out/share/gams/*; do
+      if [[ -x $f ]] && [[ -f $f ]] && [[ ! $f =~ .*\.so$ ]]; then
+        if patchelf \
+          --set-rpath "$out/share/gams" \
+          --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) $f; then
+          ln -s $f $out/bin/$(basename $f)
+        fi
+      fi
+    done
+  '';
 
   meta = with stdenv.lib;{
     description = "General Algebraic Modeling System";
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index f085c40a0e9..2a9835211c8 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -638,8 +638,8 @@ with pkgs;
   genymotion = callPackage ../development/mobile/genymotion { };
 
   gams = callPackage ../tools/misc/gams {
-    license = config.gams.license or null;
-    optgams = config.gams.optgams or null;
+    licenseFile = config.gams.licenseFile or null;
+    optgamsFile = config.gams.optgamsFile or null;
   };
 
   git-fire = callPackage ../tools/misc/git-fire { };

concatStrings [''
mkdir -p "$out/bin"
cp -a * "$out/"
${if license != null then "cp ${license} \"$out/gamslice.txt\"" else ""}
Copy link
Member

Choose a reason for hiding this comment

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

This is not really optional is it? I added an assertion to ensure the user sets it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its kind of optional you can see if your gams file is valid but not solve it

cp -a * "$out/"
${if license != null then "cp ${license} \"$out/gamslice.txt\"" else ""}
${if optgams != null then "cp ${optgams} \"$out/optgams.def\"" else ""}
ln -s $out/optgams.def $out/bin/optgams.def
Copy link
Member

Choose a reason for hiding this comment

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

This lines only make sense if optgams is set. I put both in an optional block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks

ln -s $out/optgams.def $out/bin/optgams.def
ln -s $out/libjoatdclib64.so $out/bin/libjoatdclib64.so
ln -s $out/libgmdcclib64.so $out/bin/libgmdcclib64.so
ln -s $out/libgdxdclib64.so $out/bin/libgdxdclib64.so
Copy link
Member

Choose a reason for hiding this comment

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

I expanded the rpath to include this. I did not saw any missing libraries. How can I test this works?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

try running the gams binary, but I can try running it

installPhase = with lib;
concatStrings [''
mkdir -p "$out/bin"
cp -a * "$out/"
Copy link
Member

Choose a reason for hiding this comment

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

Doing this can clutter the user profile with random files from this package. Instead I put everything into share/gams.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice I will continue doing that for future packages

unpackCmd = "unzip $src";
buildInputs = [ unzip file ];
dontBuild = true;
binaries = [ "decisc" "gmsbncux.out" "eigenvalue" "mcfilter" "gmsptnux.out" "csv2gdx" "gdx2veda" "endecrypt" "eigenvector" "gmsderux.out" "gmsba_ux.out" "gmsdi_ux.out" "gmssb_ux.out" "sqlite3" "gamskeep" "gmsck_ux.out" "gmsgewux.out" "finlib" "apilib" "noalib" "gmsls_ux.out" "gmsdetux.out" "gmsxa_ux.out" "gmscr_ux.out" "gmsunzip" "scenred2" "mps2gms" "gdxrename" "gmscvpux.out" "gmsckbux.out" "bib2gms" "gmsbaxux.out" "gmszip" "gmscvlux.out" "decism" "gmsecpux.out" "gmsbd_ux.out" "gdxdiff" "gamscmex.out" "gamsinst" "invert" "gmscv_ux.out" "chk4upd" "gdxmerge" "gmscvnux.out" "gmsmd_ux.out" "cholesky" "gmsunpack" "gdxdump" "gmsge_ux.out" "gamslib" "gdxcopy" "gmsgenux.out" "gmsex_ux.out" "gdx2sqlite" "hexdump" "gmsja_ux.out" "datalib" "gmscvaux.out" "testlib" "gdxrank" "gmsdesux.out" "gmsmceux.out" "scenred" "gdxtroll" "csdp" "gmsmn_ux.out" "emplib" "gams" ];
Copy link
Member

Choose a reason for hiding this comment

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

This list is hard to update. I made this a for loop instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thansk

@@ -637,6 +637,11 @@ with pkgs;

genymotion = callPackage ../development/mobile/genymotion { };

gams = callPackage ../tools/misc/gams {
license = config.gams.license or null;
optgams = config.gams.optgams or null;
Copy link
Member

Choose a reason for hiding this comment

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

I added a File suffix here for both, since it is not obvious what type is expected 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.

awesome

@Scriptkiddi
Copy link
Contributor Author

What else is there to do?

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

6 participants