Yann Hamdaoui 63746cac08
cudaPackages: generalize and refactor setup hook
This PR refactor CUDA setup hooks, and in particular
autoAddOpenGLRunpath and autoAddCudaCompatRunpathHook, that were using a
lot of code in common (in fact, I introduced the latter by copy pasting
most of the bash script of the former). This is not satisfying for
maintenance, as a recent patch showed, because we need to duplicate
changes to both hooks.

This commit abstract the common part in a single shell script that
applies a generic patch action to every elf file in the output. For
autoAddOpenGLRunpath the action is just addOpenGLRunpath (now
addDriverRunpath), and is few line function for
autoAddCudaCompatRunpathHook.

Doing so, we also takes the occasion to use the newer addDriverRunpath
instead of the previous addOpenGLRunpath, and rename the CUDA hook to
reflect that as well.

Co-Authored-By: Connor Baker <connor.baker@tweag.io>
2024-03-15 15:54:21 +01:00

122 lines
3.4 KiB
Nix

{ lib
, stdenv
, fetchFromGitHub
, libpng
, gzip
, fftw
, blas
, lapack
, cmake
, cudaPackages
, pkg-config
# Available list of packages can be found near here:
#
# - https://github.com/lammps/lammps/blob/develop/cmake/CMakeLists.txt#L222
# - https://docs.lammps.org/Build_extras.html
, packages ? {
ASPHERE = true;
BODY = true;
CLASS2 = true;
COLLOID = true;
COMPRESS = true;
CORESHELL = true;
DIPOLE = true;
GRANULAR = true;
KSPACE = true;
MANYBODY = true;
MC = true;
MISC = true;
MOLECULE = true;
OPT = true;
PERI = true;
QEQ = true;
REPLICA = true;
RIGID = true;
SHOCK = true;
ML-SNAP = true;
SRD = true;
REAXFF = true;
}
# Extra cmakeFlags to add as "-D${attr}=${value}"
, extraCmakeFlags ? {}
# Extra `buildInputs` - meant for packages that require more inputs
, extraBuildInputs ? []
}:
stdenv.mkDerivation (finalAttrs: {
# LAMMPS has weird versioning convention. Updates should go smoothly with:
# nix-update --commit lammps --version-regex 'stable_(.*)'
version = "2Aug2023_update3";
pname = "lammps";
src = fetchFromGitHub {
owner = "lammps";
repo = "lammps";
rev = "stable_${finalAttrs.version}";
hash = "sha256-jx0hkiYxQlnE2sa4WTvluEgphF//sNbK91VGAQJMwjw=";
};
preConfigure = ''
cd cmake
'';
nativeBuildInputs = [
cmake
pkg-config
# Although not always needed, it is needed if cmakeFlags include
# GPU_API=cuda, and it doesn't users that don't enable the GPU package.
cudaPackages.autoAddDriverRunpath
];
passthru = {
# Remove these at some point - perhaps after release 23.11. See discussion at:
# https://github.com/NixOS/nixpkgs/pull/238771#discussion_r1235459961
mpi = throw "`lammps-mpi.passthru.mpi` was removed in favor of `extraBuildInputs`";
inherit packages;
inherit extraCmakeFlags;
inherit extraBuildInputs;
};
cmakeFlags = [
]
++ (builtins.map (p: "-DPKG_${p}=ON") (builtins.attrNames (lib.filterAttrs (n: v: v) packages)))
++ (lib.mapAttrsToList (n: v: "-D${n}=${v}") extraCmakeFlags)
;
buildInputs = [
fftw
libpng
blas
lapack
gzip
] ++ extraBuildInputs
;
postInstall = ''
# For backwards compatibility
ln -s $out/bin/lmp $out/bin/lmp_serial
# Install vim and neovim plugin
install -Dm644 ../../tools/vim/lammps.vim $out/share/vim-plugins/lammps/syntax/lammps.vim
install -Dm644 ../../tools/vim/filetype.vim $out/share/vim-plugins/lammps/ftdetect/lammps.vim
mkdir -p $out/share/nvim
ln -s $out/share/vim-plugins/lammps $out/share/nvim/site
'';
meta = with lib; {
description = "Classical Molecular Dynamics simulation code";
longDescription = ''
LAMMPS is a classical molecular dynamics simulation code designed to
run efficiently on parallel computers. It was developed at Sandia
National Laboratories, a US Department of Energy facility, with
funding from the DOE. It is an open-source code, distributed freely
under the terms of the GNU Public License (GPL).
'';
homepage = "https://www.lammps.org";
license = licenses.gpl2Only;
platforms = platforms.linux;
# compiling lammps with 64 bit support blas and lapack might cause runtime
# segfaults. In anycase both blas and lapack should have the same #bits
# support.
broken = (blas.isILP64 && lapack.isILP64);
maintainers = [ maintainers.costrouc maintainers.doronbehar ];
mainProgram = "lmp";
};
})