diff --git a/flake.nix b/flake.nix index 6cd4659b2608e4b3a57dd544e042bbbb9bc55726..d09bb706c0260f216a4e52369a3b35edb48f0c59 100644 --- a/flake.nix +++ b/flake.nix @@ -13,6 +13,9 @@ qrcodegen = python-final.callPackage nix/qrcodegen.nix { }; svgutils = python-final.callPackage nix/svgutils.nix { }; pcbnewTransition = python-final.callPackage nix/pcbnewTransition.nix { }; + + modbus-tk = python-final.callPackage nix/modbus-tk.nix { }; + pymodbus3 = python-final.callPackage nix/pymodbus3.nix { }; }) ]; other.python3Packages = self.packages.${system}.python3.pkgs; @@ -153,6 +156,7 @@ devShells.rust = with self.packages.${system}; pkgs.mkShell { packages = with pkgs; [ rustup udev.dev pkg-config openssl.dev picotool + (self.packages.${system}.python3.withPackages (p: with p; [ pymodbus3 pyserial modbus-tk ])) ]; }; } diff --git a/nix/modbus-tk.nix b/nix/modbus-tk.nix new file mode 100644 index 0000000000000000000000000000000000000000..e91b96dd0bc844cdf8a7a30dca3c583ca3aa3060 --- /dev/null +++ b/nix/modbus-tk.nix @@ -0,0 +1,24 @@ +{ lib +, buildPythonPackage +, fetchFromGitHub +, pyserial +}: + +buildPythonPackage rec { + pname = "modbus-tk"; + version = "git"; + + src = fetchFromGitHub { + owner = "ljean"; + repo = pname; + rev = "f32bb42cda8be3122fefad59a35b5c5fe6bcf567"; + hash = "sha256-wKFRi6xcStuQURJ3Lo48P0lFDfg33Zt3NLJzqvu138U="; + }; + + # Twisted asynchronous version is not supported due to a missing dependency + propagatedBuildInputs = [ + pyserial + ]; + + pythonImportsCheck = [ "modbus_tk" ]; +} \ No newline at end of file diff --git a/nix/pymodbus3.nix b/nix/pymodbus3.nix new file mode 100644 index 0000000000000000000000000000000000000000..990fc33658810ab377e4b68701f910208b7bc217 --- /dev/null +++ b/nix/pymodbus3.nix @@ -0,0 +1,73 @@ +# based on https://github.com/NixOS/nixpkgs/blob/c8a17ce7abc03c50cd072e9e6c9b389c5f61836b/pkgs/development/python-modules/pymodbus/default.nix +{ lib +, aiohttp +, asynctest +, buildPythonPackage +, click +, fetchFromGitHub +, mock +, prompt-toolkit +, pygments +, pyserial +, pyserial-asyncio +, pytestCheckHook +, redis +, sqlalchemy +, tornado +, twisted +, pytest-asyncio +, pytest-xdist +}: + +buildPythonPackage rec { + pname = "pymodbus"; + version = "3.2.2"; + + src = fetchFromGitHub { + owner = "pymodbus-dev"; + repo = pname; + rev = "v${version}"; + hash = "sha256-Hw7oGYzjcHBTBjE9vf+3D8DzXdqVuHbJmIMH0W3mwE4="; + }; + + # Twisted asynchronous version is not supported due to a missing dependency + propagatedBuildInputs = [ + aiohttp + click + prompt-toolkit + pygments + pyserial + pyserial-asyncio + tornado + ]; + + checkInputs = [ + asynctest + mock + pytestCheckHook + redis + sqlalchemy + twisted + pytest-asyncio + pytest-xdist + ]; + + pythonImportsCheck = [ "pymodbus" ]; + + # many tests fail because self.loop is None in TestAsyncioServer + #FIXME We should figure this out but that's not a priority here because we don't use async, yet. + doCheck = false; + + meta = with lib; { + description = "Python implementation of the Modbus protocol"; + longDescription = '' + Pymodbus is a full Modbus protocol implementation using twisted, + torndo or asyncio for its asynchronous communications core. It can + also be used without any third party dependencies if a more + lightweight project is needed. + ''; + homepage = "https://github.com/riptideio/pymodbus"; + license = with licenses; [ bsd3 ]; + maintainers = with maintainers; [ fab ]; + }; +}