1{
2 lib,
3 python3Packages,
4 fetchFromGitHub,
5 fetchpatch,
6 installShellFiles,
7 git,
8 spdx-license-list-data,
9 replaceVars,
10 writableTmpDirAsHomeHook,
11}:
12
13with python3Packages;
14buildPythonApplication rec {
15 pname = "platformio";
16 version = "6.1.18";
17 pyproject = true;
18
19 # pypi tarballs don't contain tests - https://github.com/platformio/platformio-core/issues/1964
20 src = fetchFromGitHub {
21 owner = "platformio";
22 repo = "platformio-core";
23 tag = "v${version}";
24 hash = "sha256-h9/xDWXCoGHQ9r2f/ZzAtwTAs4qzDrvVAQ2kuLS9Lk8=";
25 };
26
27 outputs = [
28 "out"
29 "udev"
30 ];
31
32 patches = [
33 (replaceVars ./interpreter.patch {
34 interpreter = (python3Packages.python.withPackages (_: propagatedBuildInputs)).interpreter;
35 })
36 (replaceVars ./use-local-spdx-license-list.patch {
37 spdx_license_list_data = spdx-license-list-data.json;
38 })
39 ./missing-udev-rules-nixos.patch
40 (fetchpatch {
41 # restore PYTHONPATH when calling scons
42 # https://github.com/platformio/platformio-core/commit/097de2be98af533578671baa903a3ae825d90b94
43 url = "https://github.com/platformio/platformio-core/commit/097de2be98af533578671baa903a3ae825d90b94.patch";
44 hash = "sha256-yq+/QHCkhAkFND11MbKFiiWT3oF1cHhgWj5JkYjwuY0=";
45 revert = true;
46 })
47 ];
48
49 postPatch = ''
50 # Disable update checks at runtime
51 substituteInPlace platformio/maintenance.py --replace-fail ' check_platformio_upgrade()' ""
52
53 # Remove filterwarnings which fails on new deprecations in Python 3.12 for 3.14
54 rm tox.ini
55 '';
56
57 nativeBuildInputs = [
58 installShellFiles
59 setuptools
60 ];
61
62 pythonRelaxDeps = true;
63
64 propagatedBuildInputs =
65 [
66 aiofiles
67 ajsonrpc
68 bottle
69 click
70 click-completion
71 colorama
72 git
73 lockfile
74 marshmallow
75 pyelftools
76 pyserial
77 requests
78 semantic-version
79 setuptools
80 spdx-license-list-data.json
81 starlette
82 tabulate
83 uvicorn
84 wsproto
85 zeroconf
86 ]
87 ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
88 chardet
89 ];
90
91 preCheck = ''
92 export PATH=$PATH:$out/bin
93 '';
94
95 nativeCheckInputs = [
96 jsondiff
97 pytestCheckHook
98 writableTmpDirAsHomeHook
99 ];
100
101 # Install udev rules into a separate output so all of platformio-core is not a dependency if
102 # you want to use the udev rules on NixOS but not install platformio in your system packages.
103 postInstall = ''
104 mkdir -p $udev/lib/udev/rules.d
105 cp platformio/assets/system/99-platformio-udev.rules $udev/lib/udev/rules.d/99-platformio-udev.rules
106
107 installShellCompletion --cmd platformio \
108 --bash <(_PLATFORMIO_COMPLETE=bash_source $out/bin/platformio) \
109 --zsh <(_PLATFORMIO_COMPLETE=zsh_source $out/bin/platformio) \
110 --fish <(_PLATFORMIO_COMPLETE=fish_source $out/bin/platformio)
111
112 installShellCompletion --cmd pio \
113 --bash <(_PIO_COMPLETE=bash_source $out/bin/pio) \
114 --zsh <(_PIO_COMPLETE=zsh_source $out/bin/pio) \
115 --fish <(_PIO_COMPLETE=fish_source $out/bin/pio)
116 '';
117
118 disabledTestPaths = [
119 "tests/commands/pkg/test_install.py"
120 "tests/commands/pkg/test_list.py"
121 "tests/commands/pkg/test_outdated.py"
122 "tests/commands/pkg/test_search.py"
123 "tests/commands/pkg/test_show.py"
124 "tests/commands/pkg/test_uninstall.py"
125 "tests/commands/pkg/test_update.py"
126 "tests/commands/test_boards.py"
127 "tests/commands/test_check.py"
128 "tests/commands/test_platform.py"
129 "tests/commands/test_run.py"
130 "tests/commands/test_test.py"
131 "tests/misc/test_maintenance.py"
132 # requires internet connection
133 "tests/misc/ino2cpp/test_ino2cpp.py"
134 ];
135
136 disabledTests = [
137 # requires internet connection
138 "test_api_cache"
139 "test_ping_internet_ips"
140 "test_metadata_dump"
141 ];
142
143 pytestFlagsArray =
144 [
145 "tests"
146 ]
147 ++ (map (e: "--deselect tests/${e}") [
148 "commands/pkg/test_exec.py::test_pkg_specified"
149 "commands/pkg/test_exec.py::test_unrecognized_options"
150 "commands/test_ci.py::test_ci_boards"
151 "commands/test_ci.py::test_ci_build_dir"
152 "commands/test_ci.py::test_ci_keep_build_dir"
153 "commands/test_ci.py::test_ci_lib_and_board"
154 "commands/test_ci.py::test_ci_project_conf"
155 "commands/test_init.py::test_init_custom_framework"
156 "commands/test_init.py::test_init_duplicated_boards"
157 "commands/test_init.py::test_init_enable_auto_uploading"
158 "commands/test_init.py::test_init_ide_atom"
159 "commands/test_init.py::test_init_ide_clion"
160 "commands/test_init.py::test_init_ide_eclipse"
161 "commands/test_init.py::test_init_ide_vscode"
162 "commands/test_init.py::test_init_incorrect_board"
163 "commands/test_init.py::test_init_special_board"
164 "commands/test_lib.py::test_global_install_archive"
165 "commands/test_lib.py::test_global_install_registry"
166 "commands/test_lib.py::test_global_install_repository"
167 "commands/test_lib.py::test_global_lib_list"
168 "commands/test_lib.py::test_global_lib_uninstall"
169 "commands/test_lib.py::test_global_lib_update"
170 "commands/test_lib.py::test_global_lib_update_check"
171 "commands/test_lib.py::test_install_duplicates"
172 "commands/test_lib.py::test_lib_show"
173 "commands/test_lib.py::test_lib_stats"
174 "commands/test_lib.py::test_saving_deps"
175 "commands/test_lib.py::test_search"
176 "commands/test_lib.py::test_update"
177 "commands/test_lib_complex.py::test_global_install_archive"
178 "commands/test_lib_complex.py::test_global_install_registry"
179 "commands/test_lib_complex.py::test_global_install_repository"
180 "commands/test_lib_complex.py::test_global_lib_list"
181 "commands/test_lib_complex.py::test_global_lib_uninstall"
182 "commands/test_lib_complex.py::test_global_lib_update"
183 "commands/test_lib_complex.py::test_global_lib_update_check"
184 "commands/test_lib_complex.py::test_install_duplicates"
185 "commands/test_lib_complex.py::test_lib_show"
186 "commands/test_lib_complex.py::test_lib_stats"
187 "commands/test_lib_complex.py::test_search"
188 "package/test_manager.py::test_download"
189 "package/test_manager.py::test_install_force"
190 "package/test_manager.py::test_install_from_registry"
191 "package/test_manager.py::test_install_lib_depndencies"
192 "package/test_manager.py::test_registry"
193 "package/test_manager.py::test_uninstall"
194 "package/test_manager.py::test_update_with_metadata"
195 "package/test_manager.py::test_update_without_metadata"
196 "test_builder.py::test_build_flags"
197 "test_builder.py::test_build_unflags"
198 "test_builder.py::test_debug_custom_build_flags"
199 "test_builder.py::test_debug_default_build_flags"
200 "test_misc.py::test_api_cache"
201 "test_misc.py::test_ping_internet_ips"
202 "test_misc.py::test_platformio_cli"
203 "test_pkgmanifest.py::test_packages"
204 ]);
205
206 passthru = {
207 python = python3Packages.python;
208 };
209
210 meta = with lib; {
211 changelog = "https://github.com/platformio/platformio-core/releases/tag/${src.tag}";
212 description = "Open source ecosystem for IoT development";
213 downloadPage = "https://github.com/platformio/platformio-core";
214 homepage = "https://platformio.org";
215 license = licenses.asl20;
216 maintainers = with maintainers; [
217 mog
218 makefu
219 ];
220 mainProgram = "platformio";
221 };
222}