Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 223 lines 6.6 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 fetchpatch2, 6 libicns, 7 imagemagick, 8 makeDesktopItem, 9 copyDesktopItems, 10 cmake, 11 python3Packages, 12 mpi, 13 mpiCheckPhaseHook, 14 metis, 15 opencascade-occt, 16 libGLU, 17 zlib, 18 tcl, 19 tk, 20 xorg, 21 libjpeg, 22 ffmpeg, 23 catch2, 24 avxSupport ? stdenv.hostPlatform.avxSupport, 25 avx2Support ? stdenv.hostPlatform.avx2Support, 26 avx512Support ? stdenv.hostPlatform.avx512Support, 27}: 28let 29 archFlags = toString ( 30 lib.optional avxSupport "-mavx" 31 ++ lib.optional avx2Support "-mavx2" 32 ++ lib.optional avx512Support "-mavx512" 33 ); 34 patchSource = "https://salsa.debian.org/science-team/netgen/-/raw/debian/6.2.2404+dfsg1-5/debian/patches"; 35in 36stdenv.mkDerivation (finalAttrs: { 37 pname = "netgen"; 38 version = "6.2.2504"; 39 40 src = fetchFromGitHub { 41 owner = "ngsolve"; 42 repo = "netgen"; 43 tag = "v${finalAttrs.version}"; 44 hash = "sha256-N4mmh2H2qvc+3Pa9CHm38arViI76Qvwp8fOVGZbMv1M="; 45 }; 46 47 patches = [ 48 # disable some platform specified code used by downstream ngsolve 49 # can be enabled with -march=armv8.3-a+simd when compiling ngsolve 50 # note compiling netgen itself is not influenced by this feature 51 (fetchpatch2 { 52 url = "https://github.com/NGSolve/netgen/pull/197/commits/1d93dfba00f224787cfc2cde1af2ab5d7f5b87f7.patch"; 53 hash = "sha256-3Nom4uGhGLtSGn/k+qKKSxVxrGtGTHqPtcNn3D/gkZU"; 54 }) 55 56 (fetchpatch2 { 57 url = "${patchSource}/use-local-catch2.patch"; 58 hash = "sha256-h4ob8tl6mvGt5B0qXRFNcl9MxPXxRhYw+PrGr5iRGGk="; 59 }) 60 (fetchpatch2 { 61 url = "${patchSource}/ffmpeg_link_libraries.patch"; 62 hash = "sha256-S02OPH9hbJjOnBm6JMh6uM5XptcubV24vdyEF0FusoM="; 63 }) 64 (fetchpatch2 { 65 url = "${patchSource}/fix_nggui_tcl.patch"; 66 hash = "sha256-ODDT67+RWBzPhhq/equWsu78x9L/Yrs3U8VQ1Uu0zZw="; 67 }) 68 (fetchpatch2 { 69 url = "${patchSource}/include_stdlib.patch"; 70 hash = "sha256-W+NgGBuy/UmzVbPTSqR8FRUlyN/9dl9l9e9rxKklmIc="; 71 }) 72 ]; 73 74 # when generating python stub file utilizing system python pybind11_stubgen module 75 # cmake need to inherit pythonpath 76 postPatch = '' 77 sed -i '/-DBDIR=''\'''${CMAKE_CURRENT_BINARY_DIR}/a\ 78 -DNETGEN_VERSION_GIT=''\'''${NETGEN_VERSION_GIT} 79 ' CMakeLists.txt 80 81 substituteInPlace python/CMakeLists.txt \ 82 --replace-fail ''\'''${CMAKE_INSTALL_PREFIX}/''${NG_INSTALL_DIR_PYTHON}' \ 83 ''\'''${CMAKE_INSTALL_PREFIX}/''${NG_INSTALL_DIR_PYTHON}:$ENV{PYTHONPATH}' 84 85 substituteInPlace ng/ng.tcl ng/onetcl.cpp \ 86 --replace-fail "libnggui" "$out/lib/libnggui" 87 88 substituteInPlace ng/Togl2.1/CMakeLists.txt \ 89 --replace-fail "/usr/bin/gcc" "$CC" 90 '' 91 + lib.optionalString (!stdenv.hostPlatform.isx86_64) '' 92 # mesh generation differs on x86_64 and aarch64 platform 93 # test_tutorials will fail on aarch64 platform 94 rm tests/pytest/test_tutorials.py 95 ''; 96 97 nativeBuildInputs = [ 98 libicns 99 imagemagick 100 cmake 101 python3Packages.pybind11-stubgen 102 python3Packages.pythonImportsCheckHook 103 ] 104 ++ lib.optional stdenv.hostPlatform.isLinux copyDesktopItems; 105 106 buildInputs = [ 107 metis 108 opencascade-occt 109 zlib 110 tcl 111 tk 112 libGLU 113 xorg.libXmu 114 libjpeg 115 ffmpeg 116 mpi 117 ]; 118 119 propagatedBuildInputs = with python3Packages; [ 120 packaging 121 pybind11 122 mpi4py 123 numpy 124 ]; 125 126 cmakeFlags = [ 127 (lib.cmakeFeature "NETGEN_VERSION_GIT" "v${finalAttrs.version}-0") 128 (lib.cmakeFeature "NG_INSTALL_DIR_BIN" "bin") 129 (lib.cmakeFeature "NG_INSTALL_DIR_LIB" "lib") 130 (lib.cmakeFeature "NG_INSTALL_DIR_CMAKE" "lib/cmake/netgen") 131 (lib.cmakeFeature "NG_INSTALL_DIR_PYTHON" python3Packages.python.sitePackages) 132 (lib.cmakeFeature "NG_INSTALL_DIR_RES" "share") 133 (lib.cmakeFeature "NG_INSTALL_DIR_INCLUDE" "include") 134 (lib.cmakeFeature "CMAKE_CXX_FLAGS" archFlags) 135 (lib.cmakeBool "USE_MPI" true) 136 (lib.cmakeBool "USE_MPI4PY" true) 137 (lib.cmakeBool "PREFER_SYSTEM_PYBIND11" true) 138 (lib.cmakeBool "BUILD_STUB_FILES" true) 139 (lib.cmakeBool "USE_SUPERBUILD" false) # use system packages 140 (lib.cmakeBool "USE_NATIVE_ARCH" false) 141 (lib.cmakeBool "USE_JPEG" true) 142 (lib.cmakeBool "USE_MPEG" true) 143 (lib.cmakeBool "BUILD_TESTING" finalAttrs.finalPackage.doInstallCheck) 144 (lib.cmakeBool "ENABLE_UNIT_TESTS" finalAttrs.finalPackage.doInstallCheck) 145 ]; 146 147 __darwinAllowLocalNetworking = true; 148 149 desktopItems = [ 150 (makeDesktopItem { 151 name = "netgen"; 152 exec = "netgen"; 153 comment = finalAttrs.meta.description; 154 desktopName = "Netgen Mesh Generator"; 155 genericName = "3D Mesh Generator"; 156 categories = [ "Science" ]; 157 icon = "netgen"; 158 }) 159 ]; 160 161 postInstall = 162 lib.optionalString stdenv.hostPlatform.isDarwin '' 163 rm $out/bin/{Netgen1,startup.sh} 164 mkdir -p $out/Applications/netgen.app/Contents/{MacOS,Resources} 165 substituteInPlace $out/Info.plist --replace-fail "Netgen1" "netgen" 166 mv $out/Info.plist $out/Applications/netgen.app/Contents 167 mv $out/Netgen.icns $out/Applications/netgen.app/Contents/Resources 168 ln -s $out/bin/netgen $out/Applications/netgen.app/Contents/MacOS/netgen 169 '' 170 + lib.optionalString stdenv.hostPlatform.isLinux '' 171 # Extract pngs from the Apple icon image and create 172 # the missing ones from the 512x512 image. 173 icns2png --extract ../netgen.icns 174 for size in 16 24 32 48 64 128 256 512; do 175 mkdir -pv $out/share/icons/hicolor/"$size"x"$size"/apps 176 if [ -e netgen_"$size"x"$size"x32.png ] 177 then 178 mv netgen_"$size"x"$size"x32.png $out/share/icons/hicolor/"$size"x"$size"/apps/netgen.png 179 else 180 convert -resize "$size"x"$size" netgen_512x512x32.png $out/share/icons/hicolor/"$size"x"$size"/apps/netgen.png 181 fi 182 done; 183 ''; 184 185 doInstallCheck = true; 186 187 preInstallCheck = '' 188 export PYTHONPATH=$out/${python3Packages.python.sitePackages}:$PYTHONPATH 189 ''; 190 191 installCheckTarget = "test"; 192 193 nativeInstallCheckInputs = [ 194 catch2 195 python3Packages.pytest 196 python3Packages.pytest-check 197 python3Packages.pytest-mpi 198 mpiCheckPhaseHook 199 ]; 200 201 pythonImportsCheck = [ "netgen" ]; 202 203 passthru = { 204 inherit avxSupport avx2Support avx512Support; 205 }; 206 207 meta = { 208 homepage = "https://ngsolve.org"; 209 downloadPage = "https://github.com/NGSolve/netgen"; 210 description = "Atomatic 3d tetrahedral mesh generator"; 211 license = with lib.licenses; [ 212 lgpl2Plus 213 lgpl21Plus 214 lgpl21Only 215 bsd3 216 boost 217 publicDomain 218 ]; 219 platforms = lib.platforms.unix; 220 mainProgram = "netgen"; 221 maintainers = with lib.maintainers; [ qbisi ]; 222 }; 223})