default.nix 1.76 KB
Newer Older
Valentin Reis's avatar
Valentin Reis committed
1
2
3
4
5
6
7
8
9
10
{ lib
, src
, bash
, stdenv
, writeText
, fetchFromGitHub
, libpng
, gzip
, fftw
, openblas
11
12
13
14
, mpiSupport ? false
, mpi ? null
, libnrm
, nrmSupport ? false
Valentin Reis's avatar
Valentin Reis committed
15
16
}:

17
18
19
20
let
  inherit (stdenv.lib) optional;
in

Valentin Reis's avatar
Valentin Reis committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
assert mpiSupport -> mpi != null;

stdenv.mkDerivation rec {
  # LAMMPS has weird versioning converted to ISO 8601 format
  version = "patch_2Aug2018";
  name = "lammps-${version}";

  lammps_packages = "asphere body class2 colloid compress coreshell dipole granular kspace manybody mc misc molecule opt peri qeq replica rigid shock snap srd user-reaxc";
  lammps_includes = "-DLAMMPS_EXCEPTIONS -DLAMMPS_GZIP -DLAMMPS_MEMALIGN=64";

  inherit src;

  #src = fetchFromGitHub {
    #owner = "lammps";
    #repo = "lammps";
    #rev = "${version}";
    #sha256 = "1ph9pr7s11wgmspmnhxa55bh1pq2cyl8iimfi62lbpbpl9pr1ilc";
  #};

  passthru = {
    inherit mpi;
  };

  buildInputs = [ fftw libpng openblas gzip bash ]
45
  ++ (optional mpiSupport [ mpi ]) ++ (optional nrmSupport libnrm);
Valentin Reis's avatar
Valentin Reis committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

  # Must do manual build due to LAMMPS requiring a seperate build for
  # the libraries and executable
  builder = writeText "builder.sh" ''
    source $stdenv/setup

    mkdir lammps
    cp -r $src/lib $src/src lammps
    chmod -R 755 lammps/src/
    cd lammps/src
    for pack in ${lammps_packages}; do make "yes-$pack" SHELL=$SHELL; done
    make mode=exe ${if mpiSupport then "mpi" else "serial"} SHELL=$SHELL LMP_INC="${lammps_includes}" FFT_PATH=-DFFT_FFTW3 FFT_LIB=-lfftw3 JPG_LIB=-lpng
    make mode=shlib ${if mpiSupport then "mpi" else "serial"} SHELL=$SHELL LMP_INC="${lammps_includes}" FFT_PATH=-DFFT_FFTW3 FFT_LIB=-lfftw3 JPG_LIB=-lpng

    mkdir -p $out/bin
    cp -v lmp_* $out/bin/

    mkdir -p $out/include
    cp -v *.h $out/include/

    mkdir -p $out/lib
    cp -v liblammps* $out/lib/
  '';
}