1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 pythonOlder,
6 stdenvNoCC,
7 replaceVars,
8
9 # build
10 setuptools,
11
12 # dependencies
13 aiohttp,
14 aiorun,
15 async-timeout,
16 atomicwrites,
17 coloredlogs,
18 orjson,
19 home-assistant-chip-clusters,
20
21 # optionals
22 cryptography,
23 home-assistant-chip-core,
24 zeroconf,
25
26 # tests
27 aioresponses,
28 python,
29 pytest,
30 pytest-aiohttp,
31 pytestCheckHook,
32}:
33
34let
35 paaCerts = stdenvNoCC.mkDerivation rec {
36 pname = "matter-server-paa-certificates";
37 version = "1.4.0.0";
38
39 src = fetchFromGitHub {
40 owner = "project-chip";
41 repo = "connectedhomeip";
42 rev = "refs/tags/v${version}";
43 hash = "sha256-uJyStkwynPCm1B2ZdnDC6IAGlh+BKGfJW7tU4tULHFo=";
44 };
45
46 installPhase = ''
47 runHook preInstall
48
49 mkdir -p $out
50 cp $src/credentials/development/paa-root-certs/* $out/
51
52 runHook postInstall
53 '';
54 };
55in
56
57buildPythonPackage rec {
58 pname = "python-matter-server";
59 version = "7.0.1";
60 pyproject = true;
61
62 disabled = pythonOlder "3.10";
63
64 src = fetchFromGitHub {
65 owner = "home-assistant-libs";
66 repo = "python-matter-server";
67 rev = "refs/tags/${version}";
68 hash = "sha256-kwN7mLSKrxsAydp7PnN7kTvvi5zQSpXVwMh2slL6aIA=";
69 };
70
71 patches = [
72 (replaceVars ./link-paa-root-certs.patch {
73 paacerts = paaCerts;
74 })
75 ];
76
77 postPatch = ''
78 substituteInPlace pyproject.toml \
79 --replace 'version = "0.0.0"' 'version = "${version}"' \
80 --replace '--cov' ""
81 '';
82
83 build-system = [
84 setuptools
85 ];
86
87 pythonRelaxDeps = [ "home-assistant-chip-clusters" ];
88
89 dependencies = [
90 aiohttp
91 aiorun
92 async-timeout
93 atomicwrites
94 coloredlogs
95 orjson
96 home-assistant-chip-clusters
97 ];
98
99 optional-dependencies = {
100 server = [
101 cryptography
102 home-assistant-chip-core
103 zeroconf
104 ];
105 };
106
107 nativeCheckInputs = [
108 aioresponses
109 pytest-aiohttp
110 pytestCheckHook
111 ] ++ lib.flatten (lib.attrValues optional-dependencies);
112
113 preCheck =
114 let
115 pythonEnv = python.withPackages (_: dependencies ++ nativeCheckInputs ++ [ pytest ]);
116 in
117 ''
118 export PYTHONPATH=${pythonEnv}/${python.sitePackages}
119 '';
120
121 disabledTestPaths = [
122 # requires internet access
123 "tests/server/ota/test_dcl.py"
124 ];
125
126 meta = with lib; {
127 changelog = "https://github.com/home-assistant-libs/python-matter-server/releases/tag/${version}";
128 description = "Python server to interact with Matter";
129 mainProgram = "matter-server";
130 homepage = "https://github.com/home-assistant-libs/python-matter-server";
131 license = licenses.asl20;
132 teams = [ teams.home-assistant ];
133 };
134}