From 6e2c84a05003a36964cb0c9bfcd182a2192e0561 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Thu, 6 Feb 2025 17:01:45 -0500 Subject: [PATCH] fix(esphome): add patch to fix python env --- modules/esphome-plus/default.nix | 39 +++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/modules/esphome-plus/default.nix b/modules/esphome-plus/default.nix index ed2cf724..177278bb 100644 --- a/modules/esphome-plus/default.nix +++ b/modules/esphome-plus/default.nix @@ -47,6 +47,7 @@ in { }; config = mkIf cfg.enable { + # Fixes https://github.com/NixOS/nixpkgs/issues/339557 users = { users.esphome = { isNormalUser = true; @@ -56,7 +57,42 @@ in { groups.esphome = {}; }; - # https://github.com/NixOS/nixpkgs/issues/339557 + # Fixes https://github.com/NixOS/nixpkgs/issues/370611 + nixpkgs.overlays = [ + (final: prev: { + esphome = prev.esphome.overrideAttrs (o: { + patches = [ + (builtins.toFile "post-build.patch" '' + --- a/esphome/components/esp32/post_build.py.script + +++ b/esphome/components/esp32/post_build.py.script + @@ -2,10 +2,13 @@ + + # pylint: disable=E0602 + Import("env") # noqa + +#print(env.Dump()) + + import os + import shutil + + +os.environ["PATH"] = os.path.dirname(env.get("PYTHONEXE")) + os.pathsep + os.environ["PATH"] + + + if os.environ.get("ESPHOME_USE_SUBPROCESS") is None: + try: + import esptool + @@ -63,6 +66,7 @@ def esp32_create_combined_bin(source, target, env): + esptool.main(cmd) + else: + subprocess.run(["esptool.py", *cmd]) + + #subprocess.run([env.get("PYTHONEXE"), "/var/lib/esphome/.platformio/packages/tool-esptoolpy/esptool.py", *cmd]) + + + def esp32_copy_ota_bin(source, target, env): + '') + ]; + }); + }) + ]; + systemd.services.esphome = { serviceConfig = (optionalAttrs (cfg.firmwareConfigs != {}) { @@ -94,6 +130,7 @@ in { }); }) // { + # Fixes https://github.com/NixOS/nixpkgs/issues/339557 DynamicUser = mkForce "off"; }; };