From ec3f5a021bc12d32bee8f33828f7daa20a9d24c6 Mon Sep 17 00:00:00 2001 From: qbisi Date: Tue, 4 Feb 2025 16:06:47 +0800 Subject: [PATCH 01/12] petsc: simplify configurePhase --- pkgs/by-name/pe/petsc/package.nix | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 3db7a522fff6..5645677df27d 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -47,7 +47,9 @@ stdenv.mkDerivation rec { lapack ] ++ lib.optional hdf5-support hdf5 ++ lib.optional petsc-withp4est p4est ++ lib.optionals withParmetis [ metis parmetis ]; - prePatch = lib.optionalString stdenv.hostPlatform.isDarwin '' + postPatch = '' + patchShebangs ./lib/petsc/bin + '' + lib.optionalString stdenv.hostPlatform.isDarwin '' substituteInPlace config/install.py \ --replace /usr/bin/install_name_tool ${cctools}/bin/install_name_tool ''; @@ -67,6 +69,15 @@ stdenv.mkDerivation rec { "--with-metis-dir=${metis}" "--with-parmetis=1" "--with-parmetis-dir=${parmetis}" + ] ++ lib.optionals petsc-withp4est [ + "--with-p4est=1" + "--with-zlib-include=${zlib.dev}/include" + "--with-zlib-lib=[-L${zlib}/lib,-lz]" + ] ++ lib.optionals hdf5-support [ + "--with-hdf5=1" + "--with-hdf5-fortran-bindings=1" + "--with-hdf5-include=${hdf5.dev}/include" + "--with-hdf5-lib=[-L${hdf5}/lib,-lhdf5]" ] ++ lib.optionals petsc-optimized [ "--with-debugging=0" "COPTFLAGS=-O3" @@ -74,22 +85,6 @@ stdenv.mkDerivation rec { "CXXOPTFLAGS=-O3" "CXXFLAGS=-O3" ]; - preConfigure = '' - patchShebangs ./lib/petsc/bin - '' + lib.optionalString petsc-withp4est '' - configureFlagsArray+=( - "--with-p4est=1" - "--with-zlib-include=${zlib.dev}/include" - "--with-zlib-lib=-L${zlib}/lib -lz" - ) - '' + lib.optionalString hdf5-support '' - configureFlagsArray+=( - "--with-hdf5=1" - "--with-hdf5-fortran-bindings=1" - "--with-hdf5-include=${hdf5.dev}/include" - "--with-hdf5-lib=-L${hdf5}/lib -lhdf5" - ) - ''; hardeningDisable = lib.optionals (!petsc-optimized) [ "fortify" From e6bda1731a4851ef920168fcc8e4e8f8cef8f441 Mon Sep 17 00:00:00 2001 From: qbisi Date: Tue, 4 Feb 2025 16:48:17 +0800 Subject: [PATCH 02/12] petsc: reformat with nixfmt-rfc-style --- pkgs/by-name/pe/petsc/package.nix | 97 ++++++++++++++++++------------- 1 file changed, 56 insertions(+), 41 deletions(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 5645677df27d..c83df800ca11 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -42,49 +42,64 @@ stdenv.mkDerivation rec { gfortran pkg-config ] ++ lib.optional mpiSupport mpi; - buildInputs = [ - blas - lapack - ] ++ lib.optional hdf5-support hdf5 ++ lib.optional petsc-withp4est p4est ++ lib.optionals withParmetis [ metis parmetis ]; + buildInputs = + [ + blas + lapack + ] + ++ lib.optional hdf5-support hdf5 + ++ lib.optional petsc-withp4est p4est + ++ lib.optionals withParmetis [ + metis + parmetis + ]; - postPatch = '' - patchShebangs ./lib/petsc/bin - '' + lib.optionalString stdenv.hostPlatform.isDarwin '' - substituteInPlace config/install.py \ - --replace /usr/bin/install_name_tool ${cctools}/bin/install_name_tool - ''; + postPatch = + '' + patchShebangs ./lib/petsc/bin + '' + + lib.optionalString stdenv.hostPlatform.isDarwin '' + substituteInPlace config/install.py \ + --replace /usr/bin/install_name_tool ${cctools}/bin/install_name_tool + ''; - configureFlags = [ - "--with-blas=1" - "--with-lapack=1" - "--with-scalar-type=${petsc-scalar-type}" - "--with-precision=${petsc-precision}" - "--with-mpi=${if mpiSupport then "1" else "0"}" - ] ++ lib.optionals mpiSupport [ - "--CC=mpicc" - "--with-cxx=mpicxx" - "--with-fc=mpif90" - ] ++ lib.optionals (mpiSupport && withParmetis) [ - "--with-metis=1" - "--with-metis-dir=${metis}" - "--with-parmetis=1" - "--with-parmetis-dir=${parmetis}" - ] ++ lib.optionals petsc-withp4est [ - "--with-p4est=1" - "--with-zlib-include=${zlib.dev}/include" - "--with-zlib-lib=[-L${zlib}/lib,-lz]" - ] ++ lib.optionals hdf5-support [ - "--with-hdf5=1" - "--with-hdf5-fortran-bindings=1" - "--with-hdf5-include=${hdf5.dev}/include" - "--with-hdf5-lib=[-L${hdf5}/lib,-lhdf5]" - ] ++ lib.optionals petsc-optimized [ - "--with-debugging=0" - "COPTFLAGS=-O3" - "FOPTFLAGS=-O3" - "CXXOPTFLAGS=-O3" - "CXXFLAGS=-O3" - ]; + configureFlags = + [ + "--with-blas=1" + "--with-lapack=1" + "--with-scalar-type=${petsc-scalar-type}" + "--with-precision=${petsc-precision}" + "--with-mpi=${if mpiSupport then "1" else "0"}" + ] + ++ lib.optionals mpiSupport [ + "--CC=mpicc" + "--with-cxx=mpicxx" + "--with-fc=mpif90" + ] + ++ lib.optionals (mpiSupport && withParmetis) [ + "--with-metis=1" + "--with-metis-dir=${metis}" + "--with-parmetis=1" + "--with-parmetis-dir=${parmetis}" + ] + ++ lib.optionals petsc-withp4est [ + "--with-p4est=1" + "--with-zlib-include=${zlib.dev}/include" + "--with-zlib-lib=[-L${zlib}/lib,-lz]" + ] + ++ lib.optionals hdf5-support [ + "--with-hdf5=1" + "--with-hdf5-fortran-bindings=1" + "--with-hdf5-include=${hdf5.dev}/include" + "--with-hdf5-lib=[-L${hdf5}/lib,-lhdf5]" + ] + ++ lib.optionals petsc-optimized [ + "--with-debugging=0" + "COPTFLAGS=-O3" + "FOPTFLAGS=-O3" + "CXXOPTFLAGS=-O3" + "CXXFLAGS=-O3" + ]; hardeningDisable = lib.optionals (!petsc-optimized) [ "fortify" From 602e8d527b3277770acc30bcc6801f2889a1f07b Mon Sep 17 00:00:00 2001 From: qbisi Date: Tue, 4 Feb 2025 19:53:26 +0800 Subject: [PATCH 03/12] petsc: add standalone metis support --- pkgs/by-name/pe/petsc/package.nix | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index c83df800ca11..6ad696a539cf 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -14,6 +14,7 @@ hdf5-support ? false, hdf5, metis, + withMetis ? false, parmetis, withParmetis ? false, pkg-config, @@ -27,6 +28,9 @@ # This version of PETSc does not support a non-MPI p4est build assert petsc-withp4est -> p4est.mpiSupport; +# Package parmetis depend on metis and mpi support +assert withParmetis -> (withMetis && mpiSupport); + stdenv.mkDerivation rec { pname = "petsc"; version = "3.21.4"; @@ -49,10 +53,8 @@ stdenv.mkDerivation rec { ] ++ lib.optional hdf5-support hdf5 ++ lib.optional petsc-withp4est p4est - ++ lib.optionals withParmetis [ - metis - parmetis - ]; + ++ lib.optional withMetis metis + ++ lib.optional withParmetis parmetis; postPatch = '' @@ -76,9 +78,11 @@ stdenv.mkDerivation rec { "--with-cxx=mpicxx" "--with-fc=mpif90" ] - ++ lib.optionals (mpiSupport && withParmetis) [ + ++ lib.optionals withMetis [ "--with-metis=1" "--with-metis-dir=${metis}" + ] + ++ lib.optionals withParmetis [ "--with-parmetis=1" "--with-parmetis-dir=${parmetis}" ] From f4bba88df7414956e652134e198762d619d657cc Mon Sep 17 00:00:00 2001 From: qbisi Date: Tue, 4 Feb 2025 20:10:36 +0800 Subject: [PATCH 04/12] petsc: add ptscotch support --- pkgs/by-name/pe/petsc/package.nix | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 6ad696a539cf..2c29bfd2129a 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -17,6 +17,8 @@ withMetis ? false, parmetis, withParmetis ? false, + scotch, + withPtscotch ? false, pkg-config, p4est, zlib, # propagated by p4est but required by petsc @@ -31,6 +33,8 @@ assert petsc-withp4est -> p4est.mpiSupport; # Package parmetis depend on metis and mpi support assert withParmetis -> (withMetis && mpiSupport); +assert withPtscotch -> mpiSupport; + stdenv.mkDerivation rec { pname = "petsc"; version = "3.21.4"; @@ -54,7 +58,8 @@ stdenv.mkDerivation rec { ++ lib.optional hdf5-support hdf5 ++ lib.optional petsc-withp4est p4est ++ lib.optional withMetis metis - ++ lib.optional withParmetis parmetis; + ++ lib.optional withParmetis parmetis + ++ lib.optional withPtscotch scotch; postPatch = '' @@ -86,6 +91,11 @@ stdenv.mkDerivation rec { "--with-parmetis=1" "--with-parmetis-dir=${parmetis}" ] + ++ lib.optionals withPtscotch [ + "--with-ptscotch=1" + "--with-ptscotch-include=${scotch.dev}/include" + "--with-ptscotch-lib=[-L${scotch}/lib,-lptscotch,-lptesmumps,-lptscotchparmetisv3,-lptscotcherr,-lesmumps,-lscotch,-lscotcherr]" + ] ++ lib.optionals petsc-withp4est [ "--with-p4est=1" "--with-zlib-include=${zlib.dev}/include" From 0b2160ea3cbdfa033401a5716ad094b9d76aeacf Mon Sep 17 00:00:00 2001 From: qbisi Date: Tue, 4 Feb 2025 20:14:57 +0800 Subject: [PATCH 05/12] petsc: add scalapack and mumps support --- pkgs/by-name/pe/petsc/package.nix | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 2c29bfd2129a..6a13227e4031 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -19,6 +19,10 @@ withParmetis ? false, scotch, withPtscotch ? false, + scalapack, + withScalapack ? false, + mumps_par, + withMumps ? false, pkg-config, p4est, zlib, # propagated by p4est but required by petsc @@ -34,6 +38,8 @@ assert petsc-withp4est -> p4est.mpiSupport; assert withParmetis -> (withMetis && mpiSupport); assert withPtscotch -> mpiSupport; +assert withScalapack -> mpiSupport; +assert withMumps -> withScalapack; stdenv.mkDerivation rec { pname = "petsc"; @@ -59,7 +65,9 @@ stdenv.mkDerivation rec { ++ lib.optional petsc-withp4est p4est ++ lib.optional withMetis metis ++ lib.optional withParmetis parmetis - ++ lib.optional withPtscotch scotch; + ++ lib.optional withPtscotch scotch + ++ lib.optional withScalapack scalapack + ++ lib.optional withMumps mumps_par; postPatch = '' @@ -96,6 +104,14 @@ stdenv.mkDerivation rec { "--with-ptscotch-include=${scotch.dev}/include" "--with-ptscotch-lib=[-L${scotch}/lib,-lptscotch,-lptesmumps,-lptscotchparmetisv3,-lptscotcherr,-lesmumps,-lscotch,-lscotcherr]" ] + ++ lib.optionals withScalapack [ + "--with-scalapack=1" + "--with-scalapack-dir=${scalapack}" + ] + ++ lib.optionals withMumps [ + "--with-mumps=1" + "--with-mumps-dir=${mumps_par}" + ] ++ lib.optionals petsc-withp4est [ "--with-p4est=1" "--with-zlib-include=${zlib.dev}/include" From ad4db6e3abc06917e8dc171f401b2ece716ce757 Mon Sep 17 00:00:00 2001 From: qbisi Date: Tue, 4 Feb 2025 19:42:47 +0800 Subject: [PATCH 06/12] python312Packages.petsc4py: init at 3.22.3 --- .../petsc/fix-petsc4py-install-prefix.patch | 22 ++++++++++++++ pkgs/by-name/pe/petsc/package.nix | 30 +++++++++++++++---- pkgs/top-level/python-packages.nix | 6 ++++ 3 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 pkgs/by-name/pe/petsc/fix-petsc4py-install-prefix.patch diff --git a/pkgs/by-name/pe/petsc/fix-petsc4py-install-prefix.patch b/pkgs/by-name/pe/petsc/fix-petsc4py-install-prefix.patch new file mode 100644 index 000000000000..dd3a50114f07 --- /dev/null +++ b/pkgs/by-name/pe/petsc/fix-petsc4py-install-prefix.patch @@ -0,0 +1,22 @@ +diff --git a/config/BuildSystem/config/packages/petsc4py.py b/config/BuildSystem/config/packages/petsc4py.py +index 4a58243..831aa04 100644 +--- a/config/BuildSystem/config/packages/petsc4py.py ++++ b/config/BuildSystem/config/packages/petsc4py.py +@@ -37,7 +37,7 @@ class Configure(config.package.Package): + + def Install(self): + import os +- installLibPath = os.path.join(self.installDir, 'lib') ++ installLibPath = os.path.join(self.installDir, 'lib', '@PYTHON_SITEPACKAGES@') + if self.setCompilers.isDarwin(self.log): + apple = 'You may need to\n (csh/tcsh) setenv MACOSX_DEPLOYMENT_TARGET 10.X\n (sh/bash) MACOSX_DEPLOYMENT_TARGET=10.X; export MACOSX_DEPLOYMENT_TARGET\nbefore running make on PETSc' + else: +@@ -70,7 +70,7 @@ class Configure(config.package.Package): + newdir += 'NUMPY_INCLUDE="'+numpy_include+'" ' + + self.addDefine('HAVE_PETSC4PY',1) +- self.addDefine('PETSC4PY_INSTALL_PATH','"'+os.path.join(self.installdir.dir,'lib')+'"') ++ self.addDefine('PETSC4PY_INSTALL_PATH','"'+installLibPath+'"') + self.addMakeMacro('PETSC4PY','yes') + self.addMakeRule('petsc4pybuild','', \ + ['@echo "*** Building petsc4py ***"',\ diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 6a13227e4031..87009b8a8f91 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -4,7 +4,10 @@ fetchzip, cctools, gfortran, + replaceVars, python3, + python3Packages, + withPetsc4py ? false, blas, lapack, mpiSupport ? true, @@ -51,11 +54,19 @@ stdenv.mkDerivation rec { }; strictDeps = true; - nativeBuildInputs = [ - python3 - gfortran - pkg-config - ] ++ lib.optional mpiSupport mpi; + + nativeBuildInputs = + [ + python3 + gfortran + pkg-config + ] + ++ lib.optional mpiSupport mpi + ++ lib.optionals withPetsc4py [ + python3Packages.setuptools + python3Packages.cython + ]; + buildInputs = [ blas @@ -69,6 +80,14 @@ stdenv.mkDerivation rec { ++ lib.optional withScalapack scalapack ++ lib.optional withMumps mumps_par; + propagatedBuildInputs = lib.optional withPetsc4py python3Packages.numpy; + + patches = [ + (replaceVars ./fix-petsc4py-install-prefix.patch { + PYTHON_SITEPACKAGES = python3.sitePackages; + }) + ]; + postPatch = '' patchShebangs ./lib/petsc/bin @@ -86,6 +105,7 @@ stdenv.mkDerivation rec { "--with-precision=${petsc-precision}" "--with-mpi=${if mpiSupport then "1" else "0"}" ] + ++ lib.optional withPetsc4py "--with-petsc4py=1" ++ lib.optionals mpiSupport [ "--CC=mpicc" "--with-cxx=mpicxx" diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index b98d245a8297..85ddafd5b6fe 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -10342,6 +10342,12 @@ self: super: with self; { pesq = callPackage ../development/python-modules/pesq { }; + petsc4py = toPythonModule (pkgs.petsc.override { + python3 = python; + python3Packages = self; + withPetsc4py = true; + }); + pex = callPackage ../development/python-modules/pex { }; pexif = callPackage ../development/python-modules/pexif { }; From 3389354ca5c3f51eca33025f73eaf36aaa23ab31 Mon Sep 17 00:00:00 2001 From: qbisi Date: Wed, 5 Feb 2025 15:32:48 +0800 Subject: [PATCH 07/12] petsc: add withFullDeps option --- pkgs/by-name/pe/petsc/package.nix | 15 ++++++++------- pkgs/top-level/python-packages.nix | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 87009b8a8f91..9c6e64d6e409 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -13,25 +13,26 @@ mpiSupport ? true, mpi, # generic mpi dependency mpiCheckPhaseHook, - petsc-withp4est ? false, - hdf5-support ? false, + petsc-withp4est ? withFullDeps, + hdf5-support ? withFullDeps, hdf5, metis, - withMetis ? false, + withMetis ? withFullDeps, parmetis, - withParmetis ? false, + withParmetis ? false, # parmetis is unfree and should be enabled manualy scotch, - withPtscotch ? false, + withPtscotch ? withFullDeps, scalapack, - withScalapack ? false, + withScalapack ? withFullDeps, mumps_par, - withMumps ? false, + withMumps ? withFullDeps, pkg-config, p4est, zlib, # propagated by p4est but required by petsc petsc-optimized ? false, petsc-scalar-type ? "real", petsc-precision ? "double", + withFullDeps ? false }: # This version of PETSc does not support a non-MPI p4est build diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 85ddafd5b6fe..dbabff224391 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -10346,6 +10346,8 @@ self: super: with self; { python3 = python; python3Packages = self; withPetsc4py = true; + withFullDeps = true; + petsc-optimized = true; }); pex = callPackage ../development/python-modules/pex { }; From 291a201097ee67aafd3157149ab29d4e6a049e8a Mon Sep 17 00:00:00 2001 From: qbisi Date: Wed, 5 Feb 2025 15:48:27 +0800 Subject: [PATCH 08/12] petsc: rename some optional dependency flags --- pkgs/by-name/pe/petsc/package.nix | 14 +++++++------- pkgs/top-level/all-packages.nix | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 9c6e64d6e409..82b0f396a992 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -13,8 +13,8 @@ mpiSupport ? true, mpi, # generic mpi dependency mpiCheckPhaseHook, - petsc-withp4est ? withFullDeps, - hdf5-support ? withFullDeps, + withP4est ? withFullDeps, + withHdf5 ? withFullDeps, hdf5, metis, withMetis ? withFullDeps, @@ -36,7 +36,7 @@ }: # This version of PETSc does not support a non-MPI p4est build -assert petsc-withp4est -> p4est.mpiSupport; +assert withP4est -> (p4est.mpiSupport && mpiSupport); # Package parmetis depend on metis and mpi support assert withParmetis -> (withMetis && mpiSupport); @@ -73,8 +73,8 @@ stdenv.mkDerivation rec { blas lapack ] - ++ lib.optional hdf5-support hdf5 - ++ lib.optional petsc-withp4est p4est + ++ lib.optional withHdf5 hdf5 + ++ lib.optional withP4est p4est ++ lib.optional withMetis metis ++ lib.optional withParmetis parmetis ++ lib.optional withPtscotch scotch @@ -133,12 +133,12 @@ stdenv.mkDerivation rec { "--with-mumps=1" "--with-mumps-dir=${mumps_par}" ] - ++ lib.optionals petsc-withp4est [ + ++ lib.optionals withP4est [ "--with-p4est=1" "--with-zlib-include=${zlib.dev}/include" "--with-zlib-lib=[-L${zlib}/lib,-lz]" ] - ++ lib.optionals hdf5-support [ + ++ lib.optionals withHdf5 [ "--with-hdf5=1" "--with-hdf5-fortran-bindings=1" "--with-hdf5-include=${hdf5.dev}/include" diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index fb3618d837a1..1144d59a2f83 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17075,7 +17075,7 @@ with pkgs; ### SCIENCE/GEOLOGY pflotran = callPackage ../by-name/pf/pflotran/package.nix { petsc = petsc.override { - hdf5-support = true; + withHdf5 = true; hdf5 = hdf5-fortran-mpi; petsc-optimized = true; }; From d3b3d83b0fcd2d0e7fd7922a3da66e6a1c9491db Mon Sep 17 00:00:00 2001 From: qbisicwate Date: Thu, 6 Feb 2025 17:46:19 +0800 Subject: [PATCH 09/12] petsc: use lib.{getDev,getLib} instead *.{dev,lib} --- pkgs/by-name/pe/petsc/package.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 82b0f396a992..552416df8ec2 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -122,8 +122,8 @@ stdenv.mkDerivation rec { ] ++ lib.optionals withPtscotch [ "--with-ptscotch=1" - "--with-ptscotch-include=${scotch.dev}/include" - "--with-ptscotch-lib=[-L${scotch}/lib,-lptscotch,-lptesmumps,-lptscotchparmetisv3,-lptscotcherr,-lesmumps,-lscotch,-lscotcherr]" + "--with-ptscotch-include=${lib.getDev scotch}/include" + "--with-ptscotch-lib=[-L${lib.getLib scotch}/lib,-lptscotch,-lptesmumps,-lptscotchparmetisv3,-lptscotcherr,-lesmumps,-lscotch,-lscotcherr]" ] ++ lib.optionals withScalapack [ "--with-scalapack=1" @@ -135,14 +135,14 @@ stdenv.mkDerivation rec { ] ++ lib.optionals withP4est [ "--with-p4est=1" - "--with-zlib-include=${zlib.dev}/include" - "--with-zlib-lib=[-L${zlib}/lib,-lz]" + "--with-zlib-include=${lib.getDev zlib}/include" + "--with-zlib-lib=[-L${lib.getLib zlib}/lib,-lz]" ] ++ lib.optionals withHdf5 [ "--with-hdf5=1" "--with-hdf5-fortran-bindings=1" - "--with-hdf5-include=${hdf5.dev}/include" - "--with-hdf5-lib=[-L${hdf5}/lib,-lhdf5]" + "--with-hdf5-include=${lib.getDev hdf5}/include" + "--with-hdf5-lib=[-L${lib.getLib hdf5}/lib,-lhdf5]" ] ++ lib.optionals petsc-optimized [ "--with-debugging=0" From 92dc787ceca4c86d4df79e1d53caaa4e32a882f0 Mon Sep 17 00:00:00 2001 From: qbisi Date: Fri, 14 Feb 2025 18:00:55 +0800 Subject: [PATCH 10/12] petsc: reorder build options and external dependency --- pkgs/by-name/pe/petsc/package.nix | 44 ++++++++++++++++++------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 552416df8ec2..9d5e412fad7b 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -7,32 +7,38 @@ replaceVars, python3, python3Packages, - withPetsc4py ? false, blas, lapack, - mpiSupport ? true, + zlib, # propagated by p4est but required by petsc mpi, # generic mpi dependency mpiCheckPhaseHook, - withP4est ? withFullDeps, - withHdf5 ? withFullDeps, - hdf5, - metis, - withMetis ? withFullDeps, - parmetis, - withParmetis ? false, # parmetis is unfree and should be enabled manualy - scotch, - withPtscotch ? withFullDeps, - scalapack, - withScalapack ? withFullDeps, - mumps_par, - withMumps ? withFullDeps, - pkg-config, - p4est, - zlib, # propagated by p4est but required by petsc + + # Build options petsc-optimized ? false, petsc-scalar-type ? "real", petsc-precision ? "double", - withFullDeps ? false + mpiSupport ? true, + withPetsc4py ? false, # petsc python binding + withFullDeps ? false, # full External libraries support + + # External libraries options + withHdf5 ? withFullDeps, + withMetis ? withFullDeps, + withParmetis ? false, # parmetis is unfree and should be enabled manualy + withPtscotch ? withFullDeps, + withScalapack ? withFullDeps, + withMumps ? withFullDeps, + withP4est ? withFullDeps, + + # External libraries + hdf5, + metis, + parmetis, + scotch, + scalapack, + mumps_par, + pkg-config, + p4est, }: # This version of PETSc does not support a non-MPI p4est build From 3c01afec0a69da281268e5a921c087e08c6f7222 Mon Sep 17 00:00:00 2001 From: qbisi Date: Fri, 14 Feb 2025 19:05:03 +0800 Subject: [PATCH 11/12] petsc: add hdf5 fortran binding --- pkgs/by-name/pe/petsc/package.nix | 8 ++++---- pkgs/top-level/all-packages.nix | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 9d5e412fad7b..22735cacece5 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -31,7 +31,7 @@ withP4est ? withFullDeps, # External libraries - hdf5, + hdf5-fortran-mpi, metis, parmetis, scotch, @@ -79,7 +79,7 @@ stdenv.mkDerivation rec { blas lapack ] - ++ lib.optional withHdf5 hdf5 + ++ lib.optional withHdf5 hdf5-fortran-mpi ++ lib.optional withP4est p4est ++ lib.optional withMetis metis ++ lib.optional withParmetis parmetis @@ -147,8 +147,8 @@ stdenv.mkDerivation rec { ++ lib.optionals withHdf5 [ "--with-hdf5=1" "--with-hdf5-fortran-bindings=1" - "--with-hdf5-include=${lib.getDev hdf5}/include" - "--with-hdf5-lib=[-L${lib.getLib hdf5}/lib,-lhdf5]" + "--with-hdf5-include=${lib.getDev hdf5-fortran-mpi}/include" + "--with-hdf5-lib=[-L${lib.getLib hdf5-fortran-mpi}/lib,-lhdf5]" ] ++ lib.optionals petsc-optimized [ "--with-debugging=0" diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 1144d59a2f83..f18c29a4280e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17076,7 +17076,6 @@ with pkgs; pflotran = callPackage ../by-name/pf/pflotran/package.nix { petsc = petsc.override { withHdf5 = true; - hdf5 = hdf5-fortran-mpi; petsc-optimized = true; }; }; From 120cb83d3bd82c0ade523344e6fe0e7edf2e156d Mon Sep 17 00:00:00 2001 From: qbisi Date: Fri, 14 Feb 2025 19:06:55 +0800 Subject: [PATCH 12/12] petsc: set optimized and withHdf5 default to true Petsc is commonly optimized built with hdf5 support to be used as a component of other software and project. See 1. https://sources.debian.org/src/petsc/3.22.2%2Bdfsg1-1/debian/rules/#L154 2. https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=petsc --- pkgs/by-name/pe/petsc/package.nix | 4 ++-- pkgs/top-level/all-packages.nix | 8 -------- pkgs/top-level/python-packages.nix | 1 - 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 22735cacece5..cec3dda54341 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -14,7 +14,7 @@ mpiCheckPhaseHook, # Build options - petsc-optimized ? false, + petsc-optimized ? true, petsc-scalar-type ? "real", petsc-precision ? "double", mpiSupport ? true, @@ -22,7 +22,7 @@ withFullDeps ? false, # full External libraries support # External libraries options - withHdf5 ? withFullDeps, + withHdf5 ? true, withMetis ? withFullDeps, withParmetis ? false, # parmetis is unfree and should be enabled manualy withPtscotch ? withFullDeps, diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index f18c29a4280e..77e4a06b3c69 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17072,14 +17072,6 @@ with pkgs; ### SCIENCE/PROGRAMMING - ### SCIENCE/GEOLOGY - pflotran = callPackage ../by-name/pf/pflotran/package.nix { - petsc = petsc.override { - withHdf5 = true; - petsc-optimized = true; - }; - }; - ### SCIENCE/LOGIC abella = callPackage ../applications/science/logic/abella { diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index dbabff224391..f1e9cc7f6a70 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -10347,7 +10347,6 @@ self: super: with self; { python3Packages = self; withPetsc4py = true; withFullDeps = true; - petsc-optimized = true; }); pex = callPackage ../development/python-modules/pex { };