Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xdg-portal: add new module #4707

Merged
merged 1 commit into from
Jan 3, 2024
Merged

Conversation

Misterio77
Copy link
Contributor

@Misterio77 Misterio77 commented Nov 27, 2023

Description

Adds xdg.portal options. Fixes #1167

Most of it came from the equivalent NixOS module, with a few changes to work here.


The xdg-desktop-portal receives requests and forwards them to the right portal, based on:

  • Configurations
    • Provided by the user ({~/.config,etc}/xdg-desktop-portal) and/or DE (i.e. $prefix/share/xdg-desktop-portal).
    • Can be global (portals.conf) or per-DE foo-portals.conf
  • Portal definitions
    • Each portal has one specifying what they provide

The idea is that, to get working portals, we must:

  • Have xdg-desktop-portal.service running (or simply available to be started via dbus). It must be able to find:
    • Portal definitions (provided by the portal packages themselves):
      • They are only looked at a build-time defined dir (usually /etc, but for us this is not really useful), as well as $XDG_DESKTOP_PORTAL_DIR (which is what we'll set)
    • Portal configs (either user provided, or DEs):
      • If starting xdg-desktop-portal on your shell, adding DEs to home.packages currently works, as it looks on $XDG_DATA_DIR (which the respective configs are linked to).
      • For our systemd unit, it's better to use $NIXOS_XDG_DESKTOP_PORTAL_CONFIG_DIR, provided by nixpkgs' patches
  • Have our relevant portals (e.g. xdg-desktop-portal-foo.services) available (also started via dbus)

With this module, flipping xdg.portal.enable should provide a xdg-desktop-portal service unit, which should be able to locate and start portals listed on xdg.portal.extraPortals; and be controlled by portal configs provided by packages (i.e. DEs) listed on xdg.portal.configPackages, and a user defined xdg.portal.config. An example for hyprland:

{
  xdg.portal = {
    enable = true;
    extraPortals = [ pkgs.xdg-desktop-portal-hyprland pkgs.xdg-desktop-portal-gtk ];
    configPackages = [ pkgs.hyprland ];
  };
}

To illustrate xdg.portal.config, suppose you prefer to override Hyprland's provided .conf and use xdg-desktop-portal-wlr instead:

{
  xdg.portal = {
    enable = true;
    extraPortals = [ pkgs.xdg-desktop-portal-wlr pkgs.xdg-desktop-portal-gtk ];
    config.hyprland.default = [ "wlr" "gtk" ];
  };
}

Checklist

  • Change is backwards compatible.

  • Code formatted with ./format.

  • Code tested through nix-shell --pure tests -A run.all or nix develop --ignore-environment .#all using Flakes.

  • Test cases updated/added. See example.

  • Commit messages are formatted like

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

  • If this PR adds a new module

    • Added myself as module maintainer. See example.

Maintainer CC

@Misterio77 Misterio77 force-pushed the xdg-portal branch 4 times, most recently from afdcd0e to 46822da Compare November 28, 2023 00:23
@nyabinary
Copy link

xdg portal support can also lead to flatpak being managed via hm right? #4621

@Misterio77 Misterio77 force-pushed the xdg-portal branch 3 times, most recently from 7c1551d to 4d8788b Compare November 28, 2023 19:17
NovaViper added a commit to NovaViper/NixConfig that referenced this pull request Dec 2, 2023
- Re-enabled nh, fixed with viperML/nh/issues/37
- Changed Dolphin layout agian
- Made zsh history substring search use $terminfo keys
- Added Misterio77's xdg-portal HM plugin, nix-community/home-manager/pull/4707
- Reorganized and removed redundant code to make the flake more readable
- Made HomeManager generate nixpkgs/config.nix in order to properly retrieve custom nixpkgs settings again
- Updated desktop partition ids due to reinstall
- Added settings for gamemode
- Removed gamescope
- Python packages now available from Python 3.11
@NovaViper
Copy link
Contributor

Hey @Misterio77, would it be possible to use this module along with the NixOS module? KDE ignores the user defined xdg portal settings and only considers them if I use the NixOS module to declare them

@nyabinary
Copy link

Is this ready to merge?

@Misterio77
Copy link
Contributor Author

Yup! Should be. Been using this for over a month, with no issues whatsoever.

Lemme just quickly fix the news.nix conflicts.

@rycee rycee merged commit fcbc70a into nix-community:master Jan 3, 2024
3 checks passed
@rycee
Copy link
Member

rycee commented Jan 3, 2024

Great stuff! Merged to master now 🙂

@mightyiam
Copy link
Contributor

Thank you, @Misterio77 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configuring XDG Portals?
6 participants