How can I use miracast in NixOS?

I’m trying the following configuration:

{ pkgs, ... }: 
  environment.systemPackages = with pkgs; [

  xdg.portal.enable = true;

  xdg.portal.xdgOpenUsePortal = true;
  xdg.portal.extraPortals = [

  networking.firewall.trustedInterfaces = [ "p2p-wl+" ];

  networking.firewall.allowedTCPPorts = [ 7236 7250 ];
  networking.firewall.allowedUDPPorts = [ 7236 5353 ];

But it’s not working: I can enter the GUI, and the scan is success so I can see my XiaoMi TV listed, but when I select it, an error occurs.

I have tried gnome-network-displays on both Gnome and KDE, but neither of them works. There must be some tricks I have not found yet, hoping for some help.

Is it possible miracast is trying to use other, blocked, ports? You could try stopping the firewall (systemctl stop firewall) to see if it then works.


I disabled firewall, and still get the following errors (on KDE):

$ gnome-network-displays                                                                                                                      139 ↵
Gtk-Message: 23:07:26.085: Failed to load module "appmenu-gtk-module"

** (gnome-network-displays:56702): WARNING **: 23:07:26.191: Error initing screencast portal: Failed to create portal session (response: 2)

** (gnome-network-displays:56702): WARNING **: 23:07:26.191: Falling back to X11! You need to fix your setup to avoid issues (XDG Portals and/or mutter screencasting support)!
[1]    56702 segmentation fault (core dumped)  gnome-network-displays

This looks like a portal issue. KDE and Gnome have their own portals. Have you tried casting from Gnome instead of KDE? Or using a KDE alternative?

Are you using Wayland?

1 Like

I have tried both KDE/Gnome, and both X11/Wayland, None of the 4 combinations work.

I’m not sure which step I’m doing wrong, It will be very helpful if someone can share a working nixos configuration.

What’s the log output of gnome-network-displays on GNOME Wayland?