summary refs log tree commit diff
path: root/pkgs/development/libraries/physics/geant4/default.nix
blob: 97e8cf9c7c438b4fdd92e2d85d0d7892d319b5d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
{ enableMultiThreading ? true
, enableG3toG4         ? false
, enableInventor       ? false
, enableGDML           ? false
, enableQT             ? false
, enableXM             ? false
, enableOpenGLX11      ? true
, enableRaytracerX11   ? false

# Standard build environment with cmake.
, stdenv, fetchurl, fetchpatch, cmake

# Optional system packages, otherwise internal GEANT4 packages are used.
, clhep ? null # not packaged currently
, expat
, zlib

# For enableGDML.
, xercesc

# For enableQT.
, qtbase

# For enableXM.
, motif

# For enableInventor
, coin3d
, soxt
, libXpm

# For enableQT, enableXM, enableOpenGLX11, enableRaytracerX11.
, libGLU, libGL
, xlibsWrapper
, libXmu
}:

stdenv.mkDerivation rec {
  version = "10.6.0";
  pname = "geant4";

  src = fetchurl{
    url = "https://geant4-data.web.cern.ch/geant4-data/releases/geant4.10.06.tar.gz";
    sha256 = "169ikv2sssfbqml7bs146dj035xifxm9b12r4rzmgpvswfhca90l";
  };

  # This patch fixes crash when set -u is enabled
  patches = [
    (fetchpatch {
      name = "bash-variable-fix.patch";
      url = "https://bugzilla-geant4.kek.jp/attachment.cgi?id=606&action=diff&collapsed=&headers=1&format=raw";
      sha256 = "1bg9wg174fbqbjsjm1gz9584a7rq9p1szxr2fq9yfvqaf78289k6";
    })
  ];

  cmakeFlags = [
    "-DGEANT4_INSTALL_DATA=OFF"
    "-DGEANT4_USE_GDML=${if enableGDML then "ON" else "OFF"}"
    "-DGEANT4_USE_G3TOG4=${if enableG3toG4 then "ON" else "OFF"}"
    "-DGEANT4_USE_QT=${if enableQT then "ON" else "OFF"}"
    "-DGEANT4_USE_XM=${if enableXM then "ON" else "OFF"}"
    "-DGEANT4_USE_OPENGL_X11=${if enableOpenGLX11 then "ON" else "OFF"}"
    "-DGEANT4_USE_INVENTOR=${if enableInventor then "ON" else "OFF"}"
    "-DGEANT4_USE_RAYTRACER_X11=${if enableRaytracerX11 then "ON" else "OFF"}"
    "-DGEANT4_USE_SYSTEM_CLHEP=${if clhep != null then "ON" else "OFF"}"
    "-DGEANT4_USE_SYSTEM_EXPAT=${if expat != null then "ON" else "OFF"}"
    "-DGEANT4_USE_SYSTEM_ZLIB=${if zlib != null then "ON" else "OFF"}"
    "-DGEANT4_BUILD_MULTITHREADED=${if enableMultiThreading then "ON" else "OFF"}"
  ] ++ stdenv.lib.optionals enableInventor [
    "-DINVENTOR_INCLUDE_DIR=${coin3d}/include"
    "-DINVENTOR_LIBRARY_RELEASE=${coin3d}/lib/libCoin.so"
  ];

  enableParallelBuilding = true;
  nativeBuildInputs =  [ cmake ];

  buildInputs = [ libGLU xlibsWrapper libXmu ]
    ++ stdenv.lib.optionals enableInventor [ libXpm coin3d soxt motif ];

  propagatedBuildInputs = [ clhep expat zlib libGL ]
    ++ stdenv.lib.optionals enableGDML [ xercesc ]
    ++ stdenv.lib.optionals enableXM [ motif ]
    ++ stdenv.lib.optionals enableQT [ qtbase ];

  postFixup = ''
    # Don't try to export invalid environment variables.
    sed -i 's/export G4\([A-Z]*\)DATA/#export G4\1DATA/' "$out"/bin/geant4.sh
  '';

  setupHook = ./geant4-hook.sh;

  passthru = {
    data = import ./datasets.nix {
          inherit stdenv fetchurl;
          geant_version = version;
      };
  };

  # Set the myriad of envars required by Geant4 if we use a nix-shell.
  shellHook = ''
    source $out/nix-support/setup-hook
  '';

  meta = with stdenv.lib; {
    description = "A toolkit for the simulation of the passage of particles through matter";
    longDescription = ''
      Geant4 is a toolkit for the simulation of the passage of particles through matter.
      Its areas of application include high energy, nuclear and accelerator physics, as well as studies in medical and space science.
      The two main reference papers for Geant4 are published in Nuclear Instruments and Methods in Physics Research A 506 (2003) 250-303, and IEEE Transactions on Nuclear Science 53 No. 1 (2006) 270-278.
    '';
    homepage = http://www.geant4.org;
    license = licenses.g4sl;
    maintainers = with maintainers; [ tmplt omnipotententity ];
    platforms = platforms.linux;
  };
}