···1+{ fetchFromGitHub, fetchurl, lib, python3Packages
2+, coreVersion ? "1.13.3" # the version of the binary espurna image to flash
3+, coreSize ? "1MB" # size of the binary image to flash
4+, coreSha256 ? "0pkb2nmml0blrfiqpc46xpjc2dw927i89k1lfyqx827wanhc704x" }:
5+6+with python3Packages;
7+8+let
9+ core = fetchurl {
10+ url = "https://github.com/xoseperez/espurna/releases/download/${coreVersion}/espurna-${coreVersion}-espurna-core-${coreSize}.bin";
11+ sha256 = coreSha256;
12+ };
13+14+in buildPythonApplication rec {
15+ name = "sonota-unstable-${version}";
16+ version = "2018-10-07";
17+18+ src = fetchFromGitHub {
19+ owner = "mirko";
20+ repo = "SonOTA";
21+ rev = "d7f4b353858aae7ac403f95475a35560fb7ffeae";
22+ sha256 = "0jd9xrhcyk8d2plbjnrlpn87536zr6n708797n0k5blf109q3c1z";
23+ };
24+25+ patches = [
26+ ./set_resource_path.patch
27+ ];
28+29+ postPatch = ''
30+ substituteInPlace sonota.py --subst-var out
31+ '';
32+33+ format = "other";
34+35+ propagatedBuildInputs = [ httplib2 netifaces tornado ];
36+37+ installPhase = ''
38+ runHook preInstall
39+40+ install -Dm755 sonota.py $out/bin/sonota
41+ install -d $out/share/sonota
42+ cp -r ssl static $out/share/sonota
43+ cp ${core} $out/share/sonota/static/image_arduino.bin
44+45+ runHook postInstall
46+ '';
47+48+ meta = with lib; {
49+ description = "Flash Itead Sonoff devices with custom firmware via original OTA mechanism";
50+ homepage = src.meta.homepage;
51+ license = licenses.gpl2;
52+ maintainers = with maintainers; [ peterhoeg ];
53+ };
54+}
+20
pkgs/tools/misc/sonota/set_resource_path.patch
···00000000000000000000
···1+diff --git a/sonota.py b/sonota.py
2+index f67128b..9f2752e 100644
3+--- a/sonota.py
4++++ b/sonota.py
5+@@ -475,14 +475,7 @@ def promptforval(msg):
6+ return val
7+8+ def resource_path(relative_path):
9+- """ Get absolute path to resource, works for dev and for PyInstaller """
10+- try:
11+- # PyInstaller creates a temp folder and stores path in _MEIPASS
12+- base_path = sys._MEIPASS
13+- except Exception:
14+- base_path = os.path.dirname(sys.argv[0])
15+-
16+- return os.path.join(base_path, relative_path)
17++ return os.path.join("@out@/share/sonota", relative_path)
18+19+ def checkargs():
20+ # Make sure all of the binary files that are needed are there