nixos/local/pkgs/vasp-gpu/default.nix

73 lines
2.1 KiB
Nix
Raw Normal View History

2024-02-21 16:14:39 +08:00
{
buildFHSEnv, writeScript, stdenvNoCC, requireFile, substituteAll, symlinkJoin,
2024-02-21 16:14:39 +08:00
config, cudaCapabilities ? config.cudaCapabilities, nvhpcArch ? config.nvhpcArch or "px",
nvhpc, lmod, mkl, gfortran, rsync, which, hdf5, wannier90
2024-02-21 16:14:39 +08:00
}:
2024-02-21 15:27:39 +08:00
let
2024-02-24 15:43:38 +08:00
versions =
2024-02-20 18:22:38 +08:00
{
2024-02-24 15:43:38 +08:00
# nix-store --query --hash $(nix store add-path ./vasp-6.4.0)
"6.3.1" = "1xdr5kjxz6v2li73cbx1ls5b1lnm6z16jaa4fpln7d3arnnr1mgx";
"6.4.0" = "189i1l5q33ynmps93p2mwqf5fx7p4l50sls1krqlv8ls14s3m71f";
};
buildEnv = buildFHSEnv
{
name = "buildEnv";
2024-02-23 18:29:19 +08:00
targetPkgs = pkgs: with pkgs; [ zlib ];
2024-02-20 18:22:38 +08:00
};
2024-02-21 15:27:39 +08:00
buildScript = writeScript "build"
2024-02-20 18:22:38 +08:00
''
2024-02-23 18:29:19 +08:00
. ${lmod}/share/lmod/lmod/init/bash
module use ${nvhpc}/share/nvhpc/modulefiles
2024-02-20 18:22:38 +08:00
module load nvhpc
mkdir -p bin
2024-02-21 15:27:39 +08:00
make DEPS=1 -j$NIX_BUILD_CORES
2024-02-20 18:22:38 +08:00
'';
2024-02-24 15:43:38 +08:00
include = version: substituteAll
2024-02-21 16:14:39 +08:00
{
2024-02-24 15:43:38 +08:00
src = ./makefile.include-${version};
2024-02-21 16:14:39 +08:00
cudaCapabilities = builtins.concatStringsSep "," (builtins.map
(cap: "cc${builtins.replaceStrings ["."] [""] cap}")
cudaCapabilities);
inherit nvhpcArch;
};
2024-02-24 15:43:38 +08:00
vasp = version: stdenvNoCC.mkDerivation rec
2024-02-21 15:27:39 +08:00
{
pname = "vasp";
2024-02-24 15:43:38 +08:00
inherit version;
2024-02-21 15:27:39 +08:00
src = requireFile
{
name = "${pname}-${version}";
2024-02-24 15:43:38 +08:00
sha256 = versions.${version};
2024-02-21 15:27:39 +08:00
hashMode = "recursive";
message = "Source file not found.";
};
2024-02-24 15:43:38 +08:00
configurePhase = "cp ${include version} makefile.include";
2024-02-21 15:27:39 +08:00
enableParallelBuilding = true;
buildInputs = [ mkl hdf5 wannier90 ];
nativeBuildInputs = [ gfortran rsync which ];
2024-02-23 18:29:19 +08:00
MKLROOT = "${mkl}";
HDF5_ROOT = "${hdf5}";
WANNIER90_ROOT = "${wannier90}";
2024-02-24 15:43:38 +08:00
buildPhase = "${buildEnv}/bin/buildEnv ${buildScript}";
2024-02-21 15:27:39 +08:00
installPhase =
''
2024-02-23 18:29:19 +08:00
mkdir -p $out/bin
for i in std gam ncl; do cp bin/vasp_$i $out/bin/vasp-$i; done
2024-02-21 15:27:39 +08:00
'';
};
2024-02-24 15:43:38 +08:00
startScript = version: writeScript "vasp-gpu-${version}"
2024-02-21 16:14:39 +08:00
''
2024-02-23 18:29:19 +08:00
. ${lmod}/share/lmod/lmod/init/bash
module use ${nvhpc}/share/nvhpc/modulefiles
2024-02-21 16:14:39 +08:00
module load nvhpc
exec $@
'';
2024-02-24 15:43:38 +08:00
runEnv = version: buildFHSEnv
{
name = "vasp-gpu-${version}";
targetPkgs = pkgs: with pkgs; [ zlib (vasp version) ];
runScript = startScript version;
};
in builtins.mapAttrs (version: _: runEnv version) versions