packages: Add a sandboxed discord package

This commit is contained in:
PapaTutuWawa 2021-08-26 19:15:53 +02:00
parent ed430bcf54
commit 2114a4fc94
6 changed files with 83 additions and 1 deletions

View File

@ -54,7 +54,7 @@ in
}; };
# We don't tolerate non-free software, except for Steam and Linux firmware # We don't tolerate non-free software, except for Steam and Linux firmware
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "firmwareLinuxNonfree" "steam" "steam-original" "steam-runtime"]; nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "firmwareLinuxNonfree" "steam" "steam-original" "steam-runtime" "discord" ];
services = { services = {
connman = { connman = {

View File

@ -91,6 +91,7 @@
evdev-proxy # Custom package evdev-proxy # Custom package
vfio-isolate # Custom Package vfio-isolate # Custom Package
steam steam
discord-wrapper
]; ];
sessionVariables = { sessionVariables = {

View File

@ -0,0 +1,41 @@
{
lib, stdenv, pkgs
, extraStartupArgs ? ""
}:
pkgs.discord.overrideAttrs (old: let
asar = pkgs.nodePackages.asar;
gtk3 = pkgs.gtk3;
binaryName = "Discord";
system-electron = "$out/opt/${binaryName}/system-electron.sh";
in {
nativeBuildInputs = with pkgs; old.nativeBuildInputs ++ [ electron asar ];
buildPhase = ''
${asar}/bin/asar e resources/app.asar resources/app
rm resources/app.asar
sed -i "s|process.resourcesPath|'$out/opt/${binaryName}/resources'|" resources/app/app_bootstrap/buildInfo.js
sed -i "s|exeDir,|'$out/usr/share/pixmaps',|" resources/app/app_bootstrap/autoStart/linux.js
${asar}/bin/asar p resources/app resources/app.asar --unpack-dir '**'
rm -rf resources/app
'';
installPhase = ''
mkdir -p $out/{bin,opt/${binaryName},share/pixmaps}
mv * $out/opt/${binaryName}
echo "#!/bin/sh" > ${system-electron}
echo "exec ${pkgs.electron}/bin/electron $out/opt/${binaryName}/resources/app.asar ${extraStartupArgs}" >> ${system-electron}
chmod +x ${system-electron}
chmod +x $out/opt/${binaryName}/${binaryName}
patchelf --set-interpreter ${stdenv.cc.bintools.dynamicLinker} \
$out/opt/${binaryName}/${binaryName}
wrapProgram ${system-electron} \
"''${gappsWrapperArgs[@]}" \
--prefix XDG_DATA_DIRS : "${gtk3}/share/gsettings-schemas/${gtk3.name}/" \
--prefix LD_LIBRARY_PATH : ${old.libPath}:$out/opt/${binaryName}
ln -s ${system-electron} $out/bin/${binaryName}
# Without || true the install would fail on case-insensitive filesystems
ln -s ${system-electron} $out/bin/${lib.strings.toLower binaryName} || true
ln -s $out/opt/${binaryName}/discord.png $out/share/pixmaps/${old.pname}.png
ln -s "${old.desktopItem}/share/applications" $out/share/
'';
desktopItem = null;
})

View File

@ -0,0 +1,11 @@
{ stdenv, lib, makeDesktopItem, discord }:
makeDesktopItem {
name = "Discord";
exec = "${discord}/bin/Discord";
icon = "discord";
comment = "All-in-one voice and text chat for gamers that's free, secure, and works on both your desktop and phone.";
genericName = "Internet Messenger";
desktopName = "Discord";
categories = "Network;InstantMessaging;";
}

View File

@ -0,0 +1,14 @@
{ writeScript, runtimeShell, buildFHSUserEnvBubblewrap, discord }:
buildFHSUserEnvBubblewrap {
name = "discord";
runScript = ''
#!${runtimeShell}
exec ${discord}/bin/Discord $@
'';
specifyHomeDirs = true;
mountInHome = ".config/discord";
additionalBlacklist = [ "/mnt" ];
chdirTo = "/home/$USER";
}

View File

@ -3,6 +3,16 @@
let let
pySmartDL = pkgs.callPackage ./development/python/pySmartDL {}; pySmartDL = pkgs.callPackage ./development/python/pySmartDL {};
cfscrape = pkgs.callPackage ./development/python/cfscrape {}; cfscrape = pkgs.callPackage ./development/python/cfscrape {};
buildFHSUserEnvBubblewrap = pkgs.callPackage ./build-support/build-fhs-userenv-bubblewrap {};
discord-system-electron = pkgs.callPackage ./applications/networking/instant-messengers/discord {
# Wayland
# NOTE: electron under Wayland has no window titlebars
#extraStartupArgs = "--enable-features=UseOzonePlatform --ozone-platform=wayland";
};
discord-system-electron-wrapped = pkgs.callPackage ./applications/networking/instant-messengers/discord/wrapped.nix {
buildFHSUserEnvBubblewrap = buildFHSUserEnvBubblewrap;
discord = discord-system-electron;
};
in { in {
gamemode = pkgs.callPackage ./tools/games/gamemode { }; gamemode = pkgs.callPackage ./tools/games/gamemode { };
key-mapper = pkgs.callPackage ./tools/games/key-mapper {}; key-mapper = pkgs.callPackage ./tools/games/key-mapper {};
@ -24,4 +34,9 @@ in {
pySmartDL = pySmartDL; pySmartDL = pySmartDL;
cfscrape = cfscrape; cfscrape = cfscrape;
}; };
discord-system-electron = discord-system-electron;
discord-system-electron-wrapped = discord-system-electron-wrapped;
discord-wrapper = pkgs.callPackage ./applications/networking/instant-messengers/discord/desktop.nix {
discord = discord-system-electron-wrapped;
};
} }