Vendor discord

This commit is contained in:
Nathan McCarty 2022-06-12 13:17:15 -04:00
parent 5d1bf8473b
commit 4a2422b977
Signed by: thatonelutenist
GPG Key ID: D70DA3DD4D1E9F96
2 changed files with 218 additions and 5 deletions

View File

@ -6,6 +6,16 @@
environment.systemPackages = with pkgs; environment.systemPackages = with pkgs;
let let
enableWayland = drv: bin: drv.overrideAttrs (
old: {
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.makeWrapper ];
postFixup = (old.postFixup or "") + ''
wrapProgram $out/bin/${bin} \
--add-flags "--enable-features=UseOzonePlatform" \
--add-flags "--ozone-platform=wayland"
'';
}
);
## Wayland workaround chromium desktop items ## Wayland workaround chromium desktop items
# Facebook messenger # Facebook messenger
fbChromeDesktopItem = pkgs.makeDesktopItem { fbChromeDesktopItem = pkgs.makeDesktopItem {
@ -21,6 +31,19 @@
exec = "${pkgs.chromium}/bin/chromium --enable-features=UseOzonePlatform -ozone-platform=wayland --app=\"https://teams.microsoft.com\""; exec = "${pkgs.chromium}/bin/chromium --enable-features=UseOzonePlatform -ozone-platform=wayland --app=\"https://teams.microsoft.com\"";
terminal = false; terminal = false;
}; };
# Discord
discordWayland = pkgs.callPackage ../packages/discord/default.nix rec {
pname = "discord-electron";
binaryName = "Discord";
desktopName = "Discord (Wayland)";
version = "0.0.18";
src = fetchurl {
url = "https://dl.discordapp.net/apps/linux/${version}/discord-${version}.tar.gz";
hash = "sha256-BBc4n6Q3xuBE13JS3gz/6EcwdOWW57NLp2saOlwOgMI=";
};
electron = pkgs.electron_13;
};
## Pass wayland options to existing applications ## Pass wayland options to existing applications
signalWaylandItem = pkgs.makeDesktopItem { signalWaylandItem = pkgs.makeDesktopItem {
name = "signal-desktop-wayland"; name = "signal-desktop-wayland";
@ -41,13 +64,12 @@
in in
[ [
# Discord # Discord
unstable.discord discordWayland
unstable.betterdiscordctl unstable.betterdiscordctl
# Desktop matrix client # Desktop matrix client
element-desktop (enableWayland element-desktop "element-desktop")
# Desktop signal client # Desktop signal client
signal-desktop (enableWayland signal-desktop "signal-desktop")
signalWaylandItem
# Desktop telegram client # Desktop telegram client
tdesktop tdesktop
# Desktop mastodon client # Desktop mastodon client
@ -66,7 +88,8 @@
teamsItem teamsItem
]; ];
# Override for waylandified discord, really jank, but its still newer than the bundled electron
# Work around for discord jank ugh
nixpkgs.config.permittedInsecurePackages = [ nixpkgs.config.permittedInsecurePackages = [
"electron-13.6.9" "electron-13.6.9"
]; ];

View File

@ -0,0 +1,190 @@
{ pname
, version
, src
, binaryName
, desktopName
, autoPatchelfHook
, makeDesktopItem
, lib
, stdenv
, wrapGAppsHook
, alsaLib
, at-spi2-atk
, at-spi2-core
, atk
, cairo
, cups
, dbus
, expat
, fontconfig
, freetype
, gdk-pixbuf
, glib
, gtk3
, libcxx
, libdrm
, libnotify
, libpulseaudio
, libuuid
, libX11
, libXScrnSaver
, libXcomposite
, libXcursor
, libXdamage
, libXext
, libXfixes
, libXi
, libXrandr
, libXrender
, libXtst
, libxcb
, libxshmfence
, mesa
, nspr
, nss
, pango
, systemd
, libappindicator-gtk3
, libdbusmenu
, writeScript
, common-updater-scripts
, electron
, nodePackages
, libgcc
, glibc
}:
let
inherit binaryName;
in
stdenv.mkDerivation rec {
inherit pname version src;
nativeBuildInputs = [
alsaLib
autoPatchelfHook
stdenv.cc.cc
cups
libdrm
libuuid
libXdamage
libX11
libXScrnSaver
libXtst
libxcb
libxshmfence
mesa
nss
wrapGAppsHook
nodePackages.asar
autoPatchelfHook
];
buildInputs = [
electron
libgcc
glibc
];
dontWrapGApps = true;
libPath = lib.makeLibraryPath [
libcxx
systemd
libpulseaudio
libdrm
mesa
stdenv.cc.cc
alsaLib
atk
at-spi2-atk
at-spi2-core
cairo
cups
dbus
expat
fontconfig
freetype
gdk-pixbuf
glib
gtk3
libnotify
libX11
libXcomposite
libuuid
libXcursor
libXdamage
libXext
libXfixes
libXi
libXrandr
libXrender
libXtst
nspr
nss
libxcb
pango
systemd
libXScrnSaver
libappindicator-gtk3
libdbusmenu
libgcc
];
installPhase =
let
electron_exec = "${electron}/bin/electron";
in
''
mkdir -p $out/{bin,opt/${binaryName},share/pixmaps}
mv * $out/opt/${binaryName}
chmod +x $out/opt/${binaryName}/${binaryName}
ln -s $out/opt/${binaryName}/discord.png $out/share/pixmaps/${pname}.png
mkdir -p $out/share/applications
ls $out/share/applications
sed "s|OUTDIR|$out|" ${desktopItem}/share/applications/${pname}.desktop > $out/share/applications/${pname}.desktop
# Hacks for system electron
asar e $out/opt/${binaryName}/resources/app.asar $out/opt/${binaryName}/resources/app
rm $out/opt/${binaryName}/resources/app.asar
sed -i "s|process.resourcesPath|'$out/opt/${binaryName}/resources'|" $out/opt/${binaryName}/resources/app/app_bootstrap/buildInfo.js
sed -i "s|exeDir,|'$out/share/pixmaps',|" $out/opt/${binaryName}/resources/app/app_bootstrap/autoStart/linux.js
asar p $out/opt/${binaryName}/resources/app $out/opt/${binaryName}/resources/app.asar --unpack-dir '**'
# executable wrapper
makeWrapper '${electron_exec}' "$out/bin/${binaryName}" \
--add-flags "--enable-features=UseOzonePlatform --ozone-platform=wayland $out/opt/${binaryName}/resources/app.asar"\
--prefix XDG_DATA_DIRS : "${gtk3}/share/gsettings-schemas/${gtk3.name}/"\
--prefix LD_LIBRARY_PATH : ${libPath}
ln -s $out/bin/${binaryName} $out/bin/${lib.strings.toLower binaryName}
'';
desktopItem =
makeDesktopItem {
name = pname;
exec = "${binaryName}";
icon = pname;
inherit desktopName;
genericName = meta.description;
categories = [ "Network" "InstantMessaging" ];
mimeTypes = [ "x-scheme-handler/discord" ];
};
passthru.updateScript = writeScript "discord-update-script" ''
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl gnugrep common-updater-scripts
set -eou pipefail;
url=$(curl -sI "https://discordapp.com/api/download/${builtins.replaceStrings ["discord-" "discord"] ["" "stable"] pname}?platform=linux&format=tar.gz" | grep -oP 'location: \K\S+')
version=''${url##https://dl*.discordapp.net/apps/linux/}
version=''${version%%/*.tar.gz}
update-source-version ${pname} "$version" --file=./pkgs/applications/networking/instant-messengers/discord/default.nix
'';
meta = with lib; {
description = "All-in-one cross-platform voice and text chat for gamers";
homepage = "https://discordapp.com/";
downloadPage = "https://discordapp.com/download";
license = licenses.unfree;
maintainers = with maintainers; [ ldesgoui MP2E ];
platforms = [ "x86_64-linux" ];
};
}