about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/physics/geant4
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/libraries/physics/geant4')
-rw-r--r--nixpkgs/pkgs/development/libraries/physics/geant4/datasets-hook.sh5
-rw-r--r--nixpkgs/pkgs/development/libraries/physics/geant4/datasets.nix119
-rw-r--r--nixpkgs/pkgs/development/libraries/physics/geant4/default.nix134
-rw-r--r--nixpkgs/pkgs/development/libraries/physics/geant4/geant4-hook.sh1
-rw-r--r--nixpkgs/pkgs/development/libraries/physics/geant4/tests.nix31
5 files changed, 290 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/libraries/physics/geant4/datasets-hook.sh b/nixpkgs/pkgs/development/libraries/physics/geant4/datasets-hook.sh
new file mode 100644
index 000000000000..8aed8b8832b3
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/physics/geant4/datasets-hook.sh
@@ -0,0 +1,5 @@
+@name@ () {
+    export G4@envvar@DATA="@datadir@"
+}
+
+postHooks+=(@name@)
diff --git a/nixpkgs/pkgs/development/libraries/physics/geant4/datasets.nix b/nixpkgs/pkgs/development/libraries/physics/geant4/datasets.nix
new file mode 100644
index 000000000000..5646f4e02bac
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/physics/geant4/datasets.nix
@@ -0,0 +1,119 @@
+{ lib, stdenv, fetchurl, geant_version }:
+
+let
+  mkDataset = { name, version, sha256, envvar }:
+    stdenv.mkDerivation {
+      inherit name version;
+      inherit geant_version;
+
+      src = fetchurl {
+        url = "https://cern.ch/geant4-data/datasets/${name}.${version}.tar.gz";
+        inherit sha256;
+      };
+
+      preferLocalBuild = true;
+      dontBuild = true;
+      dontConfigure = true;
+
+      datadir = "${placeholder "out"}/share/Geant4-${geant_version}/data/${name}${version}";
+      installPhase = ''
+        mkdir -p $datadir
+        mv ./* $datadir
+      '';
+
+      inherit envvar;
+      setupHook = ./datasets-hook.sh;
+
+      meta = with lib; {
+        description = "Data files for the Geant4 toolkit";
+        homepage = "https://geant4.web.cern.ch/support/download";
+        license = licenses.g4sl;
+        platforms = platforms.all;
+      };
+    };
+in
+  builtins.listToAttrs (map (a: { inherit (a) name; value = mkDataset a; }) [
+    {
+      name = "G4NDL";
+      version = "4.6";
+      sha256 = "022l2jjhi57frfdv9nk6s6q23gmr9zkix06fmni8gf0gmvr7qa4x";
+      envvar = "NEUTRONHP";
+    }
+
+    {
+      name = "G4EMLOW";
+      version = "7.13";
+      sha256 = "0scczd4ismvd4g3vfshbvwv92bzkdjz0ma7y21n6qxxy96v9cj1p";
+      envvar = "LE";
+    }
+
+    {
+      name = "G4PhotonEvaporation";
+      version = "5.7";
+      sha256 = "1rg7fygfxx06h98ywlci6b0b9ih74q8diygr76c3vppxdzjl47kn";
+      envvar = "LEVELGAMMA";
+    }
+
+    {
+      name = "G4RadioactiveDecay";
+      version = "5.6";
+      sha256 = "1w8d9zzc4ss7sh1f8cxv5pmrx2b74p1y26377rw9hnlfkiy0g1iq";
+      envvar = "RADIOACTIVE";
+    }
+
+    {
+      name = "G4SAIDDATA";
+      version = "2.0";
+      sha256 = "149fqy801n1pj2g6lcai2ziyvdz8cxdgbfarax6y8wdakgksh9hx";
+      envvar = "SAIDXS";
+    }
+
+    {
+      name = "G4PARTICLEXS";
+      version = "3.1";
+      sha256 = "1kg9y0kqn4lma7b0yjpgj7s9n317yqi54ydvq365qphnmm7ahka0";
+      envvar = "PARTICLEXS";
+    }
+
+    {
+      name = "G4ABLA";
+      version = "3.1";
+      sha256 = "1v97q28g1xqwnav0lwzwk7hc3b87yrmbvkgadf4bkwcbnm9b163n";
+      envvar = "ABLA";
+    }
+
+    {
+      name = "G4INCL";
+      version = "1.0";
+      sha256 = "0z9nqk125vvf4f19lhgb37jy60jf9zrjqg5zbxbd1wz93a162qbi";
+      envvar = "INCL";
+    }
+
+    {
+      name = "G4PII";
+      version = "1.3";
+      sha256 = "09p92rk1sj837m6n6yd9k9a8gkh6bby2bfn6k0f3ix3m4s8as9b2";
+      envvar = "PII";
+    }
+
+    {
+      name = "G4ENSDFSTATE";
+      version = "2.3";
+      sha256 = "00wjir59rrrlk0a12vi8rsnhyya71rdi1kmark9sp487hbhcai4l";
+      envvar = "ENSDFSTATE";
+    }
+
+    {
+      name = "G4RealSurface";
+      version = "2.2";
+      sha256 = "08382y1258ifs7nap6zaaazvabg72blr0dkqgwk32lrg07hdwm4r";
+      envvar = "REALSURFACE";
+    }
+
+    {
+      name = "G4TENDL";
+      version = "1.3.2";
+      sha256 = "0jdqmz3rz5a7yrq1mli6dj3bnmn73igf4fdxwfbl3rxywg38fa9v";
+      envvar = "PARTICLEHP";
+    }
+  ])
diff --git a/nixpkgs/pkgs/development/libraries/physics/geant4/default.nix b/nixpkgs/pkgs/development/libraries/physics/geant4/default.nix
new file mode 100644
index 000000000000..159c746fecd8
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/physics/geant4/default.nix
@@ -0,0 +1,134 @@
+{ enableMultiThreading ? true
+, enableG3toG4         ? false
+, enableInventor       ? false
+, enableGDML           ? false
+, enableQT             ? false
+, enableXM             ? false
+, enableOpenGLX11      ? true
+, enablePython         ? false
+, enableRaytracerX11   ? false
+
+# Standard build environment with cmake.
+, lib, 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
+
+# For enablePython
+, boost
+, python3
+
+# For tests
+, callPackage
+}:
+
+let
+  boost_python = boost.override { enablePython = true; python = python3; };
+in
+
+stdenv.mkDerivation rec {
+  version = "10.7.0";
+  pname = "geant4";
+
+  src = fetchurl{
+    url = "https://geant4-data.web.cern.ch/geant4-data/releases/geant4.10.07.tar.gz";
+    sha256 = "0jmdxb8z20d4l6sf2w0gk9ska48kylm38yngy3mzyvyj619a8vkp";
+  };
+
+  boost_python_lib = "python${builtins.replaceStrings ["."] [""] python3.pythonVersion}";
+  postPatch = ''
+    # Fix for boost 1.67+
+    substituteInPlace environments/g4py/CMakeLists.txt \
+      --replace "REQUIRED python" \
+                "REQUIRED COMPONENTS $boost_python_lib"
+    substituteInPlace environments/g4py/G4PythonHelpers.cmake \
+      --replace "Boost::python" "Boost::$boost_python_lib"
+  '';
+
+  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_PYTHON=${if enablePython 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"}"
+  ] ++ lib.optionals (enableMultiThreading && enablePython) [
+    "-DGEANT4_BUILD_TLS_MODEL=global-dynamic"
+  ] ++ lib.optionals enableInventor [
+    "-DINVENTOR_INCLUDE_DIR=${coin3d}/include"
+    "-DINVENTOR_LIBRARY_RELEASE=${coin3d}/lib/libCoin.so"
+  ];
+
+  nativeBuildInputs =  [ cmake ];
+
+  buildInputs = [ libGLU xlibsWrapper libXmu ]
+    ++ lib.optionals enableInventor [ libXpm coin3d soxt motif ]
+    ++ lib.optionals enablePython [ boost_python python3 ];
+
+  propagatedBuildInputs = [ clhep expat zlib libGL ]
+    ++ lib.optionals enableGDML [ xercesc ]
+    ++ lib.optionals enableXM [ motif ]
+    ++ 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 lib stdenv fetchurl;
+          geant_version = version;
+      };
+
+    tests = callPackage ./tests.nix {};
+  };
+
+  # Set the myriad of envars required by Geant4 if we use a nix-shell.
+  shellHook = ''
+    source $out/nix-support/setup-hook
+  '';
+
+  meta = with 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;
+  };
+}
diff --git a/nixpkgs/pkgs/development/libraries/physics/geant4/geant4-hook.sh b/nixpkgs/pkgs/development/libraries/physics/geant4/geant4-hook.sh
new file mode 100644
index 000000000000..0b775d432831
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/physics/geant4/geant4-hook.sh
@@ -0,0 +1 @@
+source @out@/bin/geant4.sh
diff --git a/nixpkgs/pkgs/development/libraries/physics/geant4/tests.nix b/nixpkgs/pkgs/development/libraries/physics/geant4/tests.nix
new file mode 100644
index 000000000000..83afee6089d4
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/physics/geant4/tests.nix
@@ -0,0 +1,31 @@
+{ stdenv, cmake, geant4 }:
+
+{
+  example_B1 = stdenv.mkDerivation {
+    name = "${geant4.name}-test-example_B1";
+
+    inherit (geant4) src;
+
+    nativeBuildInputs = [ cmake ];
+    buildInputs = [ geant4 ];
+    checkInputs = with geant4.data; [
+      G4EMLOW
+      G4ENSDFSTATE
+      G4PARTICLEXS
+      G4PhotonEvaporation
+    ];
+
+    prePatch = ''
+      cd examples/basic/B1
+    '';
+
+    doCheck = true;
+    checkPhase = ''
+      runHook preCheck
+
+      ./exampleB1 ../run2.mac
+
+      runHook postCheck
+    '';
+  };
+}