1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 cmake,
6 removeReferencesTo,
7 cppSupport ? true,
8 fortranSupport ? false,
9 fortran,
10 zlibSupport ? true,
11 zlib,
12 szipSupport ? false,
13 szip,
14 mpiSupport ? false,
15 mpi,
16 enableShared ? !stdenv.hostPlatform.isStatic,
17 enableStatic ? stdenv.hostPlatform.isStatic,
18 javaSupport ? false,
19 jdk,
20 usev110Api ? false,
21 threadsafe ? false,
22 python3,
23}:
24
25# cpp and mpi options are mutually exclusive
26# (--enable-unsupported could be used to force the build)
27assert !cppSupport || !mpiSupport;
28
29let
30 inherit (lib) optional optionals;
31in
32
33stdenv.mkDerivation rec {
34 version = "1.14.6";
35 pname =
36 "hdf5"
37 + lib.optionalString cppSupport "-cpp"
38 + lib.optionalString fortranSupport "-fortran"
39 + lib.optionalString mpiSupport "-mpi"
40 + lib.optionalString threadsafe "-threadsafe";
41
42 src = fetchFromGitHub {
43 owner = "HDFGroup";
44 repo = "hdf5";
45 rev = "hdf5_${version}";
46 hash = "sha256-mJTax+VWAL3Amkq3Ij8fxazY2nfpMOTxYMUQlTvY/rg=";
47 };
48
49 passthru = {
50 inherit
51 cppSupport
52 fortranSupport
53 fortran
54 zlibSupport
55 zlib
56 szipSupport
57 szip
58 mpiSupport
59 mpi
60 ;
61 };
62
63 outputs = [
64 "out"
65 "dev"
66 "bin"
67 ];
68
69 nativeBuildInputs = [
70 removeReferencesTo
71 cmake
72 ]
73 ++ optional fortranSupport fortran;
74
75 buildInputs =
76 optional fortranSupport fortran ++ optional szipSupport szip ++ optional javaSupport jdk;
77
78 propagatedBuildInputs = optional zlibSupport zlib ++ optional mpiSupport mpi;
79
80 cmakeFlags = [
81 "-DHDF5_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake"
82 "-DBUILD_STATIC_LIBS=${lib.boolToString enableStatic}"
83 ]
84 ++ lib.optional stdenv.hostPlatform.isDarwin "-DHDF5_BUILD_WITH_INSTALL_NAME=ON"
85 ++ lib.optional cppSupport "-DHDF5_BUILD_CPP_LIB=ON"
86 ++ lib.optional fortranSupport "-DHDF5_BUILD_FORTRAN=ON"
87 ++ lib.optional szipSupport "-DHDF5_ENABLE_SZIP_SUPPORT=ON"
88 ++ lib.optionals mpiSupport [ "-DHDF5_ENABLE_PARALLEL=ON" ]
89 ++ lib.optional enableShared "-DBUILD_SHARED_LIBS=ON"
90 ++ lib.optional javaSupport "-DHDF5_BUILD_JAVA=ON"
91 ++ lib.optional usev110Api "-DDEFAULT_API_VERSION=v110"
92 ++ lib.optionals threadsafe [
93 "-DDHDF5_ENABLE_THREADSAFE:BOOL=ON"
94 "-DHDF5_BUILD_HL_LIB=OFF"
95 ]
96 # broken in nixpkgs since around 1.14.3 -> 1.14.4.3
97 # https://github.com/HDFGroup/hdf5/issues/4208#issuecomment-2098698567
98 ++ lib.optional (
99 stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64
100 ) "-DHDF5_ENABLE_NONSTANDARD_FEATURE_FLOAT16=OFF";
101
102 postInstall = ''
103 find "$out" -type f -exec remove-references-to -t ${stdenv.cc} '{}' +
104 moveToOutput 'bin/' "''${!outputBin}"
105 moveToOutput 'bin/h5cc' "''${!outputDev}"
106 moveToOutput 'bin/h5c++' "''${!outputDev}"
107 moveToOutput 'bin/h5fc' "''${!outputDev}"
108 moveToOutput 'bin/h5pcc' "''${!outputDev}"
109 moveToOutput 'bin/h5hlcc' "''${!outputDev}"
110 moveToOutput 'bin/h5hlc++' "''${!outputDev}"
111 ''
112 +
113 lib.optionalString enableShared
114 # The shared build creates binaries with -shared suffixes,
115 # so we remove these suffixes.
116 ''
117 pushd ''${!outputBin}/bin
118 for file in *-shared; do
119 mv "$file" "''${file%%-shared}"
120 done
121 popd
122 ''
123 + lib.optionalString fortranSupport ''
124 mv $out/mod/shared $dev/include
125 rm -r $out/mod
126
127 find "$out" -type f -exec remove-references-to -t ${fortran} '{}' +
128 '';
129
130 enableParallelBuilding = true;
131
132 passthru.tests = {
133 inherit (python3.pkgs) h5py;
134 };
135
136 meta = with lib; {
137 description = "Data model, library, and file format for storing and managing data";
138 longDescription = ''
139 HDF5 supports an unlimited variety of datatypes, and is designed for flexible and efficient
140 I/O and for high volume and complex data. HDF5 is portable and is extensible, allowing
141 applications to evolve in their use of HDF5. The HDF5 Technology suite includes tools and
142 applications for managing, manipulating, viewing, and analyzing data in the HDF5 format.
143 '';
144 license = licenses.bsd3; # Lawrence Berkeley National Labs BSD 3-Clause variant
145 maintainers = [ maintainers.markuskowa ];
146 homepage = "https://www.hdfgroup.org/HDF5/";
147 platforms = platforms.unix;
148 };
149}