about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Hoeg <peter@hoeg.com>2018-10-31 13:46:10 +0800
committerPeter Hoeg <peter@hoeg.com>2019-02-07 10:18:49 +0800
commit2167b4e1bf543e830488efa5991d2e9e761254f4 (patch)
tree79a0e3b35cea361abf2438c6c0341cc1588ca664
parentf2a1a4e93be2d76720a6b96532b5b003cc769312 (diff)
downloadnixlib-2167b4e1bf543e830488efa5991d2e9e761254f4.tar
nixlib-2167b4e1bf543e830488efa5991d2e9e761254f4.tar.gz
nixlib-2167b4e1bf543e830488efa5991d2e9e761254f4.tar.bz2
nixlib-2167b4e1bf543e830488efa5991d2e9e761254f4.tar.lz
nixlib-2167b4e1bf543e830488efa5991d2e9e761254f4.tar.xz
nixlib-2167b4e1bf543e830488efa5991d2e9e761254f4.tar.zst
nixlib-2167b4e1bf543e830488efa5991d2e9e761254f4.zip
sonota: init at 2018-10-07
-rw-r--r--pkgs/tools/misc/sonota/default.nix54
-rw-r--r--pkgs/tools/misc/sonota/set_resource_path.patch20
-rw-r--r--pkgs/top-level/all-packages.nix2
3 files changed, 76 insertions, 0 deletions
diff --git a/pkgs/tools/misc/sonota/default.nix b/pkgs/tools/misc/sonota/default.nix
new file mode 100644
index 000000000000..de9366d1d0ff
--- /dev/null
+++ b/pkgs/tools/misc/sonota/default.nix
@@ -0,0 +1,54 @@
+{ fetchFromGitHub, fetchurl, lib, python3Packages
+, coreVersion ? "1.13.3" # the version of the binary espurna image to flash
+, coreSize    ? "1MB"    # size of the binary image to flash
+, coreSha256  ? "0pkb2nmml0blrfiqpc46xpjc2dw927i89k1lfyqx827wanhc704x" }:
+
+with python3Packages;
+
+let
+  core = fetchurl {
+    url    = "https://github.com/xoseperez/espurna/releases/download/${coreVersion}/espurna-${coreVersion}-espurna-core-${coreSize}.bin";
+    sha256 = coreSha256;
+  };
+
+in buildPythonApplication rec {
+  name = "sonota-unstable-${version}";
+  version = "2018-10-07";
+
+  src = fetchFromGitHub {
+    owner  = "mirko";
+    repo   = "SonOTA";
+    rev    = "d7f4b353858aae7ac403f95475a35560fb7ffeae";
+    sha256 = "0jd9xrhcyk8d2plbjnrlpn87536zr6n708797n0k5blf109q3c1z";
+  };
+
+  patches = [
+    ./set_resource_path.patch
+  ];
+
+  postPatch = ''
+    substituteInPlace sonota.py --subst-var out
+  '';
+
+  format = "other";
+
+  propagatedBuildInputs = [ httplib2 netifaces tornado ];
+
+  installPhase = ''
+    runHook preInstall
+
+    install -Dm755 sonota.py $out/bin/sonota
+    install -d $out/share/sonota
+    cp -r ssl static $out/share/sonota
+    cp ${core} $out/share/sonota/static/image_arduino.bin
+
+    runHook postInstall
+  '';
+
+  meta = with lib; {
+    description = "Flash Itead Sonoff devices with custom firmware via original OTA mechanism";
+    homepage = src.meta.homepage;
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ peterhoeg ];
+  };
+}
diff --git a/pkgs/tools/misc/sonota/set_resource_path.patch b/pkgs/tools/misc/sonota/set_resource_path.patch
new file mode 100644
index 000000000000..f9a802657762
--- /dev/null
+++ b/pkgs/tools/misc/sonota/set_resource_path.patch
@@ -0,0 +1,20 @@
+diff --git a/sonota.py b/sonota.py
+index f67128b..9f2752e 100644
+--- a/sonota.py
++++ b/sonota.py
+@@ -475,14 +475,7 @@ def promptforval(msg):
+             return val
+
+ def resource_path(relative_path):
+-    """ Get absolute path to resource, works for dev and for PyInstaller """
+-    try:
+-        # PyInstaller creates a temp folder and stores path in _MEIPASS
+-        base_path = sys._MEIPASS
+-    except Exception:
+-        base_path = os.path.dirname(sys.argv[0])
+-
+-    return os.path.join(base_path, relative_path)
++    return os.path.join("@out@/share/sonota", relative_path)
+
+ def checkargs():
+     # Make sure all of the binary files that are needed are there
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index e407c9dc44e7..7ec1de059816 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -2378,6 +2378,8 @@ in
 
   s-tar = callPackage ../tools/archivers/s-tar {};
 
+  sonota = callPackage ../tools/misc/sonota { };
+
   tealdeer = callPackage ../tools/misc/tealdeer { };
 
   teamocil = callPackage ../tools/misc/teamocil { };