1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 pythonOlder,
6 ninja,
7 numpy,
8 packaging,
9 pybind11,
10 torch,
11 which,
12}:
13
14buildPythonPackage rec {
15 pname = "monai";
16 version = "1.5.0";
17 pyproject = true;
18
19 disabled = pythonOlder "3.9";
20
21 src = fetchFromGitHub {
22 owner = "Project-MONAI";
23 repo = "MONAI";
24 tag = version;
25 hash = "sha256-SUZSWChO0oQlLblPwmCg2zt2Jp5QnpM1CXWnMiOiLhw=";
26 # note: upstream consistently seems to modify the tag shortly after release,
27 # so best to wait a few days before updating
28 };
29
30 postPatch = ''
31 substituteInPlace pyproject.toml --replace-fail 'torch>=2.4.1, <2.7.0' 'torch'
32 '';
33
34 preBuild = ''
35 export MAX_JOBS=$NIX_BUILD_CORES;
36 '';
37
38 build-system = [
39 ninja
40 which
41 ];
42
43 buildInputs = [ pybind11 ];
44
45 dependencies = [
46 numpy
47 packaging
48 torch
49 ];
50
51 pythonRelaxDeps = [ "torch" ];
52
53 env.BUILD_MONAI = 1;
54
55 doCheck = false; # takes too long; tries to download data
56
57 pythonImportsCheck = [
58 "monai"
59 "monai.apps"
60 "monai.data"
61 "monai.engines"
62 "monai.handlers"
63 "monai.inferers"
64 "monai.losses"
65 "monai.metrics"
66 "monai.optimizers"
67 "monai.networks"
68 "monai.transforms"
69 "monai.utils"
70 "monai.visualize"
71 ];
72
73 meta = with lib; {
74 description = "Pytorch framework (based on Ignite) for deep learning in medical imaging";
75 homepage = "https://github.com/Project-MONAI/MONAI";
76 changelog = "https://github.com/Project-MONAI/MONAI/releases/tag/${version}";
77 license = licenses.asl20;
78 maintainers = [ maintainers.bcdarwin ];
79 };
80}