diff options
Diffstat (limited to 'pkgs/tools/misc/esphome')
-rw-r--r-- | pkgs/tools/misc/esphome/dashboard.nix | 27 | ||||
-rw-r--r-- | pkgs/tools/misc/esphome/default.nix | 99 | ||||
-rw-r--r-- | pkgs/tools/misc/esphome/fix-src-permissions.patch | 46 |
3 files changed, 149 insertions, 23 deletions
diff --git a/pkgs/tools/misc/esphome/dashboard.nix b/pkgs/tools/misc/esphome/dashboard.nix new file mode 100644 index 00000000000..beaffadab97 --- /dev/null +++ b/pkgs/tools/misc/esphome/dashboard.nix @@ -0,0 +1,27 @@ +{ lib +, python3 +}: + +with python3.pkgs; buildPythonPackage rec { + pname = "esphome-dashboard"; + version = "20210719.0"; + + src = fetchPypi { + inherit pname version; + sha256 = "sha256-gUZut9FsFHZ0zcTg+QDIdsM3EMvNFBawgBnt/Ia1BIc="; + }; + + # no tests + doCheck = false; + + pythonImportsCheck = [ + "esphome_dashboard" + ]; + + meta = with lib; { + description = "ESPHome dashboard"; + homepage = "https://esphome.io/"; + license = with licenses; [ asl20 ]; + maintainers = with maintainers; [ hexa ]; + }; +} diff --git a/pkgs/tools/misc/esphome/default.nix b/pkgs/tools/misc/esphome/default.nix index 1160f4158b6..69a67a6e918 100644 --- a/pkgs/tools/misc/esphome/default.nix +++ b/pkgs/tools/misc/esphome/default.nix @@ -1,36 +1,68 @@ -{ lib, python3, platformio, esptool, git, protobuf3_11, fetchpatch }: +{ lib +, pkgs +, python3 +, fetchFromGitHub +, platformio +, esptool +, git +}: let python = python3.override { packageOverrides = self: super: { - protobuf = super.protobuf.override { - protobuf = protobuf3_11; - }; + esphome-dashboard = pkgs.callPackage ./dashboard.nix {}; }; }; - -in python.pkgs.buildPythonApplication rec { +in +with python.pkgs; buildPythonApplication rec { pname = "esphome"; - version = "1.14.5"; + version = "1.20.0"; - src = python.pkgs.fetchPypi { - inherit pname version; - sha256 = "176mi361677d5cqbi0hn52kky845byjs6gdad8pdhihyjgv7a9y9"; + src = fetchFromGitHub { + owner = pname; + repo = pname; + rev = "v${version}"; + sha256 = "sha256-saLcTiWqpxnE+li9ojfrEAh/vjB1c3K4kQzkrBJW3t4="; }; - ESPHOME_USE_SUBPROCESS = ""; - - propagatedBuildInputs = with python.pkgs; [ - voluptuous pyyaml paho-mqtt colorlog - tornado protobuf tzlocal pyserial ifaddr - protobuf click + patches = [ + # fix missing write permissions on src files before modifing them + ./fix-src-permissions.patch ]; - # remove all version pinning (E.g tornado==5.1.1 -> tornado) postPatch = '' - sed -i -e "s/==[0-9.]*//" setup.py + # remove all version pinning (E.g tornado==5.1.1 -> tornado) + sed -i -e "s/==[0-9.]*//" requirements.txt + + # drop coverage testing + sed -i '/--cov/d' pytest.ini ''; + # Remove esptool and platformio from requirements + ESPHOME_USE_SUBPROCESS = ""; + + # esphome has optional dependencies it does not declare, they are + # loaded when certain config blocks are used, like `font`, `image` + # or `animation`. + # They have validation functions like: + # - validate_cryptography_installed + # - validate_pillow_installed + propagatedBuildInputs = [ + click + colorama + cryptography + esphome-dashboard + ifaddr + paho-mqtt + pillow + protobuf + pyserial + pyyaml + tornado + tzlocal + voluptuous + ]; + makeWrapperArgs = [ # platformio is used in esphomeyaml/platformio_api.py # esptool is used in esphomeyaml/__main__.py @@ -39,16 +71,37 @@ in python.pkgs.buildPythonApplication rec { "--set ESPHOME_USE_SUBPROCESS ''" ]; - # Platformio will try to access the network - # Instead, run the executable - checkPhase = '' + checkInputs = [ + hypothesis + mock + pytest-asyncio + pytest-mock + pytest-sugar + pytestCheckHook + ]; + + disabledTestPaths = [ + # requires hypothesis 5.49, we have 6.x + # ImportError: cannot import name 'ip_addresses' from 'hypothesis.provisional' + "tests/unit_tests/test_core.py" + "tests/unit_tests/test_helpers.py" + ]; + + postCheck = '' $out/bin/esphome --help > /dev/null ''; + passthru = { + dashboard = esphome-dashboard; + }; + meta = with lib; { description = "Make creating custom firmwares for ESP32/ESP8266 super easy"; homepage = "https://esphome.io/"; - license = licenses.mit; - maintainers = with maintainers; [ dotlambda globin ]; + license = with licenses; [ + mit # The C++/runtime codebase of the ESPHome project (file extensions .c, .cpp, .h, .hpp, .tcc, .ino) + gpl3Only # The python codebase and all other parts of this codebase + ]; + maintainers = with maintainers; [ globin elseym hexa ]; }; } diff --git a/pkgs/tools/misc/esphome/fix-src-permissions.patch b/pkgs/tools/misc/esphome/fix-src-permissions.patch new file mode 100644 index 00000000000..5e92350105d --- /dev/null +++ b/pkgs/tools/misc/esphome/fix-src-permissions.patch @@ -0,0 +1,46 @@ +From f72c5035944065941daaa236b60664657c777726 Mon Sep 17 00:00:00 2001 +From: Martin Weinelt <hexa@darmstadt.ccc.de> +Date: Wed, 23 Jun 2021 04:50:35 +0200 +Subject: [PATCH] Set u+w for copied src files before trying to overwrite them +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +We store esphome in the nix store, which results in its file permissions +being 0444. Esphome, when compiling a firmware image, will copy these +files from the nix store to a working directory. When updating between +versions it will notice these files changed and try to copy the new +version over, which would break, because the user had no write +permissions on the files. + +❯ esphome compile 01e4ac.yml +INFO Reading configuration 01e4ac.yml... +INFO Detected timezone 'CET' with UTC offset 1 and daylight saving time from 27 March 02:00:00 to 30 October 03:00:00 +INFO Generating C++ source... +ERROR Error copying file /nix/store/lmzrgl1arqfd98jcss4rsmmy6dbffddn-esphome-1.19.2/lib/python3.8/site-packages/esphome/components/api/api_connection.cpp to 01e4ac/src/esphome/components/api/api_connection.cpp: [Errno 13] Permission denied: '01e4ac/src/esphome/components/api/api_connection.cpp' + +To fix this we modify chmod to 0644 just before esphome tries a copy +operation, which will fix permissions on existing working directories +just in time. +--- + esphome/helpers.py | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/esphome/helpers.py b/esphome/helpers.py +index ad7b8272..c456f4ff 100644 +--- a/esphome/helpers.py ++++ b/esphome/helpers.py +@@ -228,6 +228,10 @@ def copy_file_if_changed(src: os.PathLike, dst: os.PathLike) -> None: + if file_compare(src, dst): + return + mkdir_p(os.path.dirname(dst)) ++ try: ++ os.chmod(dst, 0o644) ++ except OSError: ++ pass + try: + shutil.copy(src, dst) + except OSError as err: +-- +2.31.1 + |