33 stdenv ,
44 fetchFromGitHub ,
55 mpiCheckPhaseHook ,
6+ cmake ,
67 python3 ,
78 gfortran ,
89 blas ,
910 lapack ,
11+ dbcsr ,
1012 fftw ,
1113 libint ,
1214 libvori ,
1315 libxc ,
1416 dftd4 ,
15- mctc-lib ,
16- mstore ,
17- multicharge ,
17+ simple-dftd3 ,
18+ tblite ,
1819 mpi ,
1920 gsl ,
2021 scalapack ,
3031 libvdwxc ,
3132 spla ,
3233 spfft ,
34+ trexio ,
35+ toml-f ,
36+ greenx ,
37+ gmp ,
3338 enableElpa ? false ,
3439 elpa ,
3540 cudaPackages ,
4449 "none"
4550 ) ,
4651 # Change to a value suitable for your target GPU.
47- # For AMD values see https://github.com/cp2k/cp2k/blob/master/INSTALL.md#2v-rocmhip-support-for-amd-gpu
48- # and for Nvidia see https://github.com/cp2k/cp2k/blob/master/INSTALL.md#2i-cuda-optional-improved-performance-on-gpu-systems
49- gpuVersion ? ( if gpuBackend == "cuda" then "A100" else "Mi100" ) ,
50- gpuArch ? ( if gpuBackend == "cuda" then "sm_80" else "gfx908" ) ,
52+ # see https://github.com/cp2k/cp2k/blob/master/CMakeLists.txt#L433
53+ hipTarget ? "gfx908" ,
54+ cudaTarget ? "80" ,
5155} :
5256
5357assert builtins . elem gpuBackend [
@@ -56,31 +60,30 @@ assert builtins.elem gpuBackend [
5660 "rocm"
5761] ;
5862
59- let
60- cp2kVersion = "psmp" ;
61- arch = "Linux-x86-64-gfortran" ;
62-
63- in
6463stdenv . mkDerivation rec {
6564 pname = "cp2k" ;
66- version = "2025.1 " ;
65+ version = "2025.2 " ;
6766
6867 src = fetchFromGitHub {
6968 owner = "cp2k" ;
7069 repo = "cp2k" ;
71- tag = "v${ version } " ;
72- hash = "sha256-04AFiEuv+EYubZVoYErQDdr9zipKlF7Gqy8DrUaYUMk =" ;
70+ rev = "v${ version } " ;
71+ hash = "sha256-vfl5rCoFeGtYuZ7LcsVsESjKxFbN5IYDvBSzOqsd64w =" ;
7372 fetchSubmodules = true ;
7473 } ;
7574
7675 patches = [
7776 # Remove the build command line from the source.
7877 # This avoids dependencies to .dev inputs
7978 ./remove-compiler-options.patch
79+
80+ # Fix pkg-config path generation
81+ ./pkgconfig.patch
8082 ] ;
8183
8284 nativeBuildInputs = [
8385 python3
86+ cmake
8487 which
8588 makeWrapper
8689 pkg-config
@@ -95,22 +98,26 @@ stdenv.mkDerivation rec {
9598 libvori
9699 libxc
97100 dftd4
98- mctc-lib
99- mstore
100- multicharge
101+ simple-dftd3
102+ tblite
101103 libxsmm
102104 mpi
103105 spglib
104106 scalapack
105107 blas
106108 lapack
109+ dbcsr
107110 plumed
108111 zlib
109112 hdf5-fortran
110113 sirius
111114 spla
112115 spfft
113116 libvdwxc
117+ trexio
118+ toml-f
119+ greenx
120+ gmp
114121 ]
115122 ++ lib . optional enableElpa elpa
116123 ++ lib . optionals ( gpuBackend == "cuda" ) [
@@ -129,137 +136,73 @@ stdenv.mkDerivation rec {
129136 propagatedBuildInputs = [ ( lib . getBin mpi ) ] ;
130137 propagatedUserEnvPkgs = [ mpi ] ;
131138
132- makeFlags = [
133- "ARCH=${ arch } "
134- "VERSION=${ cp2kVersion } "
135- ] ;
136-
137- doCheck = gpuBackend == "none" ;
138-
139- enableParallelBuilding = true ;
140-
141139 postPatch = ''
142140 patchShebangs tools exts/dbcsr/tools/build_utils exts/dbcsr/.cp2k
143141 substituteInPlace exts/build_dbcsr/Makefile \
144142 --replace '/usr/bin/env python3' '${ python3 } /bin/python' \
145143 --replace 'SHELL = /bin/sh' 'SHELL = bash'
146144 '' ;
147145
148- configurePhase = ''
149- runHook preConfigure
150-
151- cat > arch/${ arch } .${ cp2kVersion } << EOF
152- CC = mpicc
153- CPP =
154- FC = mpif90
155- LD = mpif90
156- AR = ar -r
157- ${ lib . strings . optionalString ( gpuBackend == "cuda" ) ''
158- OFFLOAD_CC = nvcc
159- OFFLOAD_FLAGS = -O3 -g -w --std=c++11 -arch ${ gpuArch }
160- OFFLOAD_TARGET = cuda
161- GPUVER = ${ gpuVersion }
162- CXX = mpicxx
163- CXXFLAGS = -std=c++11 -fopenmp
164- '' }
165- ${ lib . strings . optionalString ( gpuBackend == "rocm" ) ''
166- GPUVER = ${ gpuVersion }
167- OFFLOAD_CC = hipcc
168- OFFLOAD_FLAGS = -fopenmp -m64 -pthread -fPIC -D__GRID_HIP -O2 --offload-arch=${ gpuArch } --rocm-path=${ rocmPackages . rocm-core }
169- OFFLOAD_TARGET = hip
170- CXX = mpicxx
171- CXXFLAGS = -std=c++11 -fopenmp -D__HIP_PLATFORM_AMD__
172- '' }
173- DFLAGS = -D__FFTW3 -D__LIBXC -D__LIBINT -D__parallel -D__SCALAPACK \
174- -D__MPI_VERSION=3 -D__F2008 -D__LIBXSMM -D__SPGLIB \
175- -D__MAX_CONTR=4 -D__LIBVORI ${ lib . optionalString enableElpa "-D__ELPA" } \
176- -D__PLUMED2 -D__HDF5 -D__GSL -D__SIRIUS -D__LIBVDWXC -D__SPFFT -D__SPLA \
177- -D__DFTD4 \
178- ${
179- lib . strings . optionalString (
180- gpuBackend == "cuda"
181- ) "-D__OFFLOAD_CUDA -D__ACC -D__DBCSR_ACC -D__NO_OFFLOAD_PW"
182- } \
183- ${ lib . strings . optionalString (
184- gpuBackend == "rocm"
185- ) "-D__OFFLOAD_HIP -D__DBCSR_ACC -D__NO_OFFLOAD_PW" }
186- CFLAGS = -fopenmp
187- FCFLAGS = \$(DFLAGS) -O2 -ffree-form -ffree-line-length-none \
188- -ftree-vectorize -funroll-loops -msse2 \
189- -std=f2008 \
190- -fopenmp -ftree-vectorize -funroll-loops \
191- ${ lib . optionalString enableElpa "$(pkg-config --variable=fcflags elpa)" } \
192- -I${ lib . getDev libint } /include \
193- -I${ lib . getDev sirius } /include/sirius \
194- -I${ lib . getDev libxc } /include \
195- -I${ lib . getDev dftd4 } /include/dftd4 \
196- -I${ lib . getDev libxsmm } /include \
197- -I${ lib . getDev hdf5-fortran } /include \
198- -fallow-argument-mismatch
199- LIBS = -lfftw3 -lfftw3_threads \
200- -lscalapack -lblas -llapack \
201- -lxcf03 -lxc -lxsmmf -lxsmm -lsymspg \
202- -lint2 -lstdc++ -lvori \
203- -lgomp -lpthread -lm \
204- -fopenmp ${ lib . optionalString enableElpa "$(pkg-config --libs elpa)" } \
205- -lz -ldl ${ lib . optionalString ( mpi . pname == "openmpi" ) "$(mpicxx --showme:link)" } \
206- -lplumed -lhdf5_fortran -lhdf5_hl -lhdf5 -lgsl -lsirius -lspla -lspfft -lvdwxc \
207- -ldftd4 -lmstore -lmulticharge -lmctc-lib \
208- ${
209- lib . strings . optionalString ( gpuBackend == "cuda" ) ''
210- -L${ cudaPackages . cuda_cudart } /lib/stubs/ \
211- -lcudart -lnvrtc -lcuda -lcublas
212- ''
213- } \
214- ${ lib . strings . optionalString (
215- gpuBackend == "rocm"
216- ) "-lamdhip64 -lhipfft -lhipblas -lrocblas" }
217- LDFLAGS = \$(FCFLAGS) \$(LIBS)
218- include ${ plumed } /lib/plumed/src/lib/Plumed.inc
219- EOF
220-
221- runHook postConfigure
222- '' ;
146+ cmakeFlags = [
147+ ( lib . strings . cmakeBool "CP2K_USE_DFTD4" true )
148+ ( lib . strings . cmakeBool "CP2K_USE_TBLITE" true )
149+ ( lib . strings . cmakeBool "CP2K_USE_FFTW3" true )
150+ ( lib . strings . cmakeBool "CP2K_USE_HDF5" true )
151+ ( lib . strings . cmakeBool "CP2K_USE_LIBINT2" true )
152+ ( lib . strings . cmakeBool "CP2K_USE_LIBXC" true )
153+ ( lib . strings . cmakeBool "CP2K_USE_MPI" true )
154+ ( lib . strings . cmakeBool "CP2K_USE_VORI" true )
155+ ( lib . strings . cmakeBool "CP2K_USE_TREXIO" true )
156+ ( lib . strings . cmakeBool "CP2K_USE_SPGLIB" true )
157+ ( lib . strings . cmakeBool "CP2K_USE_SPLA" true )
158+ ( lib . strings . cmakeBool "CP2K_USE_LIBXSMM" true )
159+ ( lib . strings . cmakeBool "CP2K_USE_SIRIUS" true )
160+ ( lib . strings . cmakeBool "CP2K_USE_LIBVDWXC" true )
161+ ( lib . strings . cmakeBool "CP2K_USE_PLUMED" true )
162+ ( lib . strings . cmakeBool "CP2K_USE_GREENX" true )
163+ ( lib . strings . cmakeBool "CP2K_USE_ELPA" enableElpa )
164+ ( lib . strings . cmakeBool "BUILD_SHARED_LIBS" ( ! stdenv . hostPlatform . isStatic ) )
165+ ]
166+ ++ lib . optionals ( gpuBackend == "rocm" ) [
167+ ( lib . strings . cmakeFeature "CP2K_USE_ACCEL" "HIP" )
168+ ( lib . strings . cmakeFeature "CMAKE_HIP_ARCHITECTURES" hipTarget )
169+ ]
170+ ++ lib . optionals ( gpuBackend == "cuda" ) [
171+ ( lib . strings . cmakeFeature "CP2K_USE_ACCEL" "CUDA" )
172+ ( lib . strings . cmakeFeature "CMAKE_CUDA_ARCHITECTURES" cudaTarget )
173+ ] ;
223174
224175 nativeCheckInputs = [
225176 mpiCheckPhaseHook
226177 ] ;
227178
228- checkPhase = ''
229- runHook preCheck
179+ passthru = {
180+ inherit mpi ;
181+ } ;
230182
231- export CP2K_DATA_DIR=data
232- mpirun -np 2 exe/${ arch } /libcp2k_unittest.${ cp2kVersion }
183+ postInstall = ''
184+ mkdir -p $out/share/cp2k
185+ cp -r ../data/* $out/share/cp2k
233186
234- runHook postCheck
187+ for i in $out/bin/*; do
188+ wrapProgram $i \
189+ --set-default CP2K_DATA_DIR $out/share/cp2k \
190+ --set-default OMP_NUM_THREADS 1
191+ done
235192 '' ;
236193
237- installPhase = ''
238- runHook preInstall
239-
240- mkdir -p $out/bin $out/share/cp2k
194+ doInstallCheck = gpuBackend == "none" ;
241195
242- cp exe/ ${ arch } /* $out/bin
243- rm $out/bin/*_unittest.*
196+ installCheckPhase = ''
197+ runHook preInstallCheck
244198
245- for i in cp2k cp2k_shell graph; do
246- wrapProgram $out/bin/$i.${ cp2kVersion } \
247- --set-default CP2K_DATA_DIR $out/share/cp2k
199+ for TEST in $out/bin/{dbt_tas,dbt,libcp2k,parallel_rng_types,gx_ac}_unittest.psmp; do
200+ mpirun -n 2 $TEST
248201 done
249202
250- wrapProgram $out/bin/cp2k.popt \
251- --set-default CP2K_DATA_DIR $out/share/cp2k \
252- --set OMP_NUM_THREADS 1
253-
254- cp -r data/* $out/share/cp2k
255-
256- runHook postInstall
203+ runHook postInstallCheck
257204 '' ;
258205
259- passthru = {
260- inherit mpi ;
261- } ;
262-
263206 meta = {
264207 description = "Quantum chemistry and solid state physics program" ;
265208 homepage = "https://www.cp2k.org" ;
0 commit comments