Configuring xdg-desktop-portal with Home Manager on Ubuntu (Hyprland via nixGL)

Hello everyone,

Nix noob here, I’m running into issues getting xdg-desktop-portal working via Home Manager on Ubuntu (I’m locked to Ubuntu due to work computer). I’m using Home Manager to set up Hyprland through nixGL, and everything else is working well so far, except screen sharing via xdg-desktop-portal. I’d greatly appreciate any guidance on how to properly configure this.


1. Environment & Goal

  • OS: Ubuntu (version ≈ 24.04 LTS)

  • Window manager: Hyprland via home-manager and nixGL

  • Goal: Enable screen sharing (and other portal functionality) by installing and configuring xdg-desktop-portal-hyprland (or an appropriate portal backend) entirely through my Home Manager setup.

  • Gist that I initially used to set up hyprland on ubuntu: AntonFriberg gist


2. Background & References

I believe it’s possible because of:

I’d like to follow the “Home Manager way” instead of manually hacking scripts, so that all my config remains declarative and reproducible.


3. What I Have Tried

  1. Added xdg.portal.enable = true; and included xdg-desktop-portal-hyprland / xdg-desktop-portal-gtk in extraPortals.
    My xdg.portal block currently looks like this:

    xdg.portal = {
      enable = true;
      extraPortals = with pkgs; [
        xdg-desktop-portal-hyprland  
        # (config.lib.nixGL.wrap xdg-desktop-portal-hyprland)
        # xdg-desktop-portal-wlr
        xdg-desktop-portal-gtk
      ];
       configPackages = [ /* pkgs.hyprland */ ];
       config = {
         hyprland.default = [ "hyprland" "gtk" ];
       };
    };
    

    However, I get the following collision error:

    error: collision between
    `/nix/store/kryxh2frhdr8kv97ximfnn3gl9rw040w-xdg-desktop-portal-hyprland-1.3.9/bin/hyprland-share-picker`
    and
    `/nix/store/kzc3zkpg19s9rz681sa90ajkc08c3cqn-xdg-desktop-portal-hyprland-1.3.9/bin/hyprland-share-picker`
    

    (I suspect this is caused by the nixGL wrapper wrapping Hyprland itself?)
    If i do not specify the package i do not get it to work either, not even using wlr i get it to work. So i must be doing something wrong, but i can not figure it out.

  2. Tried alternative portal backends
    I’ve experimented with only xdg-desktop-portal-wlr or only xdg-desktop-portal-gtk, but neither seems to provide the proper Hyprland integration for screen sharing. In particular, Hyprland requires the specialized xdg-desktop-portal-hyprland binary to handle the share picker.

  3. Checked the Hyprland portal repository’s caution
    The hyprwm/xdg-desktop-portal-hyprland README mentions a caution about not using the portal directly without wrapping or additional environment variables. I’m not sure how to translate that advice into a Home Manager expression.


4. Links to My Configs


5. Questions & Request for Help

  1. Recommended Expression:
    What is the correct way to declare and enable xdg-desktop-portal-hyprland entirely via Home Manager? Is there an example snippet that I can adapt?

  2. Resolving the Collision:
    How do I avoid the “collision” between two identical hyprland-share-picker binaries in the store? Should I:

    • Wrap the portal package with nixGL.wrap?
    • Mask one of the binaries using config.xdg.porters.blacklist or a similar Home Manager option?
    • Use a different attribute name or override?
  3. Fallback / Alternative:
    If xdg-desktop-portal-hyprland is not feasible via Home Manager, is there a reliable way to configure Hyprland’s portal manually in conjunction with Home Manager—without losing the reproducibility and “single source of truth” benefits of Home Manager?

I’m grateful for any pointers, example configs, or patch suggestions. Thank you in advance!


Thanks again,
Drakkir

Did you ever solve this?

No, not yet atleast.
I hope to spend some time with it during my vacation. Are you having the same issues?

Hey there! Try doing this and see if it helps:

  xdg.portal = {
    enable = true;
    extraPortals = with pkgs; [
      xdg-desktop-portal-gnome
      xdg-desktop-portal-gtk
    ];
    config = {
      hyprland = {
        default = [ "hyprland" "gtk" ];
        "org.freedesktop.impl.portal.ScreenCast" = [
          "gnome"
        ];
      };
    };
  };

And then restart your entire hyprland session! That is, if it doesn’t work with a simple home-manager switch, try restarting the session (i.e. logging out and logging in again) and see if it works. If it does, congratulations.

Also, if it doesn’t work even after you restarted your session, try wrapping the packages above (xdg-desktop-portal-gnome, xdg-desktop-portal-gtk) in nixGL and retrying. Although I doubt this will be necessary.

Hi,

I couldn’t build your flake, because one of the inputs gave me a 404, so I’m not certain that my advice will work, but I hope it helps.

I suspect that the conflict comes from home-manager already adding the finalPortalPackage to xdg.portal.extraPortals which has an override here. To check/debug which portals have been added I recommend going into your home manager config with a nix repl like this from your flake root.

$ nix repl .#
nix-repl> homeConfigurations.drakkir.config.xdg.portal.extraPortals

I think this should answer your second question because it resolved a similar but different portal package conflict for me.

I got screensharing working on Hyprland (managed by Home Manager) on Ubuntu 22.02 (Jammy). I’ll walkthrough how I got it working, but I’m a newbie to the Nix world, so please bear with me.

Hyprland already install its portal

As you can check in the hyprland module for Home Manager, the module should already be installed if you didn’t change anything when you enabled Hyprland.

You can check if you got it running already with

systemctl --user status xdg-desktop-portal-hyprland

Make sure systemd can find the portal service file

In my case, it wasn’t running - the service wasn’t even found! I had to dig around XDG documentation to understand why, given that the service file was available in the XDG_DATA_DIRS path. For some reason I couldn’t figure out, systemd tries to initiate the service while the env still does not point to nix data dirs.

So, following systemd-user manual, create a file under ~/.config/systemd/user.conf ponting to your usual XDG_DATA_DIRS content. Mine is like this:

[Manager]
ManagerEnvironment="XDG_DATA_DIRS=/usr/local/share:/usr/share:/home/s044207629/.local/state/nix/profile/share:/nix/var/nix/profiles/default/share"

Of course, this cand be done in a declarative manner inside your home.nix. Restart Hyprland and check if the service is running, or try to enable it and verify that the file is found by systemd, now.

There’s no need to wrap the portal package

I noticed that my Hyprland complements do not need to be wrapped in nixGL in order for them to work. I installed the GTK portal because I use many GTK apps, but I don’t think they are strictly needed. Here’s the relevant excerpts from my home.nix:

  wayland.windowManager.hyprland = {
    enable = true;
    package = config.lib.nixGL.wrap pkgs.hyprland;
    extraConfig = builtins.readFile ./hypr/hyprland.conf;
  };
  xdg.portal = {
    enable = true;
    extraPortals = with pkgs; [ xdg-desktop-portal-gtk ];
    config = {
      hyprland = {
        default = [ "hyprland" "gtk" ];
        "org.freedesktop.impl.portal.Secret" = [ "gnome-keyring" ];
      };
    };
  };

Check your plumbing (no, seriously!)

I’m on an old Ubuntu version that didn’t even had wireplumber installed. I installed wireplumber from the default repo, but it was too old: I was able to get to the “Select screen” dialog from Hyprland when screensharing, but still no image appeared.

So, I added the upstream wireplumber repo (ppa:pipewire-debian/wireplumber-upstream), and installed a newer version of wireplumber. Lo and behold, it worked! Make sure to check if everything is up and running with the usual systemctl --user status ... command.

I hope it works out for you!

1 Like

This. On non-nixos, apparently, user systemd starts before home-manager injects XDG_DIRS. Setting user.conf is a workaround but it works. I’ll try to dig in HM if it can be fixed there.

1 Like

Adding the env var in ~/.config/systemd/user.conf worked for me! I’m in the very same situation, Ubuntu 22, home-manager and running hyprland via nixGL. Thanks, celtic