diff --git a/pkgs/by-name/ne/netgen/package.nix b/pkgs/by-name/ne/netgen/package.nix index d034a54c7fdb..a58e521737db 100644 --- a/pkgs/by-name/ne/netgen/package.nix +++ b/pkgs/by-name/ne/netgen/package.nix @@ -3,7 +3,10 @@ stdenv, fetchFromGitHub, fetchpatch2, - makeWrapper, + libicns, + imagemagick, + makeDesktopItem, + copyDesktopItems, cmake, python3Packages, mpi, @@ -66,28 +69,38 @@ stdenv.mkDerivation (finalAttrs: { url = "${patchSource}/include_stdlib.patch"; hash = "sha256-W+NgGBuy/UmzVbPTSqR8FRUlyN/9dl9l9e9rxKklmIc="; }) - (fetchpatch2 { - url = "${patchSource}/fix-version.patch"; - hash = "sha256-CT98Wq3UufB81z/jYLiH9nXvt+QzoZ7210OeuFXCfmc="; - }) ]; # when generating python stub file utilizing system python pybind11_stubgen module # cmake need to inherit pythonpath - postPatch = '' - substituteInPlace python/CMakeLists.txt \ - --replace-fail ''\'''${CMAKE_INSTALL_PREFIX}/''${NG_INSTALL_DIR_PYTHON}' \ - ''\'''${CMAKE_INSTALL_PREFIX}/''${NG_INSTALL_DIR_PYTHON}:$ENV{PYTHONPATH}' + postPatch = + '' + sed -i '/-DBDIR=''\'''${CMAKE_CURRENT_BINARY_DIR}/a\ + -DNETGEN_VERSION_GIT=''\'''${NETGEN_VERSION_GIT} + ' CMakeLists.txt - substituteInPlace ng/ng.tcl ng/onetcl.cpp \ - --replace-fail "libnggui" "$out/lib/libnggui" - ''; + substituteInPlace python/CMakeLists.txt \ + --replace-fail ''\'''${CMAKE_INSTALL_PREFIX}/''${NG_INSTALL_DIR_PYTHON}' \ + ''\'''${CMAKE_INSTALL_PREFIX}/''${NG_INSTALL_DIR_PYTHON}:$ENV{PYTHONPATH}' + + substituteInPlace ng/ng.tcl ng/onetcl.cpp \ + --replace-fail "libnggui" "$out/lib/libnggui" + + substituteInPlace ng/Togl2.1/CMakeLists.txt \ + --replace-fail "/usr/bin/gcc" "$CC" + '' + + lib.optionalString (!stdenv.hostPlatform.isx86_64) '' + # mesh generation differs on x86_64 and aarch64 platform + # test_tutorials will fail on aarch64 platform + rm tests/pytest/test_tutorials.py + ''; nativeBuildInputs = [ + libicns + imagemagick cmake - makeWrapper python3Packages.pybind11-stubgen - ]; + ] ++ lib.optional stdenv.hostPlatform.isLinux copyDesktopItems; buildInputs = [ metis @@ -111,6 +124,12 @@ stdenv.mkDerivation (finalAttrs: { cmakeFlags = [ (lib.cmakeFeature "NETGEN_VERSION_GIT" "v${finalAttrs.version}-0") + (lib.cmakeFeature "NG_INSTALL_DIR_BIN" "bin") + (lib.cmakeFeature "NG_INSTALL_DIR_LIB" "lib") + (lib.cmakeFeature "NG_INSTALL_DIR_CMAKE" "lib/cmake/${finalAttrs.pname}") + (lib.cmakeFeature "NG_INSTALL_DIR_PYTHON" python3Packages.python.sitePackages) + (lib.cmakeFeature "NG_INSTALL_DIR_RES" "share") + (lib.cmakeFeature "NG_INSTALL_DIR_INCLUDE" "include") (lib.cmakeFeature "CMAKE_CXX_FLAGS" archFlags) (lib.cmakeBool "USE_MPI" true) (lib.cmakeBool "USE_MPI4PY" true) @@ -124,9 +143,45 @@ stdenv.mkDerivation (finalAttrs: { (lib.cmakeBool "ENABLE_UNIT_TESTS" finalAttrs.finalPackage.doInstallCheck) ]; - # mesh generation differs on x86_64 and aarch64 platform - # tests will fail on aarch64 platform - doInstallCheck = stdenv.hostPlatform.isx86_64; + __darwinAllowLocalNetworking = true; + + desktopItems = [ + (makeDesktopItem { + name = "netgen"; + exec = "netgen"; + comment = finalAttrs.meta.description; + desktopName = "Netgen Mesh Generator"; + genericName = "3D Mesh Generator"; + categories = [ "Science" ]; + icon = "netgen"; + }) + ]; + + postInstall = + lib.optionalString stdenv.hostPlatform.isDarwin '' + rm $out/bin/{Netgen1,startup.sh} + mkdir -p $out/Applications/${finalAttrs.pname}.app/Contents/{MacOS,Resouces} + substituteInPlace $out/Info.plist --replace-fail "Netgen1" "netgen" + mv $out/Info.plist $out/Applications/${finalAttrs.pname}.app/Contents + mv $out/Netgen.icns $out/Applications/${finalAttrs.pname}.app/Contents/Resouces + ln -s $out/bin/netgen $out/Applications/${finalAttrs.pname}.app/Contents/MacOS/netgen + '' + + lib.optionalString stdenv.hostPlatform.isLinux '' + # Extract pngs from the Apple icon image and create + # the missing ones from the 512x512 image. + icns2png --extract ../netgen.icns + for size in 16 24 32 48 64 128 256 512; do + mkdir -pv $out/share/icons/hicolor/"$size"x"$size"/apps + if [ -e netgen_"$size"x"$size"x32.png ] + then + mv netgen_"$size"x"$size"x32.png $out/share/icons/hicolor/"$size"x"$size"/apps/netgen.png + else + convert -resize "$size"x"$size" netgen_512x512x32.png $out/share/icons/hicolor/"$size"x"$size"/apps/netgen.png + fi + done; + ''; + + doInstallCheck = true; preInstallCheck = '' export PYTHONPATH=$out/${python3Packages.python.sitePackages}:$PYTHONPATH @@ -139,15 +194,19 @@ stdenv.mkDerivation (finalAttrs: { python3Packages.pytest python3Packages.pytest-check python3Packages.pytest-mpi + python3Packages.pythonImportsCheckHook mpiCheckPhaseHook ]; + pythonImportsCheck = [ "netgen" ]; + passthru = { inherit avxSupport avx2Support avx512Support; }; meta = { homepage = "https://ngsolve.org"; + downloadPage = "https://github.com/NGSolve/netgen"; description = "Atomatic 3d tetrahedral mesh generator"; license = with lib.licenses; [ lgpl2Plus @@ -157,10 +216,7 @@ stdenv.mkDerivation (finalAttrs: { boost publicDomain ]; - platforms = [ - "x86_64-linux" - "aarch64-linux" - ]; + platforms = lib.platforms.unix; mainProgram = "netgen"; maintainers = with lib.maintainers; [ qbisi ]; };