From ac43be430a1b88141d4555fc71a9a621991bf758 Mon Sep 17 00:00:00 2001 From: Tyson Whitehead Date: Fri, 7 Oct 2016 15:38:44 -0400 Subject: [PATCH 1/4] openfoam: Initial packaging --- openfoam.nix | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 openfoam.nix diff --git a/openfoam.nix b/openfoam.nix new file mode 100644 index 0000000..d465a11 --- /dev/null +++ b/openfoam.nix @@ -0,0 +1,77 @@ +with import {}; + +stdenv.mkDerivation rec { + version = "4.0"; + name = "openfoam-${version}"; + + src = fetchurl { + url = "https://github.com/OpenFOAM/OpenFOAM-4.x/archive/version-${version}.tar.gz"; + sha256 = "0mslymq1szprzlp18j92zl30zfz9bj9r4psxa6ys99qw0ff85vx8"; + }; + + # a lot of assumptions about being under a directory named OpenFOAM-${version} + postUnpack = '' + echo "resettting sourceRoot to ''${sourceRoot/-4.x-version/}" + mv "$sourceRoot" "''${sourceRoot/-4.x-version/}" + sourceRoot="''${sourceRoot/-4.x-version/}" + ''; + + # one of the following would bake in the rpath, but sourcing etc/bashrc file updates LD_LIBRARY_PATH + # NIX_LDFLAGS="-rpath $out/platform/$WM_OPTIONS/lib $NIX_LDFLAGS" + # NIX_LDFLAGS="${NIX_LDFLAGS/"$out/lib$WM_ARCH_OPTION"/"$out/platform/$WM_OPTIONS/lib"}" + configurePhase = '' + sed -ie 's|FOAM_INST_DIR=$HOME/$WM_PROJECT.*|FOAM_INST_DIR='"$out"/lib/OpenFOAM-${version}'|' etc/bashrc + sed -ie 's|BOOST_ARCH_PATH=.*$|BOOST_ARCH_PATH=${boost}|' etc/config.sh/CGAL + sed -ie 's|CGAL_ARCH_PATH=.*$|CGAL_ARCH_PATH=${cgal}|' etc/config.sh/CGAL + sed -ie 's|METIS_ARCH_PATH=.*$|METIS_ARCH_PATH=${metis}|' etc/config.sh/metis + sed -ie 's|SCOTCH_ARCH_PATH=.*$|SCOTCH_ARCH_PATH=${scotch}|' etc/config.sh/scotch + source "$PWD/etc/bashrc" + ''; + + buildPhase = '' + export WM_NCOMPPROCS="''${NIX_BUILD_CORES}" + ./Allwmake + ''; + + # stick etc, bin, applications, and platforms under lib/OpenFOAM-${version} + # fill bin proper up with wrappers to everything in platform/$WM_OPTIONS/bin that source etc/bashrc + installPhase = '' + echo "copying etc, bin, applications, and platforms directories to $out/lib/OpenFOAM-${version}" + mkdir -p "$out/lib/OpenFOAM-${version}" + cp -at "$out/lib/OpenFOAM-${version}" etc bin applications platforms + echo "creating a bin of wrapped binaries from $out/lib/OpenFOAM-${version}/platforms/$WM_OPTIONS/bin" + for program in "$out/lib/OpenFOAM-${version}/platforms/$WM_OPTIONS/bin/"*; do + makeWrapper "$program" "$out/bin/''${program##*/}" \ + --run "source \"$out/lib/OpenFOAM-${version}/etc/bashrc\"" + done + ''; + + buildInputs = [ + makeWrapper + flex + bison + zlib + boost + openmpi +# gnuplot + readline +# ncurses + gperftools + cgal + metis + scotch + mpfr +# xorg.libXt +# paraview +# cmake +# qt4 +# freeglut + ]; + + meta = with stdenv.lib; { + homepage = http://www.openfoam.com; + description = "Free open-source CFD software"; + platforms = platforms.linux; + license = licenses.gpl3; + }; +} From 96cd6a502e21529392d73d5fc2cade17278ca8f2 Mon Sep 17 00:00:00 2001 From: Tyson Whitehead Date: Fri, 7 Oct 2016 16:48:29 -0400 Subject: [PATCH 2/4] openfoam: Drop unused buildInputs --- openfoam.nix | 7 ------- 1 file changed, 7 deletions(-) diff --git a/openfoam.nix b/openfoam.nix index d465a11..9eeb2e4 100644 --- a/openfoam.nix +++ b/openfoam.nix @@ -53,19 +53,12 @@ stdenv.mkDerivation rec { zlib boost openmpi -# gnuplot readline -# ncurses gperftools cgal metis scotch mpfr -# xorg.libXt -# paraview -# cmake -# qt4 -# freeglut ]; meta = with stdenv.lib; { From 7a6534cb21a437543cb5cee70165aa575f0ce00a Mon Sep 17 00:00:00 2001 From: Tyson Whitehead Date: Fri, 7 Oct 2016 16:49:01 -0400 Subject: [PATCH 3/4] openfoam: Don't package applications directory (it's source) --- openfoam.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openfoam.nix b/openfoam.nix index 9eeb2e4..f54b763 100644 --- a/openfoam.nix +++ b/openfoam.nix @@ -33,12 +33,12 @@ stdenv.mkDerivation rec { ./Allwmake ''; - # stick etc, bin, applications, and platforms under lib/OpenFOAM-${version} + # stick etc, bin, and platforms under lib/OpenFOAM-${version} # fill bin proper up with wrappers to everything in platform/$WM_OPTIONS/bin that source etc/bashrc installPhase = '' - echo "copying etc, bin, applications, and platforms directories to $out/lib/OpenFOAM-${version}" + echo "copying etc, bin, and platforms directories to $out/lib/OpenFOAM-${version}" mkdir -p "$out/lib/OpenFOAM-${version}" - cp -at "$out/lib/OpenFOAM-${version}" etc bin applications platforms + cp -at "$out/lib/OpenFOAM-${version}" etc bin platforms echo "creating a bin of wrapped binaries from $out/lib/OpenFOAM-${version}/platforms/$WM_OPTIONS/bin" for program in "$out/lib/OpenFOAM-${version}/platforms/$WM_OPTIONS/bin/"*; do makeWrapper "$program" "$out/bin/''${program##*/}" \ From a90c9e5ee3706c3c6c81abe80a70e0a6956e8eef Mon Sep 17 00:00:00 2001 From: Tyson Whitehead Date: Thu, 27 Oct 2016 10:57:04 -0400 Subject: [PATCH 4/4] openfoam: Add *-mpi wrappers for all bins that use libPstream.so * Ensure correct mpirun is used and right number of processes --- openfoam.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/openfoam.nix b/openfoam.nix index f54b763..9104495 100644 --- a/openfoam.nix +++ b/openfoam.nix @@ -34,7 +34,8 @@ stdenv.mkDerivation rec { ''; # stick etc, bin, and platforms under lib/OpenFOAM-${version} - # fill bin proper up with wrappers to everything in platform/$WM_OPTIONS/bin that source etc/bashrc + # fill bin proper up with wrappers that source etc/bashrc for everything in platform/$WM_OPTIONS/bin + # add -mpi suffixed versions that calls proper mpirun for those with libPstream.so depencies too installPhase = '' echo "copying etc, bin, and platforms directories to $out/lib/OpenFOAM-${version}" mkdir -p "$out/lib/OpenFOAM-${version}" @@ -43,6 +44,12 @@ stdenv.mkDerivation rec { for program in "$out/lib/OpenFOAM-${version}/platforms/$WM_OPTIONS/bin/"*; do makeWrapper "$program" "$out/bin/''${program##*/}" \ --run "source \"$out/lib/OpenFOAM-${version}/etc/bashrc\"" + if readelf -d "$program" | fgrep -q libPstream.so; then + makeWrapper "${openmpi}/bin/mpirun" "$out/bin/''${program##*/}-mpi" \ + --run "[ -r processor0 ] || { echo \"Case is not currently decomposed, see decomposePar documentation\"; exit 1; }" \ + --run "extraFlagsArray+=(-n \"\$(ls -d processor* | wc -l)\" \"$out/bin/''${program##*/}\" -parallel)" \ + --run "source \"$out/lib/OpenFOAM-${version}/etc/bashrc\"" + fi done '';