diff --git a/pkgs/applications/networking/instant-messengers/discord/darwin.nix b/pkgs/applications/networking/instant-messengers/discord/darwin.nix index 4bc9ac98df1f..494a7e6a4428 100644 --- a/pkgs/applications/networking/instant-messengers/discord/darwin.nix +++ b/pkgs/applications/networking/instant-messengers/discord/darwin.nix @@ -1,4 +1,4 @@ -{ pname, version, src, meta, stdenv, binaryName, desktopName, undmg }: +{ pname, version, src, openasar, meta, stdenv, binaryName, desktopName, lib, undmg }: stdenv.mkDerivation { inherit pname version src meta; @@ -8,7 +8,15 @@ stdenv.mkDerivation { sourceRoot = "."; installPhase = '' + runHook preInstall + mkdir -p $out/Applications cp -r "${desktopName}.app" $out/Applications + + runHook postInstall + ''; + + postInstall = lib.strings.optionalString (openasar != null) '' + cp -f ${openasar} $out/Applications/${desktopName}.app/Contents/Resources/app.asar ''; } diff --git a/pkgs/applications/networking/instant-messengers/discord/default.nix b/pkgs/applications/networking/instant-messengers/discord/default.nix index ab471ef47fb7..957efb7a1a48 100644 --- a/pkgs/applications/networking/instant-messengers/discord/default.nix +++ b/pkgs/applications/networking/instant-messengers/discord/default.nix @@ -1,4 +1,4 @@ -{ branch ? "stable", pkgs, lib, stdenv }: +{ branch ? "stable", pkgs, lib, stdenv, withOpenASAR ? false }: let inherit (pkgs) callPackage fetchurl; versions = if stdenv.isLinux then { @@ -61,8 +61,11 @@ let ++ lib.optionals (branch == "ptb") [ "aarch64-darwin" ]; }; package = if stdenv.isLinux then ./linux.nix else ./darwin.nix; + + openasar = if withOpenASAR then callPackage ./openasar.nix { } else null; + packages = (builtins.mapAttrs - (_: value: callPackage package (value // { inherit src version; meta = meta // { mainProgram = value.binaryName; }; })) + (_: value: callPackage package (value // { inherit src version openasar; meta = meta // { mainProgram = value.binaryName; }; })) { stable = rec { pname = "discord"; diff --git a/pkgs/applications/networking/instant-messengers/discord/linux.nix b/pkgs/applications/networking/instant-messengers/discord/linux.nix index 74e424aaf1df..28c1d353ff61 100644 --- a/pkgs/applications/networking/instant-messengers/discord/linux.nix +++ b/pkgs/applications/networking/instant-messengers/discord/linux.nix @@ -1,4 +1,4 @@ -{ pname, version, src, meta, binaryName, desktopName, autoPatchelfHook +{ pname, version, src, openasar, meta, binaryName, desktopName, autoPatchelfHook , makeDesktopItem, lib, stdenv, wrapGAppsHook, makeShellWrapper, alsa-lib, at-spi2-atk , at-spi2-core, atk, cairo, cups, dbus, expat, fontconfig, freetype, gdk-pixbuf , glib, gtk3, libcxx, libdrm, libnotify, libpulseaudio, libuuid, libX11 @@ -72,6 +72,8 @@ stdenv.mkDerivation rec { ]; installPhase = '' + runHook preInstall + mkdir -p $out/{bin,opt/${binaryName},share/pixmaps,share/icons/hicolor/256x256/apps} mv * $out/opt/${binaryName} @@ -95,6 +97,12 @@ stdenv.mkDerivation rec { ln -s $out/opt/${binaryName}/discord.png $out/share/icons/hicolor/256x256/apps/${pname}.png ln -s "${desktopItem}/share/applications" $out/share/ + + runHook postInstall + ''; + + postInstall = lib.strings.optionalString (openasar != null) '' + cp -f ${openasar} $out/opt/${binaryName}/resources/app.asar ''; desktopItem = makeDesktopItem { diff --git a/pkgs/applications/networking/instant-messengers/discord/openasar.nix b/pkgs/applications/networking/instant-messengers/discord/openasar.nix new file mode 100644 index 000000000000..e378f490c0f4 --- /dev/null +++ b/pkgs/applications/networking/instant-messengers/discord/openasar.nix @@ -0,0 +1,42 @@ +{ lib, stdenv, fetchFromGitHub, nodejs, bash, nodePackages }: + +stdenv.mkDerivation rec { + version = "unstable-2022-06-10"; + pname = "openasar"; + + src = fetchFromGitHub { + owner = "GooseMod"; + repo = "OpenAsar"; + rev = "c6f2f5eb7827fea14cb4c54345af8ff6858c633a"; + sha256 = "m6e/WKGgkR8vjKcHSNdWE25MmDQM1Z3kgB24OJgbw/w="; + }; + + buildPhase = '' + runHook preBuild + + bash scripts/injectPolyfills.sh + substituteInPlace src/index.js --replace 'nightly' '${version}' + ${nodejs}/bin/node scripts/strip.js + ${nodePackages.asar}/bin/asar pack src app.asar + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + install app.asar $out + + runHook postInstall + ''; + + doCheck = false; + + meta = with lib; { + description = "Open-source alternative of Discord desktop's \"app.asar\"."; + homepage = "https://openasar.dev"; + license = licenses.mit; + maintainers = with maintainers; [ pedrohlc ]; + platforms = nodejs.meta.platforms; + }; +}