about summary refs log tree commit diff
path: root/pkgs/by-name/ve/vesktop/package.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name/ve/vesktop/package.nix')
-rw-r--r--pkgs/by-name/ve/vesktop/package.nix250
1 files changed, 132 insertions, 118 deletions
diff --git a/pkgs/by-name/ve/vesktop/package.nix b/pkgs/by-name/ve/vesktop/package.nix
index 8b06a570dedc4..6998f0ab8847e 100644
--- a/pkgs/by-name/ve/vesktop/package.nix
+++ b/pkgs/by-name/ve/vesktop/package.nix
@@ -1,25 +1,24 @@
-{ lib
-, stdenv
-, stdenvNoCC
-, fetchFromGitHub
-, substituteAll
-, makeWrapper
-, makeDesktopItem
-, copyDesktopItems
-, vencord
-, electron
-, libicns
-, jq
-, moreutils
-, cacert
-, nodePackages
-, pipewire
-, libpulseaudio
-, autoPatchelfHook
-, withTTS ? true
+{
+  lib,
+  stdenv,
+  fetchFromGitHub,
+  substituteAll,
+  makeBinaryWrapper,
+  makeWrapper,
+  makeDesktopItem,
+  copyDesktopItems,
+  vencord,
+  electron,
+  libicns,
+  pipewire,
+  libpulseaudio,
+  autoPatchelfHook,
+  pnpm,
+  nodejs,
+  withTTS ? true,
   # Enables the use of vencord from nixpkgs instead of
   # letting vesktop manage it's own version
-, withSystemVencord ? true
+  withSystemVencord ? false,
 }:
 stdenv.mkDerivation (finalAttrs: {
   pname = "vesktop";
@@ -32,141 +31,156 @@ stdenv.mkDerivation (finalAttrs: {
     hash = "sha256-cZOyydwpIW9Xq716KVi1RGtSlgVnOP3w8vXDwouS70E=";
   };
 
-  # NOTE: This requires pnpm 8.10.0 or newer
-  # https://github.com/pnpm/pnpm/pull/7214
-  pnpmDeps =
-    assert lib.versionAtLeast nodePackages.pnpm.version "8.10.0";
-    stdenvNoCC.mkDerivation {
-      pname = "${finalAttrs.pname}-pnpm-deps";
-      inherit (finalAttrs) src version patches ELECTRON_SKIP_BINARY_DOWNLOAD;
-
-      nativeBuildInputs = [
-        jq
-        moreutils
-        nodePackages.pnpm
-        cacert
-      ];
-
-      pnpmPatch = builtins.toJSON {
-        pnpm.supportedArchitectures = {
-          os = [ "linux" ];
-          cpu = [ "x64" "arm64" ];
-        };
-      };
-
-      postPatch = ''
-        mv package.json package.json.orig
-        jq --raw-output ". * $pnpmPatch" package.json.orig > package.json
-      '';
-
-      # https://github.com/NixOS/nixpkgs/blob/763e59ffedb5c25774387bf99bc725df5df82d10/pkgs/applications/misc/pot/default.nix#L56
-      installPhase = ''
-        export HOME=$(mktemp -d)
-
-        pnpm config set store-dir $out
-        pnpm install --frozen-lockfile --ignore-script
-
-        rm -rf $out/v3/tmp
-        for f in $(find $out -name "*.json"); do
-          sed -i -E -e 's/"checkedAt":[0-9]+,//g' $f
-          jq --sort-keys . $f | sponge $f
-        done
-      '';
-
-      dontBuild = true;
-      dontFixup = true;
-      outputHashMode = "recursive";
-      outputHash = "sha256-6ezEBeYmK5va3gCh00YnJzZ77V/Ql7A3l/+csohkz68=";
-    };
-
-  nativeBuildInputs = [
-    copyDesktopItems
-    nodePackages.pnpm
-    nodePackages.nodejs
-    makeWrapper
-    autoPatchelfHook
-  ];
+  pnpmDeps = pnpm.fetchDeps {
+    inherit (finalAttrs)
+      pname
+      version
+      src
+      patches
+      ;
+    hash = "sha256-PogE8uf3W5cKSCqFHMz7FOvT7ONUP4FiFWGBgtk3UC8=";
+  };
 
-  buildInputs = [
-    pipewire
+  nativeBuildInputs =
+    [
+      nodejs
+      pnpm.configHook
+    ]
+    ++ lib.optionals stdenv.isLinux [
+      # vesktop uses venmic, which is a shipped as a prebuilt node module
+      # and needs to be patched
+      autoPatchelfHook
+      copyDesktopItems
+      # we use a script wrapper here for environment variable expansion at runtime
+      # https://github.com/NixOS/nixpkgs/issues/172583
+      makeWrapper
+    ]
+    ++ lib.optionals stdenv.isDarwin [
+      # on macos we don't need to expand variables, so we can use the faster binary wrapper
+      makeBinaryWrapper
+    ];
+
+  buildInputs = lib.optionals stdenv.isLinux [
     libpulseaudio
+    pipewire
     stdenv.cc.cc.lib
   ];
 
-  patches = [
-    ./disable_update_checking.patch
-  ] ++ lib.optional withSystemVencord (substituteAll { inherit vencord; src = ./use_system_vencord.patch; });
-
-  ELECTRON_SKIP_BINARY_DOWNLOAD = 1;
+  patches =
+    [ ./disable_update_checking.patch ]
+    ++ lib.optional withSystemVencord (substituteAll {
+      inherit vencord;
+      src = ./use_system_vencord.patch;
+    });
 
-  preBuild = ''
-    export HOME=$(mktemp -d)
-    export STORE_PATH=$(mktemp -d)
+  env = {
+    ELECTRON_SKIP_BINARY_DOWNLOAD = 1;
+  };
 
-    cp -Tr "$pnpmDeps" "$STORE_PATH"
-    chmod -R +w "$STORE_PATH"
+  # disable code signing on macos
+  # https://github.com/electron-userland/electron-builder/blob/77f977435c99247d5db395895618b150f5006e8f/docs/code-signing.md#how-to-disable-code-signing-during-the-build-process-on-macos
+  postConfigure = lib.optionalString stdenv.isDarwin ''
+    export CSC_IDENTITY_AUTO_DISCOVERY=false
+  '';
 
-    pnpm config set store-dir "$STORE_PATH"
-    pnpm install --offline --frozen-lockfile --ignore-script
-    patchShebangs node_modules/{*,.*}
+  # electron builds must be writable on darwin
+  preBuild = lib.optionalString stdenv.isDarwin ''
+    cp -r ${electron}/Applications/Electron.app .
+    chmod -R u+w Electron.app
   '';
 
-  postBuild = ''
+  buildPhase = ''
+    runHook preBuild
+
     pnpm build
-    # using `pnpm exec` here apparently makes it ignore ELECTRON_SKIP_BINARY_DOWNLOAD
-    ./node_modules/.bin/electron-builder \
+    pnpm exec electron-builder \
       --dir \
       -c.asarUnpack="**/*.node" \
-      -c.electronDist=${electron}/libexec/electron \
+      -c.electronDist=${if stdenv.isDarwin then "." else "${electron}/libexec/electron"} \
       -c.electronVersion=${electron.version}
+
+    runHook postBuild
+  '';
+
+  postBuild = lib.optionalString stdenv.isLinux ''
+    pushd build
+    ${libicns}/bin/icns2png -x icon.icns
+    popd
   '';
 
-  # this is consistent with other nixpkgs electron packages and upstream, as far as I am aware
   installPhase =
     ''
       runHook preInstall
-
+    ''
+    + lib.optionalString stdenv.isLinux ''
       mkdir -p $out/opt/Vesktop
-      cp -r dist/linux-*unpacked/resources $out/opt/Vesktop/
+      cp -r dist/*unpacked/resources $out/opt/Vesktop/
 
-      pushd build
-      ${libicns}/bin/icns2png -x icon.icns
-      for file in icon_*x32.png; do
+      for file in build/icon_*x32.png; do
         file_suffix=''${file//icon_}
         install -Dm0644 $file $out/share/icons/hicolor/''${file_suffix//x32.png}/apps/vesktop.png
       done
+    ''
+    + lib.optionalString stdenv.isDarwin ''
+      mkdir -p $out/{Applications,bin}
+      mv dist/mac*/Vesktop.App $out/Applications
+    ''
+    + ''
+      runHook postInstall
+    '';
 
+  postFixup =
+    lib.optionalString stdenv.isLinux ''
       makeWrapper ${electron}/bin/electron $out/bin/vesktop \
         --add-flags $out/opt/Vesktop/resources/app.asar \
         ${lib.optionalString withTTS "--add-flags \"--enable-speech-dispatcher\""} \
         --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime}}"
-
-      runHook postInstall
+    ''
+    + lib.optionalString stdenv.isDarwin ''
+      makeWrapper $out/Applications/Vesktop.app/Contents/MacOS/Vesktop $out/bin/vesktop
     '';
 
-  desktopItems = [
-    (makeDesktopItem {
-      name = "vesktop";
-      desktopName = "Vesktop";
-      exec = "vesktop %U";
-      icon = "vesktop";
-      startupWMClass = "Vesktop";
-      genericName = "Internet Messenger";
-      keywords = [ "discord" "vencord" "electron" "chat" ];
-      categories = [ "Network" "InstantMessaging" "Chat" ];
-    })
-  ];
+  desktopItems = lib.optional stdenv.isLinux (makeDesktopItem {
+    name = "vesktop";
+    desktopName = "Vesktop";
+    exec = "vesktop %U";
+    icon = "vesktop";
+    startupWMClass = "Vesktop";
+    genericName = "Internet Messenger";
+    keywords = [
+      "discord"
+      "vencord"
+      "electron"
+      "chat"
+    ];
+    categories = [
+      "Network"
+      "InstantMessaging"
+      "Chat"
+    ];
+  });
 
   passthru = {
     inherit (finalAttrs) pnpmDeps;
   };
 
-  meta = with lib; {
-    description = "An alternate client for Discord with Vencord built-in";
+  meta = {
+    description = "Alternate client for Discord with Vencord built-in";
     homepage = "https://github.com/Vencord/Vesktop";
-    license = licenses.gpl3Only;
-    maintainers = with maintainers; [ getchoo Scrumplex vgskye pluiedev ];
-    platforms = [ "x86_64-linux" "aarch64-linux" ];
+    changelog = "https://github.com/Vencord/Vesktop/releases/tag/${finalAttrs.src.rev}";
+    license = lib.licenses.gpl3Only;
+    maintainers = with lib.maintainers; [
+      getchoo
+      Scrumplex
+      vgskye
+      pluiedev
+    ];
     mainProgram = "vesktop";
+    platforms = [
+      "x86_64-linux"
+      "aarch64-linux"
+      "x86_64-darwin"
+      "aarch64-darwin"
+    ];
   };
 })