Unverified Commit 5f3f3867 authored by toonn's avatar toonn Committed by GitHub
Browse files

wire-desktop: build from source (#499529)

parents 095af0b5 d82df552
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -14476,6 +14476,12 @@
    githubId = 913109;
    name = "Emil Fresk";
  };
  korkutkardes7 = {
    email = "korkutkardes7@hotmail.com";
    github = "KorkutKardes7";
    githubId = 148012191;
    name = "Korkut Kardeşseven";
  };
  kornholi = {
    email = "kornholijo@gmail.com";
    github = "kornholi";
+10 −0
Original line number Diff line number Diff line
--- a/bin/build-tools/lib/build-linux.ts	2026-03-14 16:55:05.607020706 +0300
+++ b/bin/build-tools/lib/build-linux.ts	2026-03-14 16:56:36.314018156 +0300
@@ -115,6 +115,7 @@
       ...platformSpecificConfig,
       depends: rpmDepends,
     },
+    electronDist: "node_modules/electron-dist",
   };
 
   return {builderConfig, linuxConfig};
+10 −0
Original line number Diff line number Diff line
--- a/bin/build-tools/lib/build-macos.ts	2026-03-14 19:53:19.400997490 +0300
+++ b/bin/build-tools/lib/build-macos.ts	2026-03-14 19:53:21.919315580 +0300
@@ -98,6 +98,7 @@
     protocols: [{name: `${commonConfig.name} Core Protocol`, schemes: [commonConfig.customProtocolName]}],
     prune: true,
     quiet: false,
+    electronZipDir: "node_modules/electron-dist",
   };
 
   if (macOSConfig.electronMirror) {
+23 −0
Original line number Diff line number Diff line
{
  "@unrs/resolver-binding-android-arm-eabi@npm:1.11.1": "61ec7f4f3602cda87a24701f7d9904b13eb7d0b579ef7033455541d5a7b13a7868557d3df962b0dc3b84db442e9b829c54355d7ead6d0bf078f2660f10779511",
  "@unrs/resolver-binding-android-arm64@npm:1.11.1": "98af481a2ff7ef2a88dff7117085c4aa16f522d9a069cc1111c0c01a849fe1752de5a6d846fbd5d6b143b7962831edb929f4a2e71fa60ffa8354bc605a5361d9",
  "@unrs/resolver-binding-darwin-arm64@npm:1.11.1": "cdd8a50fa3d09e19a3f28f02bd06735948aa2839806d9771f9be4531ee25aba5f673d561d33c9390aece4bdde9f81f6b79f51127f60df32513f35436e2ce227e",
  "@unrs/resolver-binding-darwin-x64@npm:1.11.1": "d89ca565eb69b5b9709f1978402a4ae1b83613764e946db35340c3c3ea229c7fb3754a3da169e79a8dc0e552765690ccb62209b17160d1f7d524dca47e36f2f3",
  "@unrs/resolver-binding-freebsd-x64@npm:1.11.1": "0b8679c0d7136d7421cb13302311db2fc7e7770d605726814b257e6f03979004ad3e546947d8be159059946c91fa88eef4371e0ab1539453092b1a02491f63db",
  "@unrs/resolver-binding-linux-arm-gnueabihf@npm:1.11.1": "003aa1bd9c950d8b2547e21610cb40bf1cd81e5fd50d8e2bfdcebca9c1c14f902b2d83315cf27415d99a0c35921b9feb3be99ff9cf0e05342b66ec7f2e9cc7cb",
  "@unrs/resolver-binding-linux-arm-musleabihf@npm:1.11.1": "0f9a66eaffbda26a53f1ad958e02e651cf2e35c3d9e4d8dca794dcdb57312b528dc5aef5419c6a8537bc97cc569e5d4d64673620523279c00648c90359befe1d",
  "@unrs/resolver-binding-linux-arm64-gnu@npm:1.11.1": "4e57baf96705e1a690e43a0a62da074a2245b5b17d60339230aa974a35d7c1e7160bde4ac700d7b9b8a5a535ec733675b6c50876310a2e66222b395ac3977305",
  "@unrs/resolver-binding-linux-arm64-musl@npm:1.11.1": "772327066fdf6f457b27a71f1b58b348c829b29053154320980e63a67b8d53b18c342b699f6fffce9f0626cbe93a86e367e0b614581fb875c1897d281381c732",
  "@unrs/resolver-binding-linux-ppc64-gnu@npm:1.11.1": "60f7876213b834ae92d03d0ab20e914f428d5e9167ef65571061e5921d9dd09e6cc90e02d9394d6e34f645605731f2d7cdc997239b4e33d1799352ce673451f9",
  "@unrs/resolver-binding-linux-riscv64-gnu@npm:1.11.1": "a947ec594e963273c05352cf1b140da0202ec3f6c6b2bcbb51401b2032fde3298677ec985b3b76640ec21ae2a83ab186290e2e89cb559bffe6e23e069b83dc1a",
  "@unrs/resolver-binding-linux-riscv64-musl@npm:1.11.1": "46e462d52b0f064beecc6b3015a4e450e2227da971dab34cb02557756dc082253aec04da64a1e39fa72f4fc1b40779b4964594c702a2dc57728e83ac87ae632d",
  "@unrs/resolver-binding-linux-s390x-gnu@npm:1.11.1": "1f0fc98eb80152dc1d81a02eaccefdb4d613992a11d1d584298a4045390534a83ab07f3b25429f5e83ab97c9645491021950960961478da17d1275b071c335e1",
  "@unrs/resolver-binding-linux-x64-gnu@npm:1.11.1": "bddb12a68a6ae78ff036c8403299b31a4a6b8cd87d04ae72197be13dcef9561cf2ae2e5f6727c19ad038c025a57229c8759a6a4ea3ac2c05cc950da62adbb7d1",
  "@unrs/resolver-binding-linux-x64-musl@npm:1.11.1": "1b00602cce9d99d8f35d1eb6447f14b6a38c0b4bc39807c738c7a0fd64763145d3079adbdcb5b6f0793e5056af636746ef53bbc5ae1f5d300fdf682deb43e887",
  "@unrs/resolver-binding-wasm32-wasi@npm:1.11.1": "f0b1d5ef2066690fa9987ee47d156b459cf597945e9f0f4b8ae46d0aa8d5ff9693aeb73b302f21b90fde29ed4cedfcbcb19376ad7f1e1f2baf56e9267b9bec67",
  "@unrs/resolver-binding-win32-arm64-msvc@npm:1.11.1": "6a00804da3a6388259b15e28ed276367767325ccd08e8f9c6ea0baf8c7cea8d709c4fea9005853fa0024577947d0819e8e41031505b4af6ddbfba4ad98a0ec47",
  "@unrs/resolver-binding-win32-ia32-msvc@npm:1.11.1": "68df9e7db0f0253a77d1ac09794e89f47db0878f329f5d079a2f5a73c4200c7b3e5b42c5a6d36eece4372aafb6d8c0f25c632c1c2beee75ef62fa6e204ea2232",
  "@unrs/resolver-binding-win32-x64-msvc@npm:1.11.1": "0fd962a79572c3a47533acd2bba2274583a9d6905d62f4927177c48525b91a3ad67ea680cb9e89bd1802c71cd65a414fc8d11937dad33f6fbf83013eb435acd6",
  "dmg-license@npm:1.0.11": "be760b0fc5bb36a31ad623597e8c883eee85a2a775107892354b1fb8fd11fba7bf6c2c0e96bb6c43a8f27a448bd4188d6073dbc4c0f53034f42f05660c4571ee",
  "iconv-corefoundation@npm:1.1.7": "e9456c1ece923480330e2de94c214afa04ef28b72bc9e982ada8c2fdad270a0e6af99cccb303f87406dde84cbf82b807c73152252ecc90f54d89cdd1b0e7351e"
}
+170 −181
Original line number Diff line number Diff line
{
  autoPatchelfHook,
  dpkg,
  fetchurl,
  makeDesktopItem,
  makeWrapper,
  stdenv,
  lib,
  udev,
  buildPackages,
  cpio,
  xar,
  libdbusmenu,
  alsa-lib,
  libgbm,
  nss,
  nspr,
  systemd,
  stdenv,
  stdenvNoCC,
  fetchFromGitHub,
  electron,
  nodejs,
  yarn-berry_3,
  makeWrapper,
  makeDesktopItem,
  darwin,
  zip,
  jq,
}:

let

  inherit (stdenv.hostPlatform) system;

  throwSystem = throw "Unsupported system: ${system}";

  pname = "wire-desktop";

  versions = builtins.fromJSON (builtins.readFile ./versions.json);

  version =
    {
      x86_64-darwin = versions.macos.version;
      aarch64-darwin = versions.macos.version;
      x86_64-linux = versions.linux.version;
    }
    .${system} or throwSystem;

  hash =
    {
      x86_64-darwin = versions.macos.hash;
      aarch64-darwin = versions.macos.hash;
      x86_64-linux = versions.linux.hash;
    }
    .${system} or throwSystem;

  meta = {
    description = "Modern, secure messenger for everyone";
    longDescription = ''
      Wire Personal is a secure, privacy-friendly messenger. It combines useful
      and fun features, audited security, and a beautiful, distinct user
      interface.  It does not require a phone number to register and chat.

        * End-to-end encrypted chats, calls, and files
        * Crystal clear voice and video calling
        * File and screen sharing
        * Timed messages and chats
        * Synced across your phone, desktop and tablet
    '';
    homepage = "https://wire.com/";
    downloadPage = "https://wire.com/download/";
    sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
    license = lib.licenses.gpl3Plus;
    maintainers = with lib.maintainers; [
      arianvp
      toonn
    ];
    platforms = lib.platforms.darwin ++ [
      "x86_64-linux"
    ];
    hydraPlatforms = [ ];
  hostPlatform = stdenvNoCC.hostPlatform;
  nodeArch = hostPlatform.node.arch;
  yarn-berry = yarn-berry_3;
  # same hash for this release but can change in the future
  sources = rec {
    x86_64-linux = rec {
      version = "3.40.3882";
      src = fetchFromGitHub {
        owner = "wireapp";
        repo = "wire-desktop";
        tag = "linux/${version}";
        hash = "sha256-pNu+/JKvaKSqHxNeDL8RcDy+FiY3aynQH06t05qgXrA=";
      };

  passthru.updateScript = {
    command = [
      ./update.sh
      ./.
    ];
    # R-ryantm does not respect the commit feature, leading to inaccurate
    # commit messages because it only sees the Linux version numbers.
    # nixpkgs-update: no auto update
    supportedFeatures = [ "commit" ];
    };

  linux = stdenv.mkDerivation rec {
    inherit
      pname
      version
      meta
      passthru
      ;

    src = fetchurl {
      url = "https://wire-app.wire.com/linux/debian/pool/main/Wire-${version}_amd64.deb";
      inherit hash;
    x86_64-darwin = rec {
      version = "3.40.5442";
      src = fetchFromGitHub {
        owner = "wireapp";
        repo = "wire-desktop";
        tag = "macos/${version}";
        hash = "sha256-pNu+/JKvaKSqHxNeDL8RcDy+FiY3aynQH06t05qgXrA=";
      };

    desktopItem = makeDesktopItem {
      categories = [
        "Network"
        "InstantMessaging"
        "Chat"
        "VideoConference"
      ];
      comment = "Secure messenger for everyone";
      desktopName = "Wire";
      exec = "wire-desktop %U";
      genericName = "Secure messenger";
      icon = "wire-desktop";
      name = "wire-desktop";
      startupWMClass = "Wire";
    };
    aarch64-linux = x86_64-linux;
    aarch64-darwin = x86_64-darwin;
  };
  web-config = fetchFromGitHub {
    owner = "wireapp";
    repo = "wire-web-config-wire";
    tag = "v0.34.9-0";
    hash = "sha256-E9x/tRcMfXw/tjgNBUTefym9/m/Xu9/9CclwSmxpDzU=";
  };
  electron-dist-zip = stdenvNoCC.mkDerivation {
    pname = "electron-dist-zip";
    version = electron.version;
    src = electron.dist;
    nativeBuildInputs = [ zip ];
    buildPhase = ''
      zip --recurse-paths - . > $out
    '';
    dontInstall = true;
  };
in
stdenv.mkDerivation (finalAttrs: {
  pname = "wire-desktop";
  inherit (sources.${stdenv.system}) version src;

    dontBuild = true;
    dontConfigure = true;
    dontPatchELF = true;
    dontWrapGApps = true;
  missingHashes = ./missing-hashes.json;
  offlineCache = yarn-berry.fetchYarnBerryDeps {
    inherit (finalAttrs) src missingHashes;
    hash = "sha256-md7B8NSqT9dmPxrp9zbWifNow+1j2tuTRMOljG1V8WE=";
  };

    # TODO: migrate off autoPatchelfHook and use nixpkgs' electron
  nativeBuildInputs = [
      autoPatchelfHook
      dpkg
    nodejs
    yarn-berry.yarnBerryConfigHook
    yarn-berry
    makeWrapper
      (buildPackages.wrapGAppsHook3.override { makeWrapper = buildPackages.makeShellWrapper; })
    ];

    buildInputs = [
      alsa-lib
      libgbm
      nss
      nspr
      systemd
  ]
  ++ lib.optionals stdenv.hostPlatform.isDarwin [
    jq
    darwin.autoSignDarwinBinariesHook
  ];

    installPhase = ''
      runHook preInstall

      mkdir -p "$out/bin"
      cp -R "opt" "$out"
      cp -R "usr/share" "$out/share"
      chmod -R g-w "$out"

      # Desktop file
      mkdir -p "$out/share/applications"
      cp "${desktopItem}/share/applications/"* "$out/share/applications"

      runHook postInstall
    '';

    runtimeDependencies = [
      (lib.getLib udev)
      libdbusmenu
  patches = [
    ./build-linux.patch
    ./build-macos.patch
  ];

    preFixup = ''
      gappsWrapperArgs+=(--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}")
  # we provide web-config externally due to yarn trying to fetch from github on build phase
  postPatch = ''
    substituteInPlace .copyconfigrc.js \
      --replace-fail 'repositoryUrl,' 'repositoryUrl, externalDir : "${web-config}",'
  '';

    postFixup = ''
      makeWrapper $out/opt/Wire/wire-desktop $out/bin/wire-desktop \
        "''${gappsWrapperArgs[@]}"
    '';
  };
  env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";

  darwin = stdenv.mkDerivation {
    inherit
      pname
      version
      meta
      passthru
      ;

    src = fetchurl {
      url = "https://github.com/wireapp/wire-desktop/releases/download/macos%2F${version}/Wire.pkg";
      inherit hash;
    };
  # we put the electrons for each platform under `node_modules/electron-dist` due to electron packager grabbing it otherwise
  buildPhase = ''
    runHook preBuild

    buildInputs = [
      cpio
      xar
    ];
    export BUILD_NUMBER=$(echo ${finalAttrs.version} | awk -F. '{print $NF}')
  ''
  + lib.optionalString stdenv.hostPlatform.isDarwin ''

    unpackPhase = ''
      runHook preUnpack
    # this is needed due to macos builder using electron-packager directly
    # we put the zipped electron into a custom path which is defined in the patch, see build-macos.patch
    ELECTRON_VERSION_IN_LOCKFILE=$(yarn why electron --json | tail --lines 1 | jq --raw-output '.children | to_entries | first | .key ' | cut -d : -f 2)
    mkdir node_modules/electron-dist
    cp ${electron-dist-zip} node_modules/electron-dist/electron-v$ELECTRON_VERSION_IN_LOCKFILE-mas-${nodeArch}.zip

      xar -xf $src
      cd com.wearezeta.zclient.mac.pkg
    # these variables are needed to skip signing on darwin, we sign with autoSignDarwinBinariesHook later
    export MACOS_CERTIFICATE_NAME_APPLICATION="" MACOS_CERTIFICATE_NAME_INSTALLER=""
    yarn build:macos:${nodeArch}

      runHook postUnpack
    '';
  ''
  + lib.optionalString (stdenv.hostPlatform.isLinux) ''

    buildPhase = ''
      runHook preBuild
    cp -R ${electron.dist} node_modules/electron-dist
    # electron needs to have write access otherwire electron-fuses fails
    chmod -R u+w node_modules/electron-dist

      cat Payload | gunzip -dc | cpio -i
    # we build only for the linux-unpacked output, not other targets
    export LINUX_TARGET=dir
    yarn build:linux

  ''
  + ''
    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall
  ''
  + lib.optionalString stdenv.hostPlatform.isDarwin ''

    mkdir -p $out/{Applications,bin}
    cp -r wrap/build/Wire-mas-${nodeArch}/Wire.app $out/Applications

    makeWrapper $out/Applications/Wire.app/Contents/MacOS/Wire $out/bin/wire-desktop

  ''
  + lib.optionalString (stdenv.hostPlatform.isLinux) ''

    mkdir -p $out/share/wire-desktop
    cp -r wrap/dist/linux-unpacked/{locales,resources{,.pak}} $out/share/wire-desktop

      mkdir -p $out/Applications
      cp -r Wire.app $out/Applications
    makeWrapper ${lib.getExe electron} $out/bin/wire-desktop \
      --add-flags $out/share/wire-desktop/resources/app.asar \
      --inherit-argv0

    for size in 32 256; do
      install -Dm644 "resources/icons/"$size"x"$size".png" "$out/share/icons/hicolor/"$size"x"$size"/apps/wire-desktop.png"
    done

  ''
  + ''
    runHook postInstall
  '';

  desktopItem = makeDesktopItem {
    categories = [
      "Network"
      "InstantMessaging"
      "Chat"
      "VideoConference"
    ];
    comment = "Secure messenger for everyone";
    desktopName = "Wire";
    exec = "wire-desktop %U";
    genericName = "Secure messenger";
    icon = "wire-desktop";
    name = "wire-desktop";
    startupWMClass = "Wire";
  };

in
if stdenv.hostPlatform.isDarwin then darwin else linux
  meta = {
    description = "Modern, secure messenger for everyone";
    longDescription = ''
      Wire Personal is a secure, privacy-friendly messenger. It combines useful
      and fun features, audited security, and a beautiful, distinct user
      interface.  It does not require a phone number to register and chat.

        * End-to-end encrypted chats, calls, and files
        * Crystal clear voice and video calling
        * File and screen sharing
        * Timed messages and chats
        * Synced across your phone, desktop and tablet
    '';
    homepage = "https://wire.com/";
    downloadPage = "https://wire.com/download/";
    license = lib.licenses.gpl3Plus;
    maintainers = with lib.maintainers; [
      arianvp
      ern775
      korkutkardes7
    ];
    platforms = [
      "x86_64-linux"
      "aarch64-linux"
      "x86_64-darwin"
      "aarch64-darwin"
    ];
  };
})
Loading