about summary refs log tree commit diff
path: root/nixpkgs/pkgs/by-name/pr/protonmail-bridge-gui/package.nix
blob: 2b15e67908d420496302a6a7b3c394a83e72b78d (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
102
103
104
105
106
107
108
109
110
111
112
113
{ lib
, stdenv
, pkg-config
, libsecret
, cmake
, ninja
, qt6
, grpc
, protobuf
, zlib
, gtest
, sentry-native
, protonmail-bridge
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "protonmail-bridge-gui";

  inherit (protonmail-bridge) version src;

  patches = [
    # Use `gtest` from Nixpkgs to allow an offline build
    ./use-nix-googletest.patch
  ];

  nativeBuildInputs = [
    pkg-config
    cmake
    ninja
    qt6.qtbase
    qt6.qtdeclarative
    qt6.qtwayland
    qt6.qtsvg
    qt6.wrapQtAppsHook
  ];

  buildInputs = [
    libsecret
    grpc
    protobuf
    zlib
    gtest
    sentry-native
  ];

  sourceRoot = "${finalAttrs.src.name}/internal/frontend/bridge-gui";

  postPatch = ''
    # Bypass `vcpkg` by deleting lines that `include` BridgeSetup.cmake
    find . -type f -name "CMakeLists.txt" -exec sed -i "/BridgeSetup\\.cmake/d" {} \;

    # Use the available ICU version
    sed -i "s/libicu\(i18n\|uc\|data\)\.so\.56/libicu\1.so/g" bridge-gui/DeployLinux.cmake

    # Create a Desktop Entry that uses a `protonmail-bridge-gui` binary without upstream's launcher
    sed "s/^\(Icon\|Exec\)=.*$/\1=protonmail-bridge-gui/" ../../../dist/proton-bridge.desktop > proton-bridge-gui.desktop

    # Also update `StartupWMClass` to match the GUI binary's `wmclass` (Wayland app id)
    sed -i "s/^\(StartupWMClass=\)Proton Mail Bridge$/\1ch.proton.bridge-gui/" proton-bridge-gui.desktop

    # Don't build `bridge-gui-tester`
    sed -i "/add_subdirectory(bridge-gui-tester)/d" CMakeLists.txt
  '';

  preConfigure = ''
    cmakeFlagsArray+=(
      "-DCMAKE_BUILD_TYPE=Release"
      "-DBRIDGE_APP_FULL_NAME=Proton Mail Bridge"
      "-DBRIDGE_VENDOR=Proton AG"
      "-DBRIDGE_REVISION=${finalAttrs.src.rev}"
      "-DBRIDGE_TAG=${finalAttrs.version}"
      "-DBRIDGE_BUILD_ENV=Nix"
      "-DBRIDGE_APP_VERSION=${finalAttrs.version}"
    )
  '';

  installPhase = ''
    runHook preInstall

    # Install the GUI binary
    install -Dm755 bridge-gui/bridge-gui $out/lib/bridge-gui

    # Symlink the backend binary from the protonmail-bridge (CLI) package
    ln -s ${protonmail-bridge}/bin/protonmail-bridge $out/lib/bridge

    # Symlink the GUI binary
    mkdir -p $out/bin
    ln -s $out/lib/bridge-gui $out/bin/protonmail-bridge-gui

    # Install desktop assets
    install -Dm644 ../proton-bridge-gui.desktop -t $out/share/applications
    install -Dm644 ../../../../dist/bridge.svg $out/share/icons/hicolor/scalable/apps/protonmail-bridge-gui.svg

    runHook postInstall
  '';

  meta = {
    changelog = "https://github.com/ProtonMail/proton-bridge/blob/${finalAttrs.src.rev}/Changelog.md";
    description = "Qt-based GUI to use your ProtonMail account with your local e-mail client";
    downloadPage = "https://github.com/ProtonMail/proton-bridge/releases";
    homepage = "https://github.com/ProtonMail/proton-bridge";
    license = lib.licenses.gpl3Plus;
    longDescription = ''
      Provides a GUI application that runs in the background and seamlessly encrypts
      and decrypts your mail as it enters and leaves your computer.

      To work, use secret-service freedesktop.org API (e.g. Gnome keyring) or pass.
    '';
    mainProgram = "protonmail-bridge-gui";
    maintainers = with lib.maintainers; [ daniel-fahey ];
    platforms = lib.platforms.linux;
  };
})