From 5bb6e6038ec8d458de7ca2527eb17627761406e2 Mon Sep 17 00:00:00 2001 From: Swarsel Date: Sat, 10 Aug 2024 16:40:35 +0200 Subject: [PATCH] fix: screen sharing on wayland; add:safeeyes this did not work due to a missing/wrong implementation of pipewire and xdg-portal. Now screensharing works in Microsoft Teams, Firefox as well as Discord. This also adds the safeeyes service. --- SwarselSystems.org | 160 +++++++++++++++++++++++---- modules/home/nixos.nix | 2 +- modules/home/startup.nix | 2 +- pkgs/swarselcheck/default.nix | 4 +- profiles/TEMPLATE/home.nix | 2 +- profiles/common/home/sway.nix | 16 ++- profiles/common/home/waybar.nix | 9 +- profiles/common/nixos/hardware.nix | 4 +- profiles/common/nixos/pipewire.nix | 14 +++ profiles/common/nixos/safeeyes.nix | 4 + profiles/common/nixos/sway.nix | 26 +++++ profiles/common/nixos/xdg-portal.nix | 19 ++++ scripts/swarselcheck.sh | 12 +- 13 files changed, 231 insertions(+), 43 deletions(-) create mode 100644 profiles/common/nixos/pipewire.nix create mode 100644 profiles/common/nixos/safeeyes.nix create mode 100644 profiles/common/nixos/sway.nix create mode 100644 profiles/common/nixos/xdg-portal.nix diff --git a/SwarselSystems.org b/SwarselSystems.org index 5fa5316..5d72a9a 100644 --- a/SwarselSystems.org +++ b/SwarselSystems.org @@ -243,7 +243,7 @@ Do not that =syncthingtray= is also not mentioned here. It is installed as a hom #+begin_src nix :tangle no :noweb-ref startupnixos { command = "nextcloud --background"; } -{ command = "discord --start-minimized"; } +{ command = "vesktop --start-minimized"; } { command = "element-desktop --hidden -enable-features=UseOzonePlatform -ozone-platform=wayland --disable-gpu-driver-bug-workarounds"; } { command = "ANKI_WAYLAND=1 anki"; } { command = "OBSIDIAN_USE_WAYLAND=1 obsidian"; } @@ -4396,7 +4396,7 @@ As such, I also define three additional overlays: #+begin_src shell :tangle scripts/swarselcheck.sh kitty=0 element=0 - discord=0 + vesktop=0 spotifyplayer=0 while :; do case ${1:-} in @@ -4404,7 +4404,7 @@ As such, I also define three additional overlays: ;; -e|--element) element=1 ;; - -d|--discord) discord=1 + -d|--vesktop) vesktop=1 ;; -s|--spotifyplayer) spotifyplayer=1 ;; @@ -4431,12 +4431,12 @@ As such, I also define three additional overlays: else exec swaymsg '[app_id=Element]' kill fi - elif [[ $discord -eq 1 ]]; then - STR=$(swaymsg -t get_tree | grep discord || true) + elif [[ $vesktop -eq 1 ]]; then + STR=$(swaymsg -t get_tree | grep vesktop || true) if [ "$STR" == "" ]; then - exec discord + exec vesktop else - exec swaymsg '[app_id=discord]' kill + exec swaymsg '[app_id=vesktop]' kill fi elif [[ $spotifyplayer -eq 1 ]]; then STR=$(swaymsg -t get_tree | jq -r 'recurse(.nodes[]) | select(.name == "__i3_scratch")' | grep spotifytui || true) @@ -4453,11 +4453,11 @@ As such, I also define three additional overlays: #+end_src #+begin_src nix :tangle pkgs/swarselcheck/default.nix - { writeShellApplication, kitty, element-desktop-wayland, discord, spotify-player, sway, jq}: + { writeShellApplication, kitty, element-desktop-wayland, vesktop, spotify-player, sway, jq}: writeShellApplication { name = "swarselcheck"; - runtimeInputs = [ kitty element-desktop-wayland discord spotify-player jq ]; + runtimeInputs = [ kitty element-desktop-wayland vesktop spotify-player jq ]; text = builtins.readFile ../../scripts/swarselcheck.sh; } @@ -4842,7 +4842,7 @@ Modules that need to be loaded on the NixOS level. Note that these will not be a config.swarselsystems.startup = lib.mkIf (!config.swarselsystems.isNixos) [ { command = "sleep 60 && nixGL nextcloud --background"; } - { command = "sleep 60 && nixGL discord --start-minimized -enable-features=UseOzonePlatform -ozone-platform=wayland"; } + { command = "sleep 60 && nixGL vesktop --start-minimized -enable-features=UseOzonePlatform -ozone-platform=wayland"; } { command = "sleep 60 && nixGL syncthingtray --wait"; } { command = "sleep 60 && ANKI_WAYLAND=1 nixGL anki"; } { command = "nm-applet --indicator"; } @@ -4880,7 +4880,7 @@ in type = types.listOf (types.attrsOf types.str); default = [ { command = "nextcloud --background"; } - { command = "discord --start-minimized"; } + { command = "vesktop --start-minimized"; } { command = "element-desktop --hidden -enable-features=UseOzonePlatform -ozone-platform=wayland --disable-gpu-driver-bug-workarounds"; } { command = "ANKI_WAYLAND=1 anki"; } { command = "OBSIDIAN_USE_WAYLAND=1 obsidian"; } @@ -4946,12 +4946,14 @@ First, we enable the use of =home-manager= as a NixoS module ./network.nix ./time.nix ./hardware.nix + ./pipewire.nix ./sops.nix ./packages.nix ./programs.nix ./zsh.nix ./syncthing.nix ./blueman.nix + ./safeeyes.nix ./networkdevices.nix ./gvfs.nix ./interceptiontools.nix @@ -4960,11 +4962,30 @@ First, we enable the use of =home-manager= as a NixoS module ./stylix.nix ./power-profiles-daemon.nix # ./impermanence.nix + ./nvd-rebuild.nix ./nix-ld.nix ./gnome-keyring.nix + ./sway.nix + ./xdg-portal.nix ]; - nix.settings.trusted-users = [ "swarsel" ]; + nix = let + flakeInputs = lib.filterAttrs (_: lib.isType "flake") inputs; + in { + settings = { + experimental-features = [ + "nix-command" + "flakes" + "ca-derivations" + ]; + trusted-users = [ "swarsel" ]; + flake-registry = ""; + warn-dirty = false; + }; + channel.enable = false; + registry = lib.mapAttrs (_: flake: {inherit flake;}) flakeInputs; + nixPath = lib.mapAttrsToList (n: _: "${n}=flake:${n}") flakeInputs; + }; home-manager = { useGlobalPkgs = true; @@ -5137,8 +5158,10 @@ Enable OpenGL, Sound, Bluetooth and various drivers. keyboard.qmk.enable = true; - pulseaudio= { - enable = true; + + + pulseaudio = { + enable = lib.mkIf (!config.services.pipewire.enable) true; package = pkgs.pulseaudioFull; }; @@ -5159,6 +5182,24 @@ Enable OpenGL, Sound, Bluetooth and various drivers. } #+end_src +**** Pipewire + +#+begin_src nix :tangle profiles/common/nixos/pipewire.nix + _ : { + security.rtkit.enable = true; # this is required for pipewire real-time access + + services.pipewire = { + enable = true; + pulse.enable = true; + jack.enable = true; + audio.enable = true; + alsa = { + enable = true; + support32Bit = true; + }; + }; + } +#+end_src **** Common network settings :PROPERTIES: :CUSTOM_ID: h:7d696b64-debe-4a95-80b5-1e510156a6c6 @@ -5525,6 +5566,8 @@ Mostly used to install some compilers and lsp's that I want to have available wh ledger-live-desktop # pinentry + dbus + swaylock-effects # secure boot sbctl @@ -5703,6 +5746,17 @@ Enables the blueman service including the nice system tray icon. } #+end_src +***** safeeyes + +Enables the blueman service including the nice system tray icon. + +#+begin_src nix :tangle profiles/common/nixos/safeeyes.nix + _ : + { + services.safeeyes.enable = true; + } +#+end_src + ***** Network devices In this section we enable compatibility with several network devices I have at home, mainly printers and scanners. @@ -6113,6 +6167,65 @@ Used for storing sessions in e.g. Nextcloud } #+end_src +**** Sway + + + +#+begin_src nix :tangle profiles/common/nixos/sway.nix + { pkgs, ... }: + { + + programs.sway = { + enable = true; + package = pkgs.swayfx; + wrapperFeatures = { + base = true; + gtk = true; + }; + + extraOptions = [ + "--unsupported-gpu" + ]; + + extraSessionCommands = '' + export XDG_SESSION_DESKTOP=sway + export SDL_VIDEODRIVER=wayland + export QT_QPA_PLATFORM=wayland-egl + export QT_WAYLAND_DISABLE_WINDOWDECORATION=1 + export MOZ_ENABLE_WAYLAND=1 + export MOZ_DISABLE_RDD_SANDBOX=1 + ''; + }; + + } +#+end_src + +**** xdg-portal + + + +#+begin_src nix :tangle profiles/common/nixos/xdg-portal.nix + { pkgs, ... }: + { + + xdg.portal = { + enable = true; + config = { + common = { + default = "wlr"; + }; + }; + wlr.enable = true; + wlr.settings.screencast = { + output_name = "eDP-1"; + chooser_type = "simple"; + chooser_cmd = "${pkgs.slurp}/bin/slurp -f %o -or"; + }; + }; + + } +#+end_src + *** Optional @@ -6363,7 +6476,7 @@ Programming languages and default lsp's are defined here: [[#h:0e7e8bea-ec58-499 xournalpp obsidian spotify - discord + vesktop # discord client stable.nextcloud-client spotify-player element-desktop-wayland @@ -7440,18 +7553,21 @@ The rest of this configuration is found here: #+begin_src nix :tangle profiles/common/home/waybar.nix - { config, lib, ... }: + { config, lib, pkgs, ... }: { programs.waybar = { enable = true; - # systemd.enable = true; + systemd = { + enable = true; + target = "sway-sessions.target"; + }; settings = { mainBar = { layer = "top"; position = "top"; modules-left = [ "sway/workspaces" "custom/outer-right-arrow-dark" "sway/window" ]; - modules-center = [ "sway/mode" "custom/configwarn" ]; + modules-center = [ "sway/mode" "custom/configwarn" "custom/nix-updates" ]; "sway/mode" = { format = "{}"; }; @@ -7873,7 +7989,7 @@ Currently, I am too lazy to explain every option here, but most of it is very se wayland.windowManager.sway = { enable = true; checkConfig = false; # delete this line once SwayFX is fixed upstream - package = lib.mkIf config.swarselsystems.isNixos pkgs.swayfx; + package = lib.mkIf config.swarselsystems.isNixos null; systemd = { enable = true; xdgAutostart = true; @@ -8002,7 +8118,7 @@ Currently, I am too lazy to explain every option here, but most of it is very se { title = "(?:Open|Save) (?:File|Folder|As)"; } { title = "^Add$"; } { title = "com-jgoodies-jdiskreport-JDiskReport"; } - { app_id = "discord"; } + { app_id = "vesktop"; } { window_role = "pop-up"; } { window_role = "bubble"; } { window_role = "dialog"; } @@ -8067,7 +8183,7 @@ Currently, I am too lazy to explain every option here, but most of it is very se { command = "resize set width 60 ppt height 60 ppt, sticky enable"; criteria = { - app_id = "discord"; + app_id = "vesktop"; }; } { @@ -12016,7 +12132,7 @@ Special things to note here: We are running xcape to allow =CAPS= to act as =CTR startup = [ { command = "sleep 60 && nixGL nextcloud --background";} # { command = "sleep 60 && nixGL spotify";} - { command = "sleep 60 && nixGL discord --start-minimized -enable-features=UseOzonePlatform -ozone-platform=wayland";} + { command = "sleep 60 && nixGL vesktop --start-minimized -enable-features=UseOzonePlatform -ozone-platform=wayland";} # { command = "sleep 60 && nixGL schildichat-desktop --hidden";} { command = "sleep 60 && nixGL syncthingtray --wait"; } { command = "sleep 60 && ANKI_WAYLAND=1 nixGL anki";} diff --git a/modules/home/nixos.nix b/modules/home/nixos.nix index d93b6ac..9810c75 100644 --- a/modules/home/nixos.nix +++ b/modules/home/nixos.nix @@ -5,7 +5,7 @@ { command = "sleep 60 && nixGL nextcloud --background"; } - { command = "sleep 60 && nixGL discord --start-minimized -enable-features=UseOzonePlatform -ozone-platform=wayland"; } + { command = "sleep 60 && nixGL vesktop --start-minimized -enable-features=UseOzonePlatform -ozone-platform=wayland"; } { command = "sleep 60 && nixGL syncthingtray --wait"; } { command = "sleep 60 && ANKI_WAYLAND=1 nixGL anki"; } { command = "nm-applet --indicator"; } diff --git a/modules/home/startup.nix b/modules/home/startup.nix index 160a6ff..c7710df 100644 --- a/modules/home/startup.nix +++ b/modules/home/startup.nix @@ -8,7 +8,7 @@ in type = types.listOf (types.attrsOf types.str); default = [ { command = "nextcloud --background"; } - { command = "discord --start-minimized"; } + { command = "vesktop --start-minimized"; } { command = "element-desktop --hidden -enable-features=UseOzonePlatform -ozone-platform=wayland --disable-gpu-driver-bug-workarounds"; } { command = "ANKI_WAYLAND=1 anki"; } { command = "OBSIDIAN_USE_WAYLAND=1 obsidian"; } diff --git a/pkgs/swarselcheck/default.nix b/pkgs/swarselcheck/default.nix index 1856c74..afe7d44 100644 --- a/pkgs/swarselcheck/default.nix +++ b/pkgs/swarselcheck/default.nix @@ -1,7 +1,7 @@ -{ writeShellApplication, kitty, element-desktop-wayland, discord, spotify-player, sway, jq }: +{ writeShellApplication, kitty, element-desktop-wayland, vesktop, spotify-player, sway, jq }: writeShellApplication { name = "swarselcheck"; - runtimeInputs = [ kitty element-desktop-wayland discord spotify-player jq ]; + runtimeInputs = [ kitty element-desktop-wayland vesktop spotify-player jq ]; text = builtins.readFile ../../scripts/swarselcheck.sh; } diff --git a/profiles/TEMPLATE/home.nix b/profiles/TEMPLATE/home.nix index ce2d860..22af825 100644 --- a/profiles/TEMPLATE/home.nix +++ b/profiles/TEMPLATE/home.nix @@ -121,7 +121,7 @@ startup = [ { command = "nextcloud --background"; } - { command = "discord --start-minimized"; } + { command = "vesktop --start-minimized"; } { command = "element-desktop --hidden -enable-features=UseOzonePlatform -ozone-platform=wayland --disable-gpu-driver-bug-workarounds"; } { command = "ANKI_WAYLAND=1 anki"; } { command = "OBSIDIAN_USE_WAYLAND=1 obsidian"; } diff --git a/profiles/common/home/sway.nix b/profiles/common/home/sway.nix index b278d39..e2d872a 100644 --- a/profiles/common/home/sway.nix +++ b/profiles/common/home/sway.nix @@ -16,7 +16,7 @@ in wayland.windowManager.sway = { enable = true; checkConfig = false; # delete this line once SwayFX is fixed upstream - package = lib.mkIf config.swarselsystems.isNixos pkgs.swayfx; + package = lib.mkIf config.swarselsystems.isNixos null; systemd = { enable = true; xdgAutostart = true; @@ -112,6 +112,7 @@ in Return = "mode default"; Right = "resize grow width 10 px or 10 ppt"; Up = "resize shrink height 10 px or 10 ppt"; + Tab = "move position center, resize set width 50 ppt height 50 ppt"; }; }; defaultWorkspace = "workspace 1:δΈ€"; @@ -147,7 +148,7 @@ in { title = "(?:Open|Save) (?:File|Folder|As)"; } { title = "^Add$"; } { title = "com-jgoodies-jdiskreport-JDiskReport"; } - { app_id = "discord"; } + { app_id = "vesktop"; } { window_role = "pop-up"; } { window_role = "bubble"; } { window_role = "dialog"; } @@ -212,7 +213,7 @@ in { command = "resize set width 60 ppt height 60 ppt, sticky enable"; criteria = { - app_id = "discord"; + app_id = "vesktop"; }; } { @@ -255,23 +256,26 @@ in in " exec_always autotiling - set $exit \"exit: [s]leep, [p]oweroff, [r]eboot, [l]ogout\" + set $exit \"exit: [s]leep, [l]ock, [p]oweroff, [r]eboot, [u]ser logout\" mode $exit { bindsym --to-code { s exec \"systemctl suspend\", mode \"default\" + l exec \"swaylock --screenshots --clock --effect-blur 7x5 --effect-vignette 0.5:0.5 --fade-in 0.2 --daemonize && systemctl suspend \", mode \"default \" p exec \"systemctl poweroff\" r exec \"systemctl reboot\" - l exec \"swaymsg exit\" + u exec \"swaymsg exit\" Return mode \"default\" Escape mode \"default\" - ${modifier}+x mode \"default\" + ${modifier}+Escape mode \"default\" } } exec systemctl --user import-environment + + ${swayfxSettings} "; diff --git a/profiles/common/home/waybar.nix b/profiles/common/home/waybar.nix index 50ad52c..70b85e3 100644 --- a/profiles/common/home/waybar.nix +++ b/profiles/common/home/waybar.nix @@ -1,15 +1,18 @@ -{ config, lib, ... }: +{ config, lib, pkgs, ... }: { programs.waybar = { enable = true; - # systemd.enable = true; + systemd = { + enable = true; + target = "sway-sessions.target"; + }; settings = { mainBar = { layer = "top"; position = "top"; modules-left = [ "sway/workspaces" "custom/outer-right-arrow-dark" "sway/window" ]; - modules-center = [ "sway/mode" "custom/configwarn" ]; + modules-center = [ "sway/mode" "custom/configwarn" "custom/nix-updates" ]; "sway/mode" = { format = "{}"; }; diff --git a/profiles/common/nixos/hardware.nix b/profiles/common/nixos/hardware.nix index 512bb5d..456cff3 100644 --- a/profiles/common/nixos/hardware.nix +++ b/profiles/common/nixos/hardware.nix @@ -14,8 +14,10 @@ keyboard.qmk.enable = true; + + pulseaudio = { - enable = true; + enable = lib.mkIf (!config.services.pipewire.enable) true; package = pkgs.pulseaudioFull; }; diff --git a/profiles/common/nixos/pipewire.nix b/profiles/common/nixos/pipewire.nix new file mode 100644 index 0000000..b557f03 --- /dev/null +++ b/profiles/common/nixos/pipewire.nix @@ -0,0 +1,14 @@ +_: { + security.rtkit.enable = true; # this is required for pipewire real-time access + + services.pipewire = { + enable = true; + pulse.enable = true; + jack.enable = true; + audio.enable = true; + alsa = { + enable = true; + support32Bit = true; + }; + }; +} diff --git a/profiles/common/nixos/safeeyes.nix b/profiles/common/nixos/safeeyes.nix new file mode 100644 index 0000000..5c5959d --- /dev/null +++ b/profiles/common/nixos/safeeyes.nix @@ -0,0 +1,4 @@ +_: +{ + services.safeeyes.enable = true; +} diff --git a/profiles/common/nixos/sway.nix b/profiles/common/nixos/sway.nix new file mode 100644 index 0000000..e3a3031 --- /dev/null +++ b/profiles/common/nixos/sway.nix @@ -0,0 +1,26 @@ +{ pkgs, ... }: +{ + + programs.sway = { + enable = true; + package = pkgs.swayfx; + wrapperFeatures = { + base = true; + gtk = true; + }; + + extraOptions = [ + "--unsupported-gpu" + ]; + + extraSessionCommands = '' + export XDG_SESSION_DESKTOP=sway + export SDL_VIDEODRIVER=wayland + export QT_QPA_PLATFORM=wayland-egl + export QT_WAYLAND_DISABLE_WINDOWDECORATION=1 + export MOZ_ENABLE_WAYLAND=1 + export MOZ_DISABLE_RDD_SANDBOX=1 + ''; + }; + +} diff --git a/profiles/common/nixos/xdg-portal.nix b/profiles/common/nixos/xdg-portal.nix new file mode 100644 index 0000000..88729d4 --- /dev/null +++ b/profiles/common/nixos/xdg-portal.nix @@ -0,0 +1,19 @@ +{ pkgs, ... }: +{ + + xdg.portal = { + enable = true; + config = { + common = { + default = "wlr"; + }; + }; + wlr.enable = true; + wlr.settings.screencast = { + output_name = "eDP-1"; + chooser_type = "simple"; + chooser_cmd = "${pkgs.slurp}/bin/slurp -f %o -or"; + }; + }; + +} diff --git a/scripts/swarselcheck.sh b/scripts/swarselcheck.sh index a695ff5..fc9ef26 100644 --- a/scripts/swarselcheck.sh +++ b/scripts/swarselcheck.sh @@ -1,6 +1,6 @@ kitty=0 element=0 -discord=0 +vesktop=0 spotifyplayer=0 while :; do case ${1:-} in @@ -8,7 +8,7 @@ while :; do ;; -e|--element) element=1 ;; - -d|--discord) discord=1 + -d|--vesktop) vesktop=1 ;; -s|--spotifyplayer) spotifyplayer=1 ;; @@ -35,12 +35,12 @@ elif [[ $element -eq 1 ]]; then else exec swaymsg '[app_id=Element]' kill fi -elif [[ $discord -eq 1 ]]; then - STR=$(swaymsg -t get_tree | grep discord || true) +elif [[ $vesktop -eq 1 ]]; then + STR=$(swaymsg -t get_tree | grep vesktop || true) if [ "$STR" == "" ]; then - exec discord + exec vesktop else - exec swaymsg '[app_id=discord]' kill + exec swaymsg '[app_id=vesktop]' kill fi elif [[ $spotifyplayer -eq 1 ]]; then STR=$(swaymsg -t get_tree | jq -r 'recurse(.nodes[]) | select(.name == "__i3_scratch")' | grep spotifytui || true)