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