about summary refs log tree commit diff
path: root/wyze.nix
blob: 584122d5226b9fc3a72e9ed68902a4ff51e25cb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{ attrs, pkgs, ... }:

pkgs.stdenv.mkDerivation {
  name = attrs.name;
  version = attrs.version;

  src = pkgs.fetchurl {
    url = "https://download.wyzecam.com/firmware/${attrs.basePath}/${attrs.version}.zip";
    hash = attrs.hash;
  };

  phases = [
    "unpackPhase"
    "buildPhase"
  ];

  nativeBuildInputs = with pkgs; [ unzip ];

  unpackPhase = if
    pkgs.lib.hasPrefix "wco_cam_sd" attrs.version
    || pkgs.lib.hasPrefix "wco_cam_v2_sd" attrs.version
    || pkgs.lib.hasPrefix "wco_station_sd_" attrs.version
  then ''
    unzip -d $out $src
  '' else ''
    unzip -d $out $src
    gzip -d $out/*.tar.gz
  '';

  buildPhase = if
    pkgs.lib.hasPrefix "wco_cam_sd" attrs.version
    || pkgs.lib.hasPrefix "wco_cam_v2_sd" attrs.version
    || pkgs.lib.hasPrefix "wco_station_sd_" attrs.version
  then ''
    ls -l $out/sd_update
    ls -1 $out/sd_update| xargs -I {} file $out/sd_update/{} > $out/info.txt
  '' else ''
    tar -xvf $out/*.tar --directory $out
    ls -l $out/fw_file
    find $out/| xargs -I {} file $out/fw_file/{} > $out/info.txt
  '';
}