This made Gnome Shell startup very slow (~ 1 minute from entering the password to getting desktop ready) and didn’t fix the sharing problem.
By switching to an old generation of Home Manager (from March 5, so more than a month ago) I got the screen sharing to work. One difference between now and then is the version of Firefox (it was 85.2 and current is 87.0). I’ve also found a thread on Arch forum that suggests that the version of Firefox might be the problem. I’d like to probe it. How can I downgrade Firefox while keeping the rest of my system the same?
Thanks @igel. Based on your suggestion I’ve used the https://lazamar.co.uk/nix-versions/ website to find the right commit and I’ve been able to run Firefox 85.0.1. With this previous version the screen sharing works as expected.
Screen sharing still doesn’t work after upgrading to Firefox 88.
To make my life easier I figured out a one-liner to launch Firefox 85 (where screen sharing works) along side whatever version is installed by default. I’m sharing it in case someone else is also struggling with this issue:
The -P option is for setting profile by name (somewhat confusingly --profile sets it by path). First time you run it, it will open a profile manager because there is no wayland-screen-sharing-downgrade profile yet. Just create it. Next time it will run without asking. Using separate profile is important, because the new version may be incompatible with the old. I ran into weird problems and I think that was the reason.
Since it’s technically a different browser than the one you have installed, it will also ask to set it as default. That’s probably not what you want.
It’s a workaround and I still hope to find a proper fix.
I just got it working, apparently by moving Firefox from ~/.config/nixpkgs/home.nix to /etc/nixos/configuration.nix. Perhaps the issue was caused by using 20.09 channel for NixOS and unstable for Home Manager.
It was @abdillah who inspired me to try this. Although I already had pipewire enabled in configuration.nix I thought that since it’s using a different channel than Home Manager there might be some incompatibility.
The way it works now is a bit wonky. After I select the screen to share once the sharing doesn’t start. Instead the same selection dialog appears - sometimes immediately, sometimes with a delay of up to few seconds. Sometimes it appears below the main Firefox window and I have to “dig it up”. After selecting the screen again the sharing starts.
I consider this good enough. Thanks to everyone who offered their help.