about summary refs log tree commit diff
path: root/pkgs/by-name/pr/protonmail-desktop/package.nix
blob: 2d937677045d6f84807811b2cbdd37345ab0103d (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{
  lib,
  stdenv,
  fetchurl,
  makeWrapper,
  dpkg,
  electron,
  unzip,
}:

let
  mainProgram = "proton-mail";
  srcHashes = {
    # Upstream info: It's intended to stay like this in further releases
    # https://github.com/NixOS/nixpkgs/pull/326152#discussion_r1679558135
    universal-darwin = "sha256-6b+CNCvrkIA1CvSohSJZq/veZZNsA3lyhVv5SsBlJlw=";
    x86_64-linux = "sha256-v8ufnQQEqTT5cr7fq8Fozje/NDlBzaCeKIzE6yU/biE=";
  };

in
stdenv.mkDerivation rec {
  pname = "protonmail-desktop";
  # Upstream info: "v"-prefix got dropped
  version = "1.0.6";

  src = fetchurl {
    url =
      if stdenv.isDarwin then
        "https://github.com/ProtonMail/inbox-desktop/releases/download/${version}/Proton.Mail-darwin-universal-${version}.zip"
      else
        "https://github.com/ProtonMail/inbox-desktop/releases/download/${version}/proton-mail_${version}_amd64.deb";
    sha256 =
      {
        x86_64-linux = srcHashes.x86_64-linux;
        x86_64-darwin = srcHashes.universal-darwin;
        aarch64-darwin = srcHashes.universal-darwin;
      }
      .${stdenv.hostPlatform.system} or (throw "unsupported system ${stdenv.hostPlatform.system}");
  };

  sourceRoot = lib.optionalString stdenv.isDarwin ".";

  dontConfigure = true;
  dontBuild = true;

  nativeBuildInputs = [
    makeWrapper
  ] ++ lib.optional stdenv.isLinux dpkg ++ lib.optional stdenv.isDarwin unzip;

  installPhase =
    let
      darwin = ''
        mkdir -p $out/{Applications,bin}
        cp -r "Proton Mail.app" $out/Applications/
        makeWrapper $out/Applications/"Proton Mail.app"/Contents/MacOS/Proton\ Mail $out/bin/protonmail-desktop
      '';
      linux = ''
        runHook preInstall
        mkdir -p $out
        cp -r usr/share/ $out/
        cp -r usr/lib/proton-mail/resources/app.asar $out/share/
      '';

    in
    ''
      runHook preInstall

      ${if stdenv.isDarwin then darwin else linux}

      runHook postInstall
    '';

  preFixup = lib.optionalString stdenv.isLinux ''
    makeWrapper ${lib.getExe electron} $out/bin/${mainProgram} \
      --add-flags $out/share/app.asar \
      --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \
      --set-default ELECTRON_FORCE_IS_PACKAGED 1 \
      --set-default ELECTRON_IS_DEV 0 \
      --inherit-argv0
  '';

  passthru.updateScript = ./update.sh;

  meta = {
    description = "Desktop application for Mail and Calendar, made with Electron";
    homepage = "https://github.com/ProtonMail/inbox-desktop";
    license = lib.licenses.gpl3Plus;
    maintainers = with lib.maintainers; [
      rsniezek
      sebtm
      matteopacini
    ];
    platforms = [
      "x86_64-linux"
      "x86_64-darwin"
      "aarch64-darwin"
    ];
    sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];
    inherit mainProgram;
  };
}