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 atomicwrites,
16 coloredlogs,
17 orjson,
18 home-assistant-chip-clusters,
19
20 # optionals
21 cryptography,
22 home-assistant-chip-core,
23 zeroconf,
24
25 # tests
26 aioresponses,
27 python,
28 pytest,
29 pytest-aiohttp,
30 pytest-cov-stub,
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 = "8.1.1";
60 pyproject = true;
61
62 disabled = pythonOlder "3.12";
63
64 src = fetchFromGitHub {
65 owner = "home-assistant-libs";
66 repo = "python-matter-server";
67 tag = version;
68 hash = "sha256-vTJGe6OGFM+q9+iovsQMPwkrHNg2l4pw9BFEtSA/vmA=";
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-fail 'version = "0.0.0"' 'version = "${version}"'
80 '';
81
82 build-system = [
83 setuptools
84 ];
85
86 pythonRelaxDeps = [ "home-assistant-chip-clusters" ];
87
88 dependencies = [
89 aiohttp
90 aiorun
91 atomicwrites
92 coloredlogs
93 orjson
94 home-assistant-chip-clusters
95 ];
96
97 optional-dependencies = {
98 server = [
99 cryptography
100 home-assistant-chip-core
101 zeroconf
102 ];
103 };
104
105 nativeCheckInputs = [
106 aioresponses
107 pytest-aiohttp
108 pytest-cov-stub
109 pytestCheckHook
110 ]
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 = {
127 changelog = "https://github.com/home-assistant-libs/python-matter-server/releases/tag/${src.tag}";
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 = lib.licenses.asl20;
132 teams = [ lib.teams.home-assistant ];
133 };
134}