···11+{ fetchFromGitHub, fetchurl, lib, python3Packages
22+, coreVersion ? "1.13.3" # the version of the binary espurna image to flash
33+, coreSize ? "1MB" # size of the binary image to flash
44+, coreSha256 ? "0pkb2nmml0blrfiqpc46xpjc2dw927i89k1lfyqx827wanhc704x" }:
55+66+with python3Packages;
77+88+let
99+ core = fetchurl {
1010+ url = "https://github.com/xoseperez/espurna/releases/download/${coreVersion}/espurna-${coreVersion}-espurna-core-${coreSize}.bin";
1111+ sha256 = coreSha256;
1212+ };
1313+1414+in buildPythonApplication rec {
1515+ name = "sonota-unstable-${version}";
1616+ version = "2018-10-07";
1717+1818+ src = fetchFromGitHub {
1919+ owner = "mirko";
2020+ repo = "SonOTA";
2121+ rev = "d7f4b353858aae7ac403f95475a35560fb7ffeae";
2222+ sha256 = "0jd9xrhcyk8d2plbjnrlpn87536zr6n708797n0k5blf109q3c1z";
2323+ };
2424+2525+ patches = [
2626+ ./set_resource_path.patch
2727+ ];
2828+2929+ postPatch = ''
3030+ substituteInPlace sonota.py --subst-var out
3131+ '';
3232+3333+ format = "other";
3434+3535+ propagatedBuildInputs = [ httplib2 netifaces tornado ];
3636+3737+ installPhase = ''
3838+ runHook preInstall
3939+4040+ install -Dm755 sonota.py $out/bin/sonota
4141+ install -d $out/share/sonota
4242+ cp -r ssl static $out/share/sonota
4343+ cp ${core} $out/share/sonota/static/image_arduino.bin
4444+4545+ runHook postInstall
4646+ '';
4747+4848+ meta = with lib; {
4949+ description = "Flash Itead Sonoff devices with custom firmware via original OTA mechanism";
5050+ homepage = src.meta.homepage;
5151+ license = licenses.gpl2;
5252+ maintainers = with maintainers; [ peterhoeg ];
5353+ };
5454+}
+20
pkgs/tools/misc/sonota/set_resource_path.patch
···11+diff --git a/sonota.py b/sonota.py
22+index f67128b..9f2752e 100644
33+--- a/sonota.py
44++++ b/sonota.py
55+@@ -475,14 +475,7 @@ def promptforval(msg):
66+ return val
77+88+ def resource_path(relative_path):
99+- """ Get absolute path to resource, works for dev and for PyInstaller """
1010+- try:
1111+- # PyInstaller creates a temp folder and stores path in _MEIPASS
1212+- base_path = sys._MEIPASS
1313+- except Exception:
1414+- base_path = os.path.dirname(sys.argv[0])
1515+-
1616+- return os.path.join(base_path, relative_path)
1717++ return os.path.join("@out@/share/sonota", relative_path)
1818+1919+ def checkargs():
2020+ # Make sure all of the binary files that are needed are there