···21 sha256 = "0bz6gkrvn7mwmjsqrazgpy9r64m5jj462v0izgvdymkx8bjd8mpi";
22 };
230000024 postPatch = ''
25 # remove all version pinning (E.g tornado==5.1.1 -> tornado)
26 sed -i -e "s/==[0-9.]*//" requirements.txt
···21 sha256 = "0bz6gkrvn7mwmjsqrazgpy9r64m5jj462v0izgvdymkx8bjd8mpi";
22 };
2324+ patches = [
25+ # fix missing write permissions on src files before modifing them
26+ ./fix-src-permissions.patch
27+ ];
28+29 postPatch = ''
30 # remove all version pinning (E.g tornado==5.1.1 -> tornado)
31 sed -i -e "s/==[0-9.]*//" requirements.txt
+46
pkgs/tools/misc/esphome/fix-src-permissions.patch
···0000000000000000000000000000000000000000000000
···1+From f72c5035944065941daaa236b60664657c777726 Mon Sep 17 00:00:00 2001
2+From: Martin Weinelt <hexa@darmstadt.ccc.de>
3+Date: Wed, 23 Jun 2021 04:50:35 +0200
4+Subject: [PATCH] Set u+w for copied src files before trying to overwrite them
5+MIME-Version: 1.0
6+Content-Type: text/plain; charset=UTF-8
7+Content-Transfer-Encoding: 8bit
8+9+We store esphome in the nix store, which results in its file permissions
10+being 0444. Esphome, when compiling a firmware image, will copy these
11+files from the nix store to a working directory. When updating between
12+versions it will notice these files changed and try to copy the new
13+version over, which would break, because the user had no write
14+permissions on the files.
15+16+❯ esphome compile 01e4ac.yml
17+INFO Reading configuration 01e4ac.yml...
18+INFO Detected timezone 'CET' with UTC offset 1 and daylight saving time from 27 March 02:00:00 to 30 October 03:00:00
19+INFO Generating C++ source...
20+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'
21+22+To fix this we modify chmod to 0644 just before esphome tries a copy
23+operation, which will fix permissions on existing working directories
24+just in time.
25+---
26+ esphome/helpers.py | 4 ++++
27+ 1 file changed, 4 insertions(+)
28+29+diff --git a/esphome/helpers.py b/esphome/helpers.py
30+index ad7b8272..c456f4ff 100644
31+--- a/esphome/helpers.py
32++++ b/esphome/helpers.py
33+@@ -228,6 +228,10 @@ def copy_file_if_changed(src: os.PathLike, dst: os.PathLike) -> None:
34+ if file_compare(src, dst):
35+ return
36+ mkdir_p(os.path.dirname(dst))
37++ try:
38++ os.chmod(dst, 0o644)
39++ except OSError:
40++ pass
41+ try:
42+ shutil.copy(src, dst)
43+ except OSError as err:
44+--
45+2.31.1
46+