1{
2 lib,
3 newScope,
4 stdenv,
5 buildPythonPackage,
6 fetchFromGitHub,
7 fetchpatch2,
8 python,
9 pax-utils,
10
11 # build-system
12 setuptools,
13 cython,
14 pybind11,
15
16 # dependencies
17 decorator,
18 cachetools,
19 mpi4py,
20 fenics-ufl,
21 firedrake-fiat,
22 h5py,
23 libsupermesh,
24 loopy,
25 petsc4py,
26 numpy,
27 packaging,
28 pkgconfig,
29 progress,
30 pyadjoint-ad,
31 pycparser,
32 pytools,
33 requests,
34 rtree,
35 scipy,
36 sympy,
37 islpy,
38 matplotlib,
39
40 # tests
41 pytest,
42 mpi-pytest,
43 mpiCheckPhaseHook,
44 writableTmpDirAsHomeHook,
45
46 # passthru.tests
47 firedrake,
48 mpich,
49}:
50let
51 firedrakePackages = lib.makeScope newScope (self: {
52 inherit (petsc4py.petscPackages) mpi hdf5;
53 mpi4py = self.callPackage mpi4py.override { };
54 h5py = self.callPackage h5py.override { };
55 mpi-pytest = self.callPackage mpi-pytest.override { };
56 });
57in
58buildPythonPackage rec {
59 pname = "firedrake";
60 version = "2025.4.2";
61 pyproject = true;
62
63 src = fetchFromGitHub {
64 owner = "firedrakeproject";
65 repo = "firedrake";
66 tag = version;
67 hash = "sha256-bAGmXoHPAdMYJMMQYVq98LYro1Vd+o9pfvXC3BsQUf0=";
68 };
69
70 postPatch =
71 # relax build-dependency petsc4py
72 ''
73 substituteInPlace pyproject.toml --replace-fail \
74 "petsc4py==3.23.4" "petsc4py"
75 ''
76 + lib.optionalString stdenv.hostPlatform.isLinux ''
77 substituteInPlace firedrake/petsc.py --replace-fail \
78 'program = ["ldd"]' \
79 'program = ["${lib.getExe' pax-utils "lddtree"}"]'
80 ''
81 + lib.optionalString stdenv.hostPlatform.isDarwin ''
82 substituteInPlace firedrake/petsc.py --replace-fail \
83 'program = ["otool"' \
84 'program = ["${lib.getExe' stdenv.cc.bintools.bintools "otool"}"'
85 '';
86
87 pythonRelaxDeps = [
88 "decorator"
89 "slepc4py"
90 ];
91
92 build-system = [
93 cython
94 libsupermesh
95 firedrakePackages.mpi4py
96 numpy
97 pkgconfig
98 pybind11
99 setuptools
100 petsc4py
101 rtree
102 ];
103
104 nativeBuildInputs = [
105 firedrakePackages.mpi
106 ];
107
108 dependencies = [
109 decorator
110 cachetools
111 firedrakePackages.mpi4py
112 fenics-ufl
113 firedrake-fiat
114 firedrakePackages.h5py
115 libsupermesh
116 loopy
117 petsc4py
118 numpy
119 packaging
120 pkgconfig
121 progress
122 pyadjoint-ad
123 pycparser
124 pytools
125 requests
126 rtree
127 scipy
128 sympy
129 # required by script spydump
130 matplotlib
131 ]
132 ++ lib.optionals stdenv.hostPlatform.isDarwin [
133 islpy
134 ];
135
136 postFixup = lib.optionalString stdenv.hostPlatform.isDarwin ''
137 install_name_tool -add_rpath ${libsupermesh}/${python.sitePackages}/libsupermesh/lib \
138 $out/${python.sitePackages}/firedrake/cython/supermeshimpl.cpython-*-darwin.so
139 '';
140
141 doCheck = true;
142
143 __darwinAllowLocalNetworking = true;
144
145 pythonImportsCheck = [ "firedrake" ];
146
147 nativeCheckInputs = [
148 pytest
149 firedrakePackages.mpi-pytest
150 mpiCheckPhaseHook
151 writableTmpDirAsHomeHook
152 ];
153
154 # These scripts are used by official sdist/editable_wheel only
155 postInstall = ''
156 rm $out/bin/firedrake-{check,status,run-split-tests}
157 '';
158
159 preCheck = ''
160 rm -rf firedrake pyop2 tinyasm tsfc
161 '';
162
163 # run official smoke tests
164 checkPhase = ''
165 runHook preCheck
166
167 make check
168
169 runHook postCheck
170 '';
171
172 passthru = {
173 tests = lib.optionalAttrs stdenv.hostPlatform.isLinux {
174 mpich = firedrake.override {
175 petsc4py = petsc4py.override { mpi = mpich; };
176 };
177 };
178 };
179
180 meta = {
181 homepage = "https://www.firedrakeproject.org";
182 downloadPage = "https://github.com/firedrakeproject/firedrake";
183 description = "Automated Finite Element System";
184 license = with lib.licenses; [
185 bsd3
186 lgpl3Plus
187 ];
188 maintainers = with lib.maintainers; [ qbisi ];
189 };
190}