1{ enableMultiThreading ? true
2, enableInventor ? false
3, enableQT ? false # deprecated name
4, enableQt ? enableQT
5, enableXM ? false
6, libGLX
7, enableOpenGLX11 ? !libGLX.meta.broken
8, enablePython ? false
9, enableRaytracerX11 ? false
10
11# Standard build environment with cmake.
12, lib, stdenv, fetchurl, cmake
13
14, clhep
15, expat
16, xercesc
17, zlib
18
19# For enableQt.
20, qtbase
21, wrapQtAppsHook
22
23# For enableXM.
24, motif
25
26# For enableInventor
27, coin3d
28, soxt
29, libXpm
30
31# For enableQt, enableXM, enableOpenGLX11, enableRaytracerX11.
32, libGLU, libGL
33, libXext
34, libXmu
35
36# For enablePython
37, boost
38, python3
39
40# For tests
41, callPackage
42}:
43
44let
45 boost_python = boost.override { enablePython = true; python = python3; };
46in
47
48lib.warnIf (enableQT != false) "geant4: enableQT is deprecated, please use enableQt"
49
50stdenv.mkDerivation rec {
51 version = "11.2.2";
52 pname = "geant4";
53
54 src = fetchurl {
55 url = "https://cern.ch/geant4-data/releases/geant4-v${version}.tar.gz";
56 hash = "sha256-0k9lc1uKCgOcAPlDSZHpnvEZuGxRDQ8qshFV24KjSR0=";
57 };
58
59 # Fix broken paths in a .pc
60 postPatch = ''
61 substituteInPlace source/externals/ptl/cmake/Modules/PTLPackageConfigHelpers.cmake \
62 --replace '${"$"}{prefix}/${"$"}{PTL_INSTALL_' '${"$"}{PTL_INSTALL_'
63 '';
64
65 cmakeFlags = [
66 "-DGEANT4_INSTALL_DATA=OFF"
67 "-DGEANT4_USE_GDML=ON"
68 "-DGEANT4_USE_G3TOG4=ON"
69 "-DGEANT4_USE_QT=${if enableQt then "ON" else "OFF"}"
70 "-DGEANT4_USE_XM=${if enableXM then "ON" else "OFF"}"
71 "-DGEANT4_USE_OPENGL_X11=${if enableOpenGLX11 then "ON" else "OFF"}"
72 "-DGEANT4_USE_INVENTOR=${if enableInventor then "ON" else "OFF"}"
73 "-DGEANT4_USE_PYTHON=${if enablePython then "ON" else "OFF"}"
74 "-DGEANT4_USE_RAYTRACER_X11=${if enableRaytracerX11 then "ON" else "OFF"}"
75 "-DGEANT4_USE_SYSTEM_CLHEP=ON"
76 "-DGEANT4_USE_SYSTEM_EXPAT=ON"
77 "-DGEANT4_USE_SYSTEM_ZLIB=ON"
78 "-DGEANT4_BUILD_MULTITHREADED=${if enableMultiThreading then "ON" else "OFF"}"
79 ] ++ lib.optionals (enableOpenGLX11 && stdenv.isDarwin) [
80 "-DXQuartzGL_INCLUDE_DIR=${libGLX.dev}/include"
81 "-DXQuartzGL_gl_LIBRARY=${libGLX}/lib/libGL.dylib"
82 ] ++ lib.optionals (enableMultiThreading && enablePython) [
83 "-DGEANT4_BUILD_TLS_MODEL=global-dynamic"
84 ] ++ lib.optionals enableInventor [
85 "-DINVENTOR_INCLUDE_DIR=${coin3d}/include"
86 "-DINVENTOR_LIBRARY_RELEASE=${coin3d}/lib/libCoin.so"
87 ];
88
89 nativeBuildInputs = [
90 cmake
91 ];
92
93 propagatedNativeBuildInputs = lib.optionals enableQt [
94 wrapQtAppsHook
95 ];
96 dontWrapQtApps = true; # no binaries
97
98 buildInputs =
99 lib.optionals enableOpenGLX11 [ libGLU libXext libXmu ]
100 ++ lib.optionals enableInventor [ libXpm coin3d soxt motif ]
101 ++ lib.optionals enablePython [ boost_python python3 ];
102
103 propagatedBuildInputs = [ clhep expat xercesc zlib ]
104 ++ lib.optionals enableOpenGLX11 [ libGL ]
105 ++ lib.optionals enableXM [ motif ]
106 ++ lib.optionals enableQt [ qtbase ];
107
108 postFixup = ''
109 # Don't try to export invalid environment variables.
110 sed -i 's/export G4\([A-Z]*\)DATA/#export G4\1DATA/' "$out"/bin/geant4.sh
111 '' + lib.optionalString enableQt ''
112 wrapQtAppsHook
113 '';
114
115 setupHook = ./geant4-hook.sh;
116
117 passthru = {
118 data = callPackage ./datasets.nix {};
119
120 tests = callPackage ./tests.nix {};
121
122 inherit enableQt;
123 };
124
125 # Set the myriad of envars required by Geant4 if we use a nix-shell.
126 shellHook = ''
127 source $out/nix-support/setup-hook
128 '';
129
130 meta = with lib; {
131 broken = (stdenv.isLinux && stdenv.isAarch64);
132 description = "Toolkit for the simulation of the passage of particles through matter";
133 longDescription = ''
134 Geant4 is a toolkit for the simulation of the passage of particles through matter.
135 Its areas of application include high energy, nuclear and accelerator physics, as well as studies in medical and space science.
136 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.
137 '';
138 homepage = "http://www.geant4.org";
139 license = licenses.g4sl;
140 maintainers = with maintainers; [ omnipotententity veprbl ];
141 platforms = platforms.unix;
142 };
143}