1{ lib, stdenv
2, fetchurl, unzip
3, hdf5
4, bzip2
5, libzip
6, zstd
7, szipSupport ? false
8, szip
9, libxml2
10, m4
11, curl # for DAP
12, removeReferencesTo
13}:
14
15let
16 inherit (hdf5) mpiSupport mpi;
17in stdenv.mkDerivation rec {
18 pname = "netcdf" + lib.optionalString mpiSupport "-mpi";
19 version = "4.9.2";
20
21 src = fetchurl {
22 url = "https://downloads.unidata.ucar.edu/netcdf-c/${version}/netcdf-c-${version}.tar.gz";
23 hash = "sha256-zxG6u725lj8J9VB54LAZ9tA3H1L44SZKW6jp/asabEg=";
24 };
25
26 postPatch = ''
27 patchShebangs .
28
29 # this test requires the net
30 for a in ncdap_test/Makefile.am ncdap_test/Makefile.in; do
31 substituteInPlace $a --replace testurl.sh " "
32 done
33
34 # Prevent building the tests from prepending `#!/bin/bash` and wiping out the patched shenbangs.
35 substituteInPlace nczarr_test/Makefile.in \
36 --replace '#!/bin/bash' '${stdenv.shell}'
37 '';
38
39 nativeBuildInputs = [ m4 removeReferencesTo ];
40
41 buildInputs = [
42 curl
43 hdf5
44 libxml2
45 mpi
46 bzip2
47 libzip
48 zstd
49 ] ++ lib.optional szipSupport szip;
50
51 passthru = {
52 inherit mpiSupport mpi;
53 };
54
55 configureFlags = [
56 "--enable-netcdf-4"
57 "--enable-dap"
58 "--enable-shared"
59 "--disable-dap-remote-tests"
60 "--with-plugin-dir=${placeholder "out"}/lib/hdf5-plugins"
61 ]
62 ++ (lib.optionals mpiSupport [ "--enable-parallel-tests" "CC=${mpi}/bin/mpicc" ]);
63
64 enableParallelBuilding = true;
65
66 disallowedReferences = [ stdenv.cc ];
67
68 postFixup = ''
69 remove-references-to -t ${stdenv.cc} "$(readlink -f $out/lib/libnetcdf.settings)"
70 '';
71
72 doCheck = !mpiSupport;
73 nativeCheckInputs = [ unzip ];
74
75 preCheck = ''
76 export HOME=$TEMP
77 '';
78
79 meta = {
80 description = "Libraries for the Unidata network Common Data Format";
81 platforms = lib.platforms.unix;
82 homepage = "https://www.unidata.ucar.edu/software/netcdf/";
83 changelog = "https://docs.unidata.ucar.edu/netcdf-c/${version}/RELEASE_NOTES.html";
84 license = lib.licenses.bsd3;
85 };
86}