1{
2 stdenv,
3 lib,
4 fetchFromGitHub,
5 python3,
6 makeWrapper,
7 eigen_3_4_0,
8 fftw,
9 libtiff,
10 libpng,
11 zlib,
12 ants,
13 bc,
14 qt5,
15 libGL,
16 libGLU,
17 libX11,
18 libXext,
19 less,
20 withGui ? true,
21}:
22
23stdenv.mkDerivation (finalAttrs: {
24 pname = "mrtrix";
25 version = "3.0.7";
26
27 src = fetchFromGitHub {
28 owner = "MRtrix3";
29 repo = "mrtrix3";
30 rev = finalAttrs.version;
31 hash = "sha256-cPI6Ac1Yp5yb07zv9r5O7ZbsHpjrv5BkzbAW1qgj3gQ=";
32 fetchSubmodules = true;
33 };
34
35 nativeBuildInputs = [
36 makeWrapper
37 less
38 python3
39 ]
40 ++ lib.optional withGui qt5.wrapQtAppsHook;
41
42 buildInputs = [
43 ants
44 eigen_3_4_0
45 python3
46 fftw
47 libtiff
48 libpng
49 zlib
50 ]
51 ++ lib.optionals withGui [
52 libGL
53 libGLU
54 libX11
55 libXext
56 qt5.qtbase
57 qt5.qtsvg
58 ];
59
60 nativeInstallCheckInputs = [ bc ];
61
62 postPatch = ''
63 patchShebangs --build ./build ./configure ./run_tests
64 patchShebangs --host ./bin/*
65
66 # patching interpreters before fixup is needed for tests:
67 patchShebangs testing/binaries/data/vectorstats/*py
68
69 substituteInPlace ./run_tests \
70 --replace-fail 'git submodule update --init $datadir >> $LOGFILE 2>&1' ""
71
72 # reduce build noise
73 substituteInPlace ./configure \
74 --replace-fail "[ '-Wall' ]" "[]"
75
76 # fix error output (cuts off after a few lines otherwise)
77 substituteInPlace ./build \
78 --replace-fail 'stderr=subprocess.PIPE' 'stderr=None'
79 '';
80
81 configurePhase = ''
82 runHook preConfigure
83 export EIGEN_CFLAGS="-isystem ${eigen_3_4_0}/include/eigen3"
84 unset LD # similar to https://github.com/MRtrix3/mrtrix3/issues/1519
85 ./configure ${lib.optionalString (!withGui) "-nogui"};
86 runHook postConfigure
87 '';
88
89 buildPhase = ''
90 runHook preBuild
91 ./build
92 (cd testing && ../build)
93 runHook postBuild
94 '';
95
96 installCheckPhase = ''
97 runHook preInstallCheck
98 ./run_tests units
99 ./run_tests binaries
100
101 # can also `./run_tests scripts`, but this fails due to lack of FSL package
102 # (and there's no convenient way to disable individual tests)
103 runHook postInstallCheck
104 '';
105 doInstallCheck = true;
106
107 installPhase = ''
108 runHook preInstall
109 mkdir -p $out
110 cp -ar lib $out/lib
111 cp -ar bin $out/bin
112 runHook postInstall
113 '';
114
115 preFixup =
116 if withGui then
117 ''
118 qtWrapperArgs+=(--prefix PATH : ${lib.makeBinPath [ ants ]})
119 ''
120 else
121 ''
122 for prog in $out/bin/*; do
123 if [[ -x "$prog" ]]; then
124 wrapProgram $prog --prefix PATH : ${lib.makeBinPath [ ants ]}
125 fi
126 done
127 '';
128
129 meta = with lib; {
130 broken = (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64);
131 homepage = "https://github.com/MRtrix3/mrtrix3";
132 description = "Suite of tools for diffusion imaging";
133 maintainers = with maintainers; [ bcdarwin ];
134 platforms = platforms.linux;
135 license = licenses.mpl20;
136 };
137})