From 4956dafd72ebcd3d34a2be55da9d33fae6da066a Mon Sep 17 00:00:00 2001 From: teutat3s Date: Sat, 13 Apr 2024 02:17:58 +0200 Subject: [PATCH] fix: screen sharing for slack, element-desktop --- flake.lock | 17 +++++++++++ flake.nix | 2 +- overlays/default.nix | 5 ++++ overlays/element-desktop.nix | 56 ++++++++++++++++++++++++++++++++++++ overlays/slack.nix | 9 ++++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 overlays/element-desktop.nix create mode 100644 overlays/slack.nix diff --git a/flake.lock b/flake.lock index 4772b4ba..481f3d79 100644 --- a/flake.lock +++ b/flake.lock @@ -143,6 +143,22 @@ "type": "github" } }, + "fork": { + "locked": { + "lastModified": 1712959986, + "narHash": "sha256-/4PhrnC+W5gWJAiRDf3tfLouxJc1UhSAnCpwKf1q1K4=", + "owner": "teutat3s", + "repo": "nixpkgs", + "rev": "2186dafc19798a5314d42c126b7520957e019cef", + "type": "github" + }, + "original": { + "owner": "teutat3s", + "ref": "fix-element-desktop-screen-sharing-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, "home-manager": { "inputs": { "nixpkgs": [ @@ -303,6 +319,7 @@ "deploy-rs": "deploy-rs", "flake-compat": "flake-compat", "flake-parts": "flake-parts", + "fork": "fork", "home-manager": "home-manager", "master": "master", "nix-darwin": "nix-darwin", diff --git a/flake.nix b/flake.nix index 68d5c85f..1a74d64c 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ unstable.url = "github:nixos/nixpkgs/nixos-unstable"; master.url = "github:nixos/nixpkgs/master"; - #fork.url = "github:teutat3s/nixpkgs/backport-droidcam"; + fork.url = "github:teutat3s/nixpkgs/fix-element-desktop-screen-sharing-23.11"; flake-compat.url = "github:edolstra/flake-compat"; flake-compat.flake = false; diff --git a/overlays/default.nix b/overlays/default.nix index d6616a31..20b946fa 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -18,12 +18,16 @@ "slack" ]; }; + fork = import inputs.fork { + system = prev.system; + }; master = import inputs.master { system = prev.system; }; in { direnv = unstable.direnv; + element-desktop = fork.element-desktop; nixVersions = prev.nixVersions // {inherit (unstable.nixVersions) nix_2_20;}; nix-direnv = unstable.nix-direnv; _1password = unstable._1password; @@ -37,6 +41,7 @@ (import ./mdbook-multilang.nix inputs) (import ./nix-index.nix) (import ./prr.nix) + (import ./slack.nix) (import ./neovim-plugins.nix) ]; }); diff --git a/overlays/element-desktop.nix b/overlays/element-desktop.nix new file mode 100644 index 00000000..5620cd10 --- /dev/null +++ b/overlays/element-desktop.nix @@ -0,0 +1,56 @@ +final: prev: { + element-desktop = prev.element-desktop.overrideAttrs (oldAttrs: rec { + + installPhase = + let + libPath = prev.lib.makeLibraryPath [ + prev.libnotify + ]; + executableName = "element-desktop"; + desktopItem = prev.makeDesktopItem { + name = "element-desktop"; + exec = "${executableName} %u"; + icon = "element"; + desktopName = "Element"; + genericName = "Matrix Client"; + comment = oldAttrs.meta.description; + categories = [ "Network" "InstantMessaging" "Chat" ]; + startupWMClass = "element"; + mimeTypes = [ "x-scheme-handler/element" ]; + }; + in + '' + runHook preInstall + + # resources + mkdir -p "$out/share/element" + ln -s '${prev.element-web}' "$out/share/element/webapp" + cp -r '.' "$out/share/element/electron" + cp -r './res/img' "$out/share/element" + rm -rf "$out/share/element/electron/node_modules" + cp -r './node_modules' "$out/share/element/electron" + cp $out/share/element/electron/lib/i18n/strings/en_EN.json $out/share/element/electron/lib/i18n/strings/en-us.json + ln -s $out/share/element/electron/lib/i18n/strings/en{-us,}.json + + # icons + for icon in $out/share/element/electron/build/icons/*.png; do + mkdir -p "$out/share/icons/hicolor/$(basename $icon .png)/apps" + ln -s "$icon" "$out/share/icons/hicolor/$(basename $icon .png)/apps/element.png" + done + + # desktop item + mkdir -p "$out/share" + ln -s "${desktopItem}/share/applications" "$out/share/applications" + + # executable wrapper + # LD_PRELOAD workaround for sqlcipher not found: https://github.com/matrix-org/seshat/issues/102 + makeWrapper '${prev.electron}/bin/electron' "$out/bin/element-desktop" \ + --set LD_PRELOAD ${prev.sqlcipher}/lib/libsqlcipher.so \ + --set LD_LIBRARY_PATH "${libPath}" \ + --add-flags "$out/share/element/electron" \ + --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WebRTCPipeWireCapturer,WaylandWindowDecorations}}" + + runHook postInstall + ''; + }); +} diff --git a/overlays/slack.nix b/overlays/slack.nix new file mode 100644 index 00000000..90796ef5 --- /dev/null +++ b/overlays/slack.nix @@ -0,0 +1,9 @@ +final: prev: { + # https://askubuntu.com/questions/1490447/slack-with-webrtcpipewirecapture-wyaland-black-screen-sharing-but-works-on-chrom + slack = prev.slack.overrideAttrs (oldAttrs: rec { + + postInstall = '' + sed -i -e 's/,"WebRTCPipeWireCapturer"/,"LebRTCPipeWireCapturer"/' $out/lib/slack/resources/app.asar + ''; + }); +}