From 1b7e4d9a2b3be2b1c6a0999ec5d1eda528aad1a4 Mon Sep 17 00:00:00 2001 From: Antoine Fauroux Date: Tue, 10 Jun 2025 14:07:00 -0400 Subject: [PATCH] Overlays: Add Smoldyn (Depends on fenix) --- flake.lock | 39 +++ flake.nix | 8 +- machines/kcnhub/packages/python.nix | 2 + overlays/libsbml.nix | 56 +++++ overlays/python-packages.nix | 2 +- overlays/python.nix | 5 +- overlays/smoldyn.nix | 362 ++++++++++++++++++++++++++++ 7 files changed, 470 insertions(+), 4 deletions(-) create mode 100644 overlays/libsbml.nix create mode 100644 overlays/smoldyn.nix diff --git a/flake.lock b/flake.lock index 49c9b2e..2cda961 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,26 @@ { "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1749537578, + "narHash": "sha256-dYEEiNRw7rClQi4Y7t9jlHjbuUvSbdTdM/jXwXuaDeQ=", + "owner": "nix-community", + "repo": "fenix", + "rev": "5e3ce25aa3048f14f206a6c4fab46af6ad939482", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { @@ -87,12 +108,30 @@ }, "root": { "inputs": { + "fenix": "fenix", "nix-matlab": "nix-matlab", "nixpkgs": "nixpkgs", "nixpkgs-unstable": "nixpkgs-unstable", "sops-nix": "sops-nix" } }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1749493129, + "narHash": "sha256-nQ+gKRLXkl7gLY836ULyAwR3O0E/+vakZt78OQ+p9Fc=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "bf6d44581085bb9b6e285902a7fae77325703171", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, "sops-nix": { "inputs": { "nixpkgs": [ diff --git a/flake.nix b/flake.nix index f0de4c1..b027fd6 100644 --- a/flake.nix +++ b/flake.nix @@ -16,8 +16,12 @@ # Follow the system nixpkgs inputs.nixpkgs.follows = "nixpkgs"; }; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; - outputs = { self, nixpkgs, nixpkgs-unstable, sops-nix, nix-matlab }@attrs: let + outputs = { self, nixpkgs, nixpkgs-unstable, sops-nix, nix-matlab, ... }@attrs: let system = "x86_64-linux"; unfree-overlay = final: prev: { unfree = import nixpkgs { @@ -35,7 +39,7 @@ config.cudaSupport = true; }; }; - python-overlay = import ./overlays/python.nix; + python-overlay = import ./overlays/python.nix attrs; applyOverlays = overlays: ({...}:{ nixpkgs.overlays = overlays; }); flakes = {...}: {nix.settings.experimental-features = [ "nix-command" "flakes" ];}; in { diff --git a/machines/kcnhub/packages/python.nix b/machines/kcnhub/packages/python.nix index c0e13de..c8a67f5 100644 --- a/machines/kcnhub/packages/python.nix +++ b/machines/kcnhub/packages/python.nix @@ -45,6 +45,8 @@ spynnaker # fetching neuromorphic data: tonic + # Stochastic simulation + # smoldyn-py # Librairies to deal with mesh diff --git a/overlays/libsbml.nix b/overlays/libsbml.nix new file mode 100644 index 0000000..9fbb674 --- /dev/null +++ b/overlays/libsbml.nix @@ -0,0 +1,56 @@ +{ + lib, + stdenv, + fetchFromGitHub, + cmake, + pkg-config, + bzip2, + libxml2, + swig, + python ? null, + withPython ? false, +}: +stdenv.mkDerivation (attrs: { + pname = "libsbml"; + version = "5.20.4"; + + src = fetchFromGitHub { + owner = "sbmlteam"; + repo = "libsbml"; + rev = "v${attrs.version}"; + hash = "sha256-qWTN033YU4iWzt+mXQaP5W/6IF5nebF4PwNVkyL8wTg="; + }; + + nativeBuildInputs = [ + cmake + pkg-config + swig + ] ++ lib.optional withPython python.pkgs.pythonImportsCheckHook; + + buildInputs = [ + bzip2.dev + libxml2 + ] ++ lib.optional withPython python; + + # libSBML doesn't always make use of pkg-config + cmakeFlags = [ + "-DLIBXML_INCLUDE_DIR=${lib.getDev libxml2}/include/libxml2" + "-DLIBXML_LIBRARY=${lib.getLib libxml2}/lib/libxml2${stdenv.hostPlatform.extensions.sharedLibrary}" + "-DPKG_CONFIG_EXECUTABLE=${lib.getBin pkg-config}/bin/pkg-config" + "-DSWIG_EXECUTABLE=${lib.getBin swig}/bin/swig" + ] ++ lib.optional withPython "-DWITH_PYTHON=ON"; + + postInstall = lib.optional withPython '' + mv $out/${python.sitePackages}/libsbml/libsbml.py $out/${python.sitePackages}/libsbml/__init__.py + ''; + + pythonImportsCheck = [ "libsbml" ]; + + meta = with lib; { + description = "Library for manipulating Systems Biology Markup Language (SBML)"; + homepage = "https://github.com/sbmlteam/libsbml"; + license = licenses.lgpl21Only; + maintainers = [ maintainers.kupac ]; + platforms = platforms.all; + }; +}) diff --git a/overlays/python-packages.nix b/overlays/python-packages.nix index 811d3d5..9c01133 100644 --- a/overlays/python-packages.nix +++ b/overlays/python-packages.nix @@ -126,4 +126,4 @@ final: final-py: prev-py: { pytorch-data ]; }; -} // (import ./spynnaker.nix final final-py prev-py) +} // (import ./spynnaker.nix final final-py prev-py) #// (import ./smoldyn.nix final final-py prev-py) diff --git a/overlays/python.nix b/overlays/python.nix index 1c8d118..e843cb8 100644 --- a/overlays/python.nix +++ b/overlays/python.nix @@ -1,5 +1,8 @@ -final: prev: { +inputs: final: prev: +(inputs.fenix.overlays.default final prev) // { pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [( (import ./python-packages.nix final) )]; + + libsbml = final.callPackage ./libsbml.nix { }; } diff --git a/overlays/smoldyn.nix b/overlays/smoldyn.nix new file mode 100644 index 0000000..aaaaf63 --- /dev/null +++ b/overlays/smoldyn.nix @@ -0,0 +1,362 @@ +final: final-py: prev-py: let + rust-new = p: p.fenix.stable; + rustPlatform = final.makeRustPlatform { + inherit (rust-new final) cargo rustc; + }; + py = final-py; + + pyenv-smoldyn = py.python.withPackages (p: with p; [ + setuptools + wheel + pybind11 + pip + ]); + + smoldyn = final.fastStdenv.mkDerivation rec { + pname = "smoldyn"; + version = "2.74"; + + outputs = [ "out" "py" ]; + + env.NIX_CFLAGS_COMPILE = "-march=native -mtune=native"; + + src = final.fetchzip { + url = "https://www.smoldyn.org/smoldyn-${version}.zip"; + hash = "sha256-cKUMGgnPrHf2dNyFHmjpERgIMU0OltUZ/uhBfxpU4e4="; + }; + + nativeBuildInputs = with final; [ + cmake + ]; + + cmakeFlags = [ + "-DSMOLDYN_VERSION=${version}" + "-DOPTION_ZLIB=ON" + ]; + + buildInputs = with final; [ + libGL + libGLU + freeglut + libtiff + zlib + pyenv-smoldyn + ]; + + postInstall = '' + cp -r py $py + ''; + }; +in { + libsbml = final.libsbml.override { + python=py.python; + withPython=true; + }; + libcombine = py.buildPythonPackage rec { + pname = "libcombine"; + version = "0.2.20"; + src = final.fetchFromGitHub { + owner = "sbmlteam"; + repo = "libcombine"; + rev = "v${version}"; + fetchSubmodules = true; + hash = "sha256-9MMQr0hQLo1l8B4nlzkk48zohCohdheojRTjKrCE6og="; + }; + preBuild = '' + cd .. + cp src/bindings/python/setup.py . + ''; + nativeBuildInputs = with final; [ + swig cmake + ]; + buildInputs = with py; [ + libsbml + final.zlib + ]; + }; + libsedml = py.buildPythonPackage rec { + pname = "libsedml"; + version = "2.0.28"; + src = final.fetchFromGitHub { + owner = "fbergmann"; + repo = "libSEDML"; + rev = "v${version}"; + fetchSubmodules = true; + hash = "sha256-Pxts0kKj3BlfrwhXJjNvL936aSXiTb1cnccsW2lbUaM="; + }; + preBuild = '' + cp src/bindings/python/setup.py . + ''; + buildInputs = [ + final.cmake + ]; + }; + pyomexmeta = py.buildPythonPackage rec { + pname = "pyomexmeta"; + version = "1.2.14"; + src = final.fetchFromGitHub { + owner = "sys-bio"; + repo = "libOmexMeta"; + rev = "v${version}"; + hash = "sha256-OMCq8uR3kC5cZpFyy28A02OSiVO4b49lFyWmbCeaw6c="; + }; + }; + # https://github.com/simularium/simulariumio/blob/main/pyproject.toml + simulariumio = py.buildPythonPackage rec { + pname = "simulariumio"; + version = "1.12.0"; + + src = final.fetchFromGitHub { + owner = "simularium"; + repo = "simulariumio"; + rev = "v${version}"; + hash = "sha256-Jl7KXEXeheYJRpgVcHyK6YUzyQMafQnABlrZM9d7c9g="; + leaveDotGit = true; + }; + + format = "pyproject"; + + nativeBuildInputs = with py; [ + setuptools + setuptools_scm + wheel + ]; + + SETUPTOOLS_SCM_PRETEND_VERSION=version; + + propagatedBuildInputs = with py; [ + numpy + pandas + pint + ]; + }; + # https://github.com/biosimulators/Biosimulators_simularium + biosimulator_simularium = py.buildPythonPackage rec { + pname = "biosimulator"; + version = "0.6.3"; + + src = final.fetchFromGitHub { + owner = "biosimulators"; + repo = "biosimulators_simularium"; + rev = "v${version}"; + hash = "sha256-t0YM5Ika6Glvw3wvV71w7IHo6AovXz+7012rueEkoFw="; + }; + + format = "pyproject"; + + nativeBuildInputs = with py; [ + poetry-core + ]; + }; + biosimulator_util = py.buildPythonPackage rec { + pname = "biosimulator"; + version = "0.2.3"; + + src = final.fetchFromGitHub { + owner = "biosimulators"; + repo = "biosimulators_utils"; + rev = "${version}"; + hash = "sha256-/4HxruGpyJ6Guk4or/i+XI1JnHh2y7tWmw0AgdP5bkU="; + }; + + nativeBuildInputs = with py; [ + pip + ]; + + propagatedBuildInputs = with py; [ + capturer + pkg_utils + jsonschema + flaky + bezier + rdflib + kisao + appdirs + matplotlib + docker + cement + regex + biopython + lxml + natsort + simplejson + libcombine + libsedml + pyomexmeta + pyyaml + evalidate + ]; + doCheck = false; + }; + # https://github.com/yaroslaff/evalidate + evalidate = py.buildPythonPackage rec { + pname = "evalidate"; + version = "2.0.3"; + + format = "pyproject"; + + src = final.fetchFromGitHub { + owner = "yaroslaff"; + repo = "evalidate"; + rev = "v${version}"; + hash = "sha256-0SdGjsddX/iYeXpB9AdD7hnBH8raGHvSZ7D30a3sRXE="; + }; + + nativeBuildInputs = with py; [ + hatchling + ]; + + propagatedBuildInputs = with py; [ + uritools + ]; + }; + pkg_utils = py.buildPythonPackage rec { + pname = "pkg_utils"; + version = "0.0.5"; + + src = final.fetchFromGitHub { + owner = "KarrLab"; + repo = "pkg_utils"; + rev = "${version}"; + hash = "sha256-u6t4z1MoEkgoPkZtJuTYUbL5HyrkYthSPu9bhm8IZwo="; + }; + + nativeBuildInputs = with py; [ + pip + ]; + + propagatedBuildInputs = with py; [ + glob2 + requirements-parser + configparser + ]; + }; + pronto = py.buildPythonPackage rec { + pname = "pronto"; + version = "2.7.0"; + + src = final.fetchFromGitHub { + owner = "althonos"; + repo = "pronto"; + rev = "v${version}"; + hash = "sha256-e+Nf+0kOH8d8KU2U9imxfeP1AjY2g/oZwZmQG394cts="; + }; + + nativeBuildInputs = with py; [ + setuptools + ]; + + buildInputs = with py; [ + python-dateutil + ]; + + format = "pyproject"; + }; + kisao = py.buildPythonPackage rec { + pname = "kisao"; + version = "2.34"; + + src = final.fetchFromGitHub { + owner = "SED-ML"; + repo = "Kisao"; + rev = "${version}"; + hash = "sha256-ozL1G9ylRhQL+lUCLwb2LSjooF5P8AgiWRMOWrBrDl8="; + }; + + prePatch = '' + cd libkisao/python + ''; + + nativeBuildInputs = with py; [ + pip + ]; + + propagatedBuildInputs = with py; [ + pkg_utils + termcolor + pronto + python-dateutil + networkx + fastobo + chardet + ]; + }; + + fastobo = py.buildPythonPackage rec { + pname = "fastobo"; + version = "0.13.0"; + + src = final.fetchFromGitHub { + owner = "fastobo"; + repo = "fastobo-py"; + rev = "v${version}"; + hash = "sha256-8v9KjYX6Fy/ALFlYfSXpW40p0z54F5tpr10TAWenizk="; + }; + + cargoDeps = rustPlatform.fetchCargoTarball { + inherit src; + name = "${pname}-${version}"; + hash = "sha256-USh7WK18I8A4VdGsUAnbrSiJuBYyq4539MlyS5ANSGo="; + }; + + format = "pyproject"; + + nativeBuildInputs = [ + rustPlatform.cargoSetupHook + (rustPlatform.maturinBuildHook.override { + pkgsHostTarget = { + inherit (rust-new final.pkgsHostTarget) cargo rustc; + inherit (final.pkgsHostTarget) maturin; + }; + }) + ]; + }; + + bezier = py.buildPythonPackage rec { + pname = "bezier"; + version = "2020.2.3"; + + src = final.fetchFromGitHub { + owner = "dhermes"; + repo = "bezier"; + rev = "${version}"; + hash = "sha256-yuq2+Yy9XO2KwLlsB0IxjseG/axNBa5KuxBZ2J22ruE="; + }; + BEZIER_NO_EXTENSION="1"; + nativeBuildInputs = with py; [ + pip + ]; + buildInputs = with py; [ + pytest + matplotlib + seaborn + scipy + ]; + propagatedBuildInputs = with py; [ + numpy + sympy + ]; + }; + + smoldyn-py = py.buildPythonPackage { + pname = "smoldyn"; + version = smoldyn.version; + + src = smoldyn.py; + + postPatch = '' + sed -e '37,38d' -i setup.py + ''; + + propagatedBuildInputs = with py; [ + biosimulator_util + biosimulator_simularium + simulariumio + numpy + pandas + h5py + openpyxl + pyvista + ]; + }; +}