summary refs log tree commit diff
path: root/pkgs/applications/networking/protonmail-bridge/default.nix
blob: 3e74fbfb66af69b0d685a9150594a378fd5d1576 (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
{ stdenv, fetchurl, lib, qtbase, qtmultimedia, qtsvg, qtdeclarative, qttools, full,
  libsecret, libGL, libpulseaudio, glib, makeWrapper, makeDesktopItem }:

let
  version = "1.1.0-1";

  description = ''
    An application that runs on your computer in the background and seamlessly encrypts
    and decrypts your mail as it enters and leaves your computer.

    To work, gnome-keyring service must be enabled.
  '';

  desktopItem = makeDesktopItem {
    name = "Desktop-Bridge";
    exec = "Desktop-Bridge";
    icon = "desktop-bridge";
    comment = stdenv.lib.replaceStrings ["\n"] [" "] description;
    desktopName = "ProtonMail Bridge";
    genericName = "ProtonMail Bridge for Linux";
    categories = "Utility;Security;Network;Email";
  };
in stdenv.mkDerivation rec {
  name = "protonmail-bridge-${version}";

  src = fetchurl {
    url = "https://protonmail.com/download/protonmail-bridge_${version}_amd64.deb";
    sha256 = "0l29z208krnd3dginc203m4p5dlmnxf08vpmbm9xzlckwmswizkb";
  };

  nativeBuildInputs = [ makeWrapper ];

  sourceRoot = ".";

  unpackCmd = ''
    ar p "$src" data.tar.xz | tar xJ
  '';

  installPhase = ''
    mkdir -p $out/{bin,lib,share/applications}
    mkdir -p $out/share/{applications,icons/hicolor/scalable/apps}

    cp -r usr/lib/protonmail/bridge/Desktop-Bridge{,.sh} $out/lib
    cp usr/share/icons/protonmail/Desktop-Bridge.svg $out/share/icons/hicolor/scalable/apps/desktop-bridge.svg
    cp ${desktopItem}/share/applications/* $out/share/applications

    ln -s $out/lib/Desktop-Bridge $out/bin/Desktop-Bridge
  '';

  postFixup = let
    rpath = lib.makeLibraryPath [
      stdenv.cc.cc.lib
      qtbase
      qtmultimedia
      qtsvg
      qtdeclarative
      qttools
      libGL
      libsecret
      libpulseaudio
      glib
    ];

    qtPath = prefix: "${full}/${prefix}";
  in ''
    patchelf \
      --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
      --set-rpath "${rpath}" \
      $out/lib/Desktop-Bridge

    wrapProgram $out/lib/Desktop-Bridge \
      --set QT_PLUGIN_PATH "${qtPath qtbase.qtPluginPrefix}" \
      --set QML_IMPORT_PATH "${qtPath qtbase.qtQmlPrefix}" \
      --set QML2_IMPORT_PATH "${qtPath qtbase.qtQmlPrefix}" \
  '';

  meta = with stdenv.lib; {
    homepage = https://www.protonmail.com/bridge;
    license = licenses.mit;
    platforms = [ "x86_64-linux" ];
    maintainers = with maintainers; [ lightdiscord ];

    inherit description;
  };
}