about summary refs log tree commit diff
path: root/pkgs/by-name/re/rewind-ai/package.nix
blob: cfd1db48467157171a84e75f5e9de919f6d725f5 (plain) (blame)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{
  lib,
  stdenvNoCC,
  fetchzip,
  writeShellApplication,
  curl,
  gawk,
  xmlstarlet,
  common-updater-scripts,
}:

stdenvNoCC.mkDerivation (finalAttrs: {
  pname = "rewind-ai";
  # Example version with explanation
  # 1.5284 (Base version)
  # 15284.1 (build number)
  # dcd0176 (commit hash)
  # 20240504 (pub date)
  version = "1.5284-15284.1-dcd0176-20240504";

  src = fetchzip {
    url =
      let
        buildNumber = lib.elemAt (lib.splitString "-" finalAttrs.version) 1;
        commitHash = lib.elemAt (lib.splitString "-" finalAttrs.version) 2;
      in
      "https://updates.rewind.ai/builds/main/b${buildNumber}-main-${commitHash}.zip";
    hash = "sha256-Y7iAYHH/msZoXFzAZHJb6YoDz5fwMPHJx1kg7TqP5Gw=";
  };

  installPhase = ''
    runHook preInstall

    mkdir -p "$out/Applications/Rewind.app"
    cp -R . "$out/Applications/Rewind.app"

    runHook postInstall
  '';

  # Example response to use when modifing the script: https://pastebin.com/raw/90qU3n6H
  # There is a real harsh limit on update checks, so DO NOT send any unnecessary update checks
  # Wait at least 3 days since the last pub_date (you will find the date at the end of the version number)
  # Example: 20240504 would be 2024/05/04, and that would mean that we want to check no earlier than on 2024/05/07 for any updates
  passthru.updateScript = lib.getExe (writeShellApplication {
    name = "${finalAttrs.pname}-update-script";
    runtimeInputs = [
      curl
      gawk
      xmlstarlet
      common-updater-scripts
    ];
    text = ''
      xml_get () {
        echo "$update_xml" | xmlstarlet sel -t -v "$1"
      }

      update_url="https://updates.rewind.ai/appcasts/main.xml"

      update_xml=$(curl -s "$update_url")

      version_base=$(xml_get "/rss/channel/item/sparkle:shortVersionString")
      url=$(xml_get "/rss/channel/item/enclosure/@url")
      pub_date=$(xml_get "/rss/channel/item/pubDate")
      commit_id=$(echo "$url" | awk -F '-|\\.' '{ print $(NF - 1) }')
      build_number=$(xml_get "/rss/channel/item/sparkle:version")
      formatted_pub_date=$(date -d "$pub_date" +"%Y%m%d")

      full_version="''${version_base}-''${build_number}-''${commit_id}-''${formatted_pub_date}"
      update-source-version "rewind-ai" "$full_version" --version-key=version --file=./pkgs/by-name/re/rewind-ai/package.nix --print-changes
    '';
  });

  meta = {
    changelog = "https://www.rewind.ai/changelog";
    description = "Rewind is a personalized AI powered by everything you've seen, said, or heard";
    homepage = "https://www.rewind.ai/";
    license = lib.licenses.unfree;
    maintainers = with lib.maintainers; [ donteatoreo ];
    platforms = [ "aarch64-darwin" ];
    sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
  };
})