nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 aiohttp,
3 alive-progress,
4 build,
5 clang-tools,
6 click,
7 colorama,
8 coloredlogs,
9 cryptography,
10 debugpy,
11 diskcache,
12 fetchFromGitHub,
13 fetchpatch,
14 glib,
15 gn,
16 googleapis-common-protos,
17 ipython,
18 jinja2,
19 json5,
20 jsonschema,
21 lark,
22 lib,
23 libnl,
24 mobly,
25 mypy,
26 mypy-protobuf,
27 ninja,
28 openssl,
29 packaging,
30 parameterized,
31 pip-tools,
32 pkg-config,
33 pkgconfig,
34 prompt-toolkit,
35 protobuf,
36 psutil,
37 ptpython,
38 pyelftools,
39 pyfakefs,
40 pygments,
41 pykwalify,
42 pyperclip,
43 pyserial,
44 python,
45 python-daemon,
46 python-path,
47 pyyaml,
48 requests,
49 setuptools,
50 six,
51 sphinx,
52 sphinx-argparse,
53 sphinx-design,
54 stdenv,
55 tabulate,
56 tomli,
57 tornado,
58 types-pyyaml,
59 types-requests,
60 watchdog,
61 websockets,
62 zap-chip,
63}:
64
65stdenv.mkDerivation rec {
66 pname = "home-assistant-chip-wheels";
67 version = "2025.7.0";
68 src = fetchFromGitHub {
69 owner = "home-assistant-libs";
70 repo = "chip-wheels";
71 tag = version;
72 fetchSubmodules = false;
73 leaveDotGit = true;
74 hash = "sha256-SfhsM2RPghFPx0qtoHsXVymwmOWFiEGAyLx6FeB++dg=";
75 postFetch = ''
76 cd $out
77 # Download connectedhomeip.
78 git fetch
79 git reset --hard HEAD
80 git submodule update --init --depth 1 connectedhomeip
81
82 # Initialize only necessary submodules.
83 cd connectedhomeip
84 ${python.interpreter} scripts/checkout_submodules.py --platform linux --shallow
85
86 # Keep the output deterministic.
87 cd $out
88 # in case python decided to leave a .pyc file, for example
89 git clean -fxd
90 rm -rf .git/
91 '';
92 };
93
94 strictDeps = true;
95
96 nativeBuildInputs = [
97 gn
98 pkg-config
99 ninja
100 clang-tools
101 zap-chip
102 # gdbus-codegen
103 glib
104 pkgconfig
105 python
106 # dependencies of build scripts
107 click
108 jinja2
109 lark
110 python-path
111 setuptools
112 build
113 pip-tools
114 ];
115
116 propagatedBuildInputs = [
117 openssl
118 glib
119 libnl
120 ];
121
122 patches = [
123 (fetchpatch {
124 # Fix building with newer gn version
125 name = "pw_protobuf_compiler-Create-a-new-includes.txt-for-each-toolchain.patch";
126 # https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/300272
127 url = "https://pigweed.googlesource.com/pigweed/pigweed/+/b66729b90fcb9df2ee4818f6d4fff59385cdbc80^!?format=TEXT";
128 decode = "base64 -d";
129 stripLen = 1;
130 extraPrefix = "connectedhomeip/third_party/pigweed/repo/";
131 hash = "sha256-6ss3j8j69w7EMio9mFP/EL2oPqQ2sLh67eWsJjHdDa8=";
132 })
133 # fix `ModuleNotFoundError: No module named 'matter'`
134 # https://github.com/project-chip/connectedhomeip/pull/39826
135 (fetchpatch {
136 url = "https://github.com/project-chip/connectedhomeip/commit/78c6a7e15658f66658eb9f780e1a0c0c176a67d7.patch";
137 stripLen = 1;
138 extraPrefix = "connectedhomeip/";
139 hash = "sha256-s5t9DvmZVpnVelrN9+Ekn0OJl/VouXUGKCgu/PTLHBI=";
140 })
141 ];
142
143 postPatch = ''
144 cd connectedhomeip
145 export HOME=$(mktemp -d)
146
147 patchShebangs --build scripts
148
149 for patch in ../*.patch; do
150 patch -p1 < $patch
151 done
152
153 # ecdsa is insecure and only used in tests
154 patch -p1 < ${./dont-import-ecdsa.patch}
155
156 # unpin dependencies
157 # there are many files to modify, in different formats
158 sed -i 's/==.*$//' third_party/pigweed/repo/pw_env_setup/py/pw_env_setup/virtualenv_setup/python_base_requirements.txt
159 sed -i 's/==[^;]*//' scripts/setup/constraints.txt scripts/tests/requirements.txt
160 sed -i 's/\(^ \+[a-zA-Z0-9-]*\)[=~><]=[^;]*/\1/' third_party/pigweed/repo/pw_protobuf_compiler/py/setup.cfg third_party/pigweed/repo/pw_protobuf/py/setup.cfg third_party/pigweed/repo/pw_protobuf_compiler/py/setup.cfg
161 # remove a few dependencies not packaged in nixpkgs and which are apparently
162 # not needed to build the python bindings of chip
163 sed -i -e '/sphinxcontrib-mermaid/d' -e '/types-six/d' -e '/types-pygment/d' -e '/types-pyserial/d' third_party/pigweed/repo/*/py/setup.cfg
164
165 # obtained by running a build in nix-shell with internet access
166 cp ${./pigweed_environment.gni} build_overrides/pigweed_environment.gni
167
168 # some code is generated by a templating tool (zap-cli)
169 scripts/codepregen.py ./zzz_pregenerated/
170
171 # `pip._internal.exceptions.InstallationError: ''${PW_PROJECT_ROOT}/scripts/py_matter_idl is not a valid editable requirement`
172 substituteInPlace scripts/tests/requirements.txt \
173 --replace-fail '-e ''${PW_PROJECT_ROOT}/scripts/py_matter_idl' "" \
174 --replace-fail '-e ''${PW_PROJECT_ROOT}/scripts/py_matter_yamltests' ""
175 '';
176
177 # the python parts of the build system work as follows
178 # gn calls pigweed to read a dozen different files to generate
179 # a file looking like requirements.txt. It then calls pip
180 # to install this computed list of dependencies into a virtualenv.
181 # Of course, pip fails in the sandbox, because it cannot download
182 # the python packages.
183 # The documented way of doing offline builds is to create a folder
184 # with wheel files for all dependencies and point pip to it
185 # via its configuration file or environment variables.
186 # https://pigweed.dev/python_build.html#installing-offline
187 # The wheel of a python package foo is available as foo.dist.
188 # So that would be easy, but we also need wheels for transitive dependencies.
189 # the function saturateDependencies below computes this transitive closure.
190 #
191 # yes this list of dependencies contains both build tools and proper dependencies.
192 env.PIP_NO_INDEX = "1";
193 env.PIP_FIND_LINKS =
194 let
195 dependencies = [
196 aiohttp
197 alive-progress
198 colorama
199 coloredlogs
200 click
201 cryptography
202 debugpy
203 diskcache
204 googleapis-common-protos
205 ipython
206 jinja2
207 json5
208 jsonschema
209 lark
210 mobly
211 mypy
212 mypy-protobuf
213 packaging
214 parameterized
215 pkgconfig
216 prompt-toolkit
217 protobuf
218 psutil
219 ptpython
220 pyfakefs
221 pyelftools
222 pygments
223 pykwalify
224 pyperclip
225 pyserial
226 python-daemon
227 python-path
228 pyyaml
229 requests
230 six
231 sphinx
232 sphinx-argparse
233 sphinx-design
234 tabulate
235 tomli
236 tornado
237 types-pyyaml
238 types-requests
239 watchdog
240 websockets
241 ];
242 filterNull = list: lib.filter (dep: dep != null) list;
243 toItem = dep: {
244 inherit dep;
245 key = dep.name;
246 };
247 saturatedDependencies = lib.genericClosure {
248 startSet = map toItem (filterNull dependencies);
249 operator = item: map toItem (filterNull ((item.dep).propagatedBuildInputs or [ ]));
250 };
251 saturatedDependencyList = lib.filter (dep: dep ? dist && dep != null) (
252 map (item: item.dep) saturatedDependencies
253 );
254 in
255 lib.concatMapStringsSep " " (dep: "file://${dep.dist}") saturatedDependencyList;
256
257 gnFlags = [
258 ''chip_project_config_include_dirs=["//.."]''
259 ''chip_crypto="openssl"''
260 "enable_rtti=true"
261 "chip_config_memory_debug_checks=false"
262 "chip_config_memory_debug_dmalloc=false"
263 ''chip_mdns="minimal"''
264 ''chip_minmdns_default_policy="libnl"''
265 ''chip_python_version="${lib.versions.majorMinor python.version}"''
266 ''chip_python_platform_tag="any"''
267 ''chip_python_package_prefix="home-assistant-chip"''
268 ''custom_toolchain="custom"''
269 ''target_cc="${stdenv.cc.targetPrefix}cc"''
270 ''target_cxx="${stdenv.cc.targetPrefix}c++"''
271 ''target_ar="${stdenv.cc.targetPrefix}ar"''
272 ];
273
274 preBuild = ''
275 export NIX_CFLAGS_COMPILE="$($PKG_CONFIG --cflags glib-2.0) -O2 -Wno-error"
276 export NIX_CFLAGS_LINK="$($PKG_CONFIG --libs gio-2.0) $($PKG_CONFIG --libs gobject-2.0) $($PKG_CONFIG --libs glib-2.0)"
277 '';
278
279 ninjaFlags = [ "chip-repl" ];
280
281 installPhase = ''
282 runHook preInstall
283
284 cp -r controller/python $out
285
286 runHook postInstall
287 '';
288
289 meta = {
290 description = "Python wheels for APIs and tools related to CHIP";
291 homepage = "https://github.com/home-assistant-libs/chip-wheels";
292 changelog = "https://github.com/home-assistant-libs/chip-wheels/releases/tag/${src.tag}";
293 license = lib.licenses.asl20;
294 teams = [ lib.teams.home-assistant ];
295 };
296
297}