diff --git a/pkgs/development/python-modules/uxsim/add-qt-plugin-path-to-env.patch b/pkgs/development/python-modules/uxsim/add-qt-plugin-path-to-env.patch new file mode 100644 index 000000000000..42f001085d05 --- /dev/null +++ b/pkgs/development/python-modules/uxsim/add-qt-plugin-path-to-env.patch @@ -0,0 +1,24 @@ +diff --git a/uxsim/__init__.py b/uxsim/__init__.py +index 01e1ad1..de1f0fd 100644 +--- a/uxsim/__init__.py ++++ b/uxsim/__init__.py +@@ -1,8 +1,14 @@ +-from .uxsim import * +-from .utils import * ++import os ++ + from .analyzer import * ++from .utils import * ++from .uxsim import * ++ ++# Only set our own plugin path if it's not already set ++if not os.getenv("QT_PLUGIN_PATH"): ++ os.environ["QT_PLUGIN_PATH"] = "$NIX_QT_PLUGIN_PATH" + + __version__ = "1.1.1" + __author__ = "Toru Seo" + __copyright__ = "Copyright (c) 2023 Toru Seo" +-__license__ = "MIT License" +\ No newline at end of file ++__license__ = "MIT License" + diff --git a/pkgs/development/python-modules/uxsim/default.nix b/pkgs/development/python-modules/uxsim/default.nix new file mode 100644 index 000000000000..e08eec1d6cf6 --- /dev/null +++ b/pkgs/development/python-modules/uxsim/default.nix @@ -0,0 +1,69 @@ +{ + lib, + buildPythonPackage, + fetchFromGitHub, + setuptools, + wheel, + qt5, + hackgen-font, + python3, + matplotlib, + numpy, + pandas, + pillow, + pyqt5, + scipy, + tqdm, +}: +buildPythonPackage rec { + pname = "uxsim"; + version = "1.1.1"; + pyproject = true; + + src = fetchFromGitHub { + owner = "toruseo"; + repo = "UXsim"; + rev = "v${version}"; + hash = "sha256-qPAFodvx+Z7RsRhzdTq1TRsbvrUFaqRJZxYg3FM6q8A="; + }; + + patches = [ + ./add-qt-plugin-path-to-env.patch + ]; + + nativeBuildInputs = [ + setuptools + wheel + ]; + + propagatedBuildInputs = [ + matplotlib + numpy + pandas + pillow + pyqt5 + scipy + tqdm + ]; + + pythonImportsCheck = ["uxsim"]; + + + # QT_PLUGIN_PATH is required to be set for the program to produce its images + # our patch sets it to $NIX_QT_PLUGIN_PATH if QT_PLUGIN_PATH is not set + # and here we replace this string with the actual path to qt plugins + postInstall = '' + substituteInPlace $out/${python3.sitePackages}/uxsim/__init__.py \ + --replace-fail '$NIX_QT_PLUGIN_PATH' '${qt5.qtbase.bin}/${qt5.qtbase.qtPluginPrefix}' + + mkdir -p $out/${python3.sitePackages}/uxsim/files + ln -s ${hackgen-font}/share/fonts/hackgen/HackGen-Regular.ttf $out/${python3.sitePackages}/uxsim/files/ + ''; + + meta = with lib; { + description = "Vehicular traffic flow simulator in road network, written in pure Python"; + homepage = "https://github.com/toruseo/UXsim"; + license = licenses.mit; + maintainers = with maintainers; [vinnymeller]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 606734fba3b2..63f1f75ab3df 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -16586,6 +16586,8 @@ self: super: with self; { inherit (pkgs.darwin.apple_sdk.frameworks) ApplicationServices CoreServices; }; + uxsim = callPackage ../development/python-modules/uxsim { }; + vaa = callPackage ../development/python-modules/vaa { }; vacuum-map-parser-base = callPackage ../development/python-modules/vacuum-map-parser-base { };