nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 version,
3 tag,
4 sourceSha256,
5}:
6
7{
8 lib,
9 stdenv,
10 fetchFromGitHub,
11 fetchpatch,
12 cmake,
13 castxml,
14 swig,
15 expat,
16 eigen,
17 fftw,
18 gdcm,
19 hdf5-cpp,
20 libjpeg,
21 libminc,
22 libtiff,
23 libpng,
24 libX11,
25 libuuid,
26 patchelf,
27 python ? null,
28 numpy ? null,
29 xz,
30 vtk,
31 which,
32 zlib,
33 enablePython ? false,
34 enableRtk ? true,
35}:
36
37let
38 # Python wrapper contains its own VTK support incompatible with MODULE_ITKVtkGlue
39 withVtk = !enablePython;
40
41 itkGenericLabelInterpolatorSrc = fetchFromGitHub {
42 owner = "InsightSoftwareConsortium";
43 repo = "ITKGenericLabelInterpolator";
44 rev = "2f3768110ffe160c00c533a1450a49a16f4452d9";
45 hash = "sha256-Cm3jg14MMnbr/sP+gqR2Rh25xJjoRvpmY/jP/DKH978=";
46 };
47
48 itkAdaptiveDenoisingSrc = fetchFromGitHub {
49 owner = "ntustison";
50 repo = "ITKAdaptiveDenoising";
51 rev = "24825c8d246e941334f47968553f0ae388851f0c";
52 hash = "sha256-deJbza36c0Ohf9oKpO2T4po37pkyI+2wCSeGL4r17Go=";
53 };
54
55 itkSimpleITKFiltersSrc = fetchFromGitHub {
56 owner = "InsightSoftwareConsortium";
57 repo = "ITKSimpleITKFilters";
58 rev = "bb896868fc6480835495d0da4356d5db009592a6";
59 hash = "sha256-MfaIA0xxA/pzUBSwnAevr17iR23Bo5iQO2cSyknS3o4=";
60 };
61
62 rtkSrc = fetchFromGitHub {
63 owner = "RTKConsortium";
64 repo = "RTK";
65 rev = "583288b1898dedcfb5e4d602e31020b452971383";
66 hash = "sha256-1ItsLCRwRzGDSRe4xUDg09Hksu1nKichbWuM0YSVkbM=";
67 };
68in
69
70stdenv.mkDerivation {
71 pname = "itk";
72 inherit version;
73
74 src = fetchFromGitHub {
75 owner = "InsightSoftwareConsortium";
76 repo = "ITK";
77 inherit tag;
78 sha256 = sourceSha256;
79 };
80
81 patches = lib.optionals (lib.versionOlder version "5.4") [
82 (fetchpatch {
83 name = "fix-gcc13-build";
84 url = "https://github.com/InsightSoftwareConsortium/ITK/commit/9a719a0d2f5f489eeb9351b0ef913c3693147a4f.patch";
85 hash = "sha256-dDyqYOzo91afR8W7k2N64X6l7t6Ws1C9iuRkWHUe0fg=";
86 })
87 ];
88
89 postPatch = ''
90 substituteInPlace CMake/ITKSetStandardCompilerFlags.cmake \
91 --replace "-march=corei7" "" \
92 --replace "-mtune=native" ""
93 ln -sr ${itkGenericLabelInterpolatorSrc} Modules/External/ITKGenericLabelInterpolator
94 ln -sr ${itkAdaptiveDenoisingSrc} Modules/External/ITKAdaptiveDenoising
95 ln -sr ${itkSimpleITKFiltersSrc} Modules/External/ITKSimpleITKFilters
96 ln -sr ${rtkSrc} Modules/Remote/RTK
97
98 # fix build with GCC 15
99 substituteInPlace Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/src/gtest-death-test.cc \
100 --replace-fail \
101 '#include <utility>' \
102 '#include <utility>
103 #include <cstdint>'
104 substituteInPlace Modules/Core/Common/include/itkFloatingPointExceptions.h \
105 --replace-fail \
106 '#include "itkSingletonMacro.h"' \
107 '#include "itkSingletonMacro.h"
108 #include <cstdint>'
109 '';
110
111 cmakeFlags = [
112 "-DBUILD_EXAMPLES=OFF"
113 "-DBUILD_SHARED_LIBS=ON"
114 "-DITK_FORBID_DOWNLOADS=ON"
115 "-DITK_USE_SYSTEM_LIBRARIES=ON" # finds common libraries e.g. hdf5, libpng, libtiff, zlib, but not GDCM, NIFTI, MINC, etc.
116 (lib.cmakeBool "ITK_USE_SYSTEM_EIGEN" (lib.versionAtLeast version "5.4"))
117 "-DITK_USE_SYSTEM_GOOGLETEST=OFF" # ANTs build failure due to https://github.com/ANTsX/ANTs/issues/1489
118 "-DITK_USE_SYSTEM_GDCM=ON"
119 "-DITK_USE_SYSTEM_MINC=ON"
120 "-DLIBMINC_DIR=${libminc}/lib/cmake"
121 "-DModule_ITKMINC=ON"
122 "-DModule_ITKIOMINC=ON"
123 "-DModule_ITKIOTransformMINC=ON"
124 "-DModule_SimpleITKFilters=ON"
125 "-DModule_ITKReview=ON"
126 "-DModule_MGHIO=ON"
127 "-DModule_AdaptiveDenoising=ON"
128 "-DModule_GenericLabelInterpolator=ON"
129 ]
130 ++ lib.optionals enableRtk [
131 "-DModule_RTK=ON"
132 ]
133 ++ lib.optionals enablePython [
134 "-DITK_WRAP_PYTHON=ON"
135 "-DITK_USE_SYSTEM_CASTXML=ON"
136 "-DITK_USE_SYSTEM_SWIG=ON"
137 "-DPY_SITE_PACKAGES_PATH=${placeholder "out"}/${python.sitePackages}"
138 ]
139 ++ lib.optionals withVtk [ "-DModule_ITKVtkGlue=ON" ]
140 ++ lib.optionals (lib.versionOlder version "5.4") [ "-DCMAKE_POLICY_VERSION_MINIMUM=3.5" ];
141
142 nativeBuildInputs = [
143 cmake
144 xz
145 ]
146 ++ lib.optionals enablePython [
147 castxml
148 swig
149 which
150 ];
151
152 buildInputs = [
153 libX11
154 libuuid
155 ]
156 ++ lib.optionals (lib.versionAtLeast version "5.4") [ eigen ]
157 ++ lib.optionals enablePython [ python ]
158 ++ lib.optionals withVtk [ vtk ];
159 # Due to ITKVtkGlue=ON and the additional dependencies needed to configure VTK 9
160 # (specifically libGL and libX11 on Linux),
161 # it's now seemingly necessary for packages that configure ITK to
162 # also include configuration deps of VTK, even if VTK is not required or available.
163 # These deps were propagated from VTK 9 in https://github.com/NixOS/nixpkgs/pull/206935,
164 # so we simply propagate them again from ITK.
165 # This admittedly is a hack and seems like an issue with VTK 9's CMake configuration.
166 propagatedBuildInputs = [
167 # The dependencies we've un-vendored from ITK, such as GDCM, must be propagated,
168 # otherwise other software built against ITK fails to configure since ITK headers
169 # refer to these previously vendored libraries:
170 expat
171 fftw
172 gdcm
173 hdf5-cpp
174 libjpeg
175 libminc
176 libpng
177 libtiff
178 zlib
179 ]
180 ++ lib.optionals withVtk vtk.propagatedBuildInputs
181 ++ lib.optionals enablePython [ numpy ];
182
183 postInstall = lib.optionalString enablePython ''
184 substitute \
185 ${./itk.egg-info} \
186 $out/${python.sitePackages}/itk-${version}.egg-info \
187 --subst-var-by ITK_VER "${version}"
188 '';
189
190 # remove forbidden reference to /build which occur when building the Python wrapping
191 # (also remove a copy of itkTestDriver with incorrect permissions/RPATH):
192 preFixup = lib.optionals enablePython ''
193 rm $out/${python.sitePackages}/itk/itkTestDriver
194 find $out/${python.sitePackages}/itk -type f -name '*.so*' -exec \
195 patchelf {} --shrink-rpath --allowed-rpath-prefixes "$NIX_STORE" \;
196 '';
197
198 meta = {
199 description = "Insight Segmentation and Registration Toolkit";
200 homepage = "https://www.itk.org";
201 license = lib.licenses.asl20;
202 maintainers = with lib.maintainers; [ bcdarwin ];
203 # aarch64-linux Python wrapping fails with "error: unknown type name '_Float128'" and similar;
204 # compilation runs slowly and times out on Darwin
205 platforms = with lib.platforms; if enablePython then [ "x86_64-linux" ] else unix;
206 };
207}