Open cjuniorfox opened 1 month ago
@gschintgen can you verify if this works for flatpak?
@cjuniorfox this should probably be a PR instead of an issue
@cjuniorfox The manual setup steps you're linking to, including the setcap, are not needed for most package types. The current doc of the pre-releases reads as follows:
The deb, rpm, zst, Flatpak and AppImage packages should handle the steps below automatically. (...) setcap
But the page is indeed difficult to read.
I tried your proposed command to run setcap
on the binary installed via flatpak, but unfortunately flatpak's sandboxing seems to do its job well...
$ flatpak list
Name Application ID Version Branch Origin Installation
LizardByte dev.lizardbyte.app.Sunshine 0.23.1 master sunshine-origin system
(...)
$ sudo setcap cap_sys_admin+p $(readlink -f $(find /var/lib/flatpak/app -name sunshine | grep /bin/sunshine))
$ flatpak run dev.lizardbyte.app.Sunshine
Config exists in both "/home/myusername/.config/sunshine" and "/home/myusername/.var/app/dev.lizardbyte.app.Sunshine/config/sunshine". Using "/home/myusername/.var/app/dev.lizardbyte.app.Sunshine/config/sunshine" for config
It is recommended to remove "/home/myusername/.config/sunshine"
[av1_mode] -- [1]
[encoder] -- [vaapi]
[global_prep_cmd] -- [[{"do":"sh -c \"xrandr --output DP-2 --mode \\\"${SUNSHINE_CLIENT_WIDTH}x${SUNSHINE_CLIENT_HEIGHT}\\\" --rate ${SUNSHINE_CLIENT_FPS}\"","undo":"xrandr --output DP-2 --mode 2560x1440 --rate 170"}]]
[address_family] -- [both]
[capture] -- [kms]
[wan_encryption_mode] -- [2]
[2024:07:13:23:30:02]: Info: Sunshine version: v2024.713.195308
[2024:07:13:23:30:02]: Error: Failed to gain CAP_SYS_ADMIN
[2024:07:13:23:30:02]: Info: /dev/dri/card0 -> i915
[2024:07:13:23:30:02]: Error: Failed to gain CAP_SYS_ADMIN
[2024:07:13:23:30:02]: Info: /dev/dri/card1 -> amdgpu
[2024:07:13:23:30:02]: Error: Failed to gain CAP_SYS_ADMIN
[2024:07:13:23:30:02]: Error: Couldn't get handle for DRM Framebuffer [142]: Probably not permitted
(...)
$ getcap -r /var/lib/flatpak/app
/var/lib/flatpak/app/dev.lizardbyte.app.Sunshine/x86_64/master/a2fac4d93e7e01ae7b49daa977ea01005a8191dca7e0f4ae6dd976149b342f47/files/bin/sunshine-v2024.713.195308 cap_sys_admin=p
(That's on Ubuntu 22.04.4.)
I don't think it's possible to use setcap on a flatpak. That's a flatpak design choice. See here for example: https://github.com/flathub/org.wireshark.Wireshark/issues/4 or this: https://github.com/flatpak/flatpak/issues/4757#issuecomment-1044595270
It is possible to use flatpak sunshine without all those setcap/sudo shenanigans, just not with direct KMS/DRM based capture.
Unfortunately KMS is the only universal capture method implemented by Sunshine and as such it's the default. But there are only hackish ways to make it work via flatpak, if at all. Maybe official KMS support could even be dropped for the flatpak? Currently the docs just state
Caution: Use distro-specific packages instead of the Flatpak if they are available.
and then the troublesome sudo ... pactl ...
incantation.
(BTW there are binaries for Fedora 40... You definitely should use those.)
@ReenigneArcher It's weird to have the app listed as "LizardByte" instead of "Sunshine" and the version shown by flatpak list
does not correspond to the actual pre-release version of the included binary. And if a user is having trouble with a flatpak build and notices that there are two different flatpaks they easily end up with the following:
$ flatpak list
Name Application ID Version Branch Origin Installation
LizardByte dev.lizardbyte.app.Sunshine 0.23.1 master sunshine-origin system
LizardByte dev.lizardbyte.app.Sunshine 0.23.1 stable flathub system
$ readlink -f $(find /var/lib/flatpak/app -name sunshine | grep /bin/sunshine)
/var/lib/flatpak/app/dev.lizardbyte.app.Sunshine/x86_64/master/a2fac4d93e7e01ae7b49daa977ea01005a8191dca7e0f4ae6dd976149b342f47/files/bin/sunshine-v2024.713.195308
/var/lib/flatpak/app/dev.lizardbyte.app.Sunshine/x86_64/stable/29ac9cf79fd5feefa05ef6190da9265be291136aef27b07fc0bceeb10e8b72c3/files/bin/sunshine-0.23.1.8b21db6.dirty
@gschintgen I agree that is weird. It must be coming from the "Developer Name" field: https://github.com/flathub/dev.lizardbyte.app.Sunshine/blob/92198b56b9dab2f47ad1734e2a2d1afd1c542e66/dev.lizardbyte.app.Sunshine.metainfo.xml#L51
@gschintgen I agree that is weird. It must be coming from the "Developer Name" field: https://github.com/flathub/dev.lizardbyte.app.Sunshine/blob/92198b56b9dab2f47ad1734e2a2d1afd1c542e66/dev.lizardbyte.app.Sunshine.metainfo.xml#L51
Seems to be a flatpak issue: https://github.com/flatpak/flatpak/issues/5700 (apparently fixed)
I tried to install the RPM package on my Fedora 40 but it didn't work because I'm using the Silverblue Atomic-like version of Fedora. It's one that I created on top of the uBlue project. Feel free to try yourself my Hyprland version if you'd like to. hyprland-atomic-x86_64-40-latest.iso hyprland-atomic-x86_64-40-latest.iso-CHECKSUM
I was trying to install the rpm using rpm-ostree install file.rpm
, but gives me an Exit status = 1
on some post-script routine that I didn't look for the motive.
To address the problem. I wrote these two systemd units and is working pretty well. Could be a suggestion for the documentation. Maybe I try a PR with it.
/etc/systemd/system/sunshine-setcap.service
[Unit]
Description=Self-hosted game stream host for Moonlight
[Service]
Type=oneshot
Environment=LANG=en_US.UTF-8
ExecStart=/usr/bin/bash -c '/usr/sbin/setcap cap_sys_admin+p $(readlink -f $(/usr/bin/find /var/lib/flatpak/app -name sunshine | /usr/bin/grep /bin/sunshine)); /usr/bin/touch /var/run/sunshine-setcap-done'
[Install]
WantedBy=multi-user.target
~/.config/systemd/user/sunshine.service
[Unit]
Description=Self-hosted game stream host for Moonlight
StartLimitIntervalSec=500
StartLimitBurst=5
[Service]
Environment=LANG=en_US.UTF-8
ExecStartPre=/bin/bash -c 'while [ ! -f /var/run/sunshine-setcap-done ]; do echo "Waiting for sunshine-setcap.service to complete..."; sleep 5; done; /usr/bin/sleep 5'
ExecStart=/usr/bin/flatpak run dev.lizardbyte.app.Sunshine
ExecStop=/usr/bin/flatpak kill dev.lizardbyte.app.Sunshine
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=xdg-desktop-autostart.target
The last 5-second delay on the sunshine.service
is because of something related to Hyprland, sunshine does not work without it. I don't know if it's strictly needed with any other compositors.
@cjuniorfox, can you confirm if your fix works with Wayland? Or is it X11 only? Because I still see the error when running the flatpak on Wayland
Attention! Sunshine detected these errors during startup. We STRONGLY RECOMMEND fixing them before streaming.
Fatal: You must run [sudo setcap cap_sys_admin+p $(readlink -f $(which sunshine))] for KMS display capture to work!
Fatal: Unable to find display or encoder during startup.
Fatal: Please check that a display is connected and powered on.
@cjuniorfox, can you confirm if your fix works with Wayland? Or is it X11 only? Because I still see the error when running the flatpak on Wayland
Attention! Sunshine detected these errors during startup. We STRONGLY RECOMMEND fixing them before streaming. Fatal: You must run [sudo setcap cap_sys_admin+p $(readlink -f $(which sunshine))] for KMS display capture to work! Fatal: Unable to find display or encoder during startup. Fatal: Please check that a display is connected and powered on.
Because of the path for the application inside the Flatpak sandboxing, you need to do the mentioned command, but with the binary executable inside the Flatpak instead of /bin/sunshine
. You need to run the command on every boot, and yes, the mentioned works with Wayland. I'm currently using Hyprland.
'/usr/sbin/setcap cap_sys_admin+p $(readlink -f $(/usr/bin/find /var/lib/flatpak/app -name sunshine | /usr/bin/grep /bin/sunshine)); /usr/bin/touch /var/run/sunshine-setcap-done'
Thanks for your reply! Can you confirm the following which might help be debug issues on my end:
cat ~/.local/share/flatpak/overrides/dev.lizardbyte.app.Sunshine
sudo -i PULSE_SERVER=unix:$(pactl info | awk '/Server String/{print$3}') \
flatpak run dev.lizardbyte.app.Sunshine
I've tested this on Fedora Kinoite 40 and Aurora DX (Universal Blue's custom Kinoite image)
I did try that using the two systemd units from your earlier post, but I'm still seeing the same error. After a reboot, I see the /var/run/sunshine-setcap-done
file was successfully created and sunshine starts up after the 5 second delay. However, KMS capture doesn't work.
Attention! Sunshine detected these errors during startup. We STRONGLY RECOMMEND fixing them before streaming.
Fatal: You must run [sudo setcap cap_sys_admin+p $(readlink -f $(which sunshine))] for KMS display capture to work! If you installed from AppImage or Flatpak, please refer to the official documentation: https://docs.lizardbyte.dev/projects/sunshine/en/latest/about/setup.html#install
Fatal: Unable to find display or encoder during startup.
Fatal: Please check that a display is connected and powered on.
I also tried running the setcap and flatpak run commands manually like this, which didn't help either:
sudo setcap cap_sys_admin+p $(readlink -f $(find /var/lib/flatpak/app -name sunshine | grep /bin/sunshine))
flatpak run dev.lizardbyte.app.Sunshine
Is there an existing issue for this?
Is your issue described in the documentation?
Is your issue present in the latest beta/pre-release?
This issue is present in the latest pre-release
Describe the Bug
Documentation bug. At that doc, fix the instruction about kms_capture:
from
sudo setcap cap_sys_admin+p $(readlink -f $(which sunshine))
tosudo setcap cap_sys_admin+p $(readlink -f $(find /var/lib/flatpak/app -name sunshine | grep /bin/sunshine))
Is also worth mentioning that the user needs to run the command on every boot and update the "Home" page from Sunshine instance.
Expected Behavior
Being able to run sunshine accordingly using flatpak
Additional Context
No response
Host Operating System
Linux
Operating System Version
Fedora 40 - 6.9.7-200.fc40.x86_64
Architecture
64 bit
Sunshine commit or version
[2024:07:13:00:56:24]: Info: Sunshine version: v2024.710.151651
Package
Linux - flatpak
GPU Type
AMD
GPU Model
RX 6700 XT
GPU Driver/Mesa Version
GLX_MESA_query_renderer 24.1.2
Capture Method
wlroots (Linux)
Config
Apps
Relevant log output