xdg-desktop-portal: Use custom variable for finding portals

x-d-p only looks for portal definitions in one of two places:
- datadir (which we cannot install anything to, since Nix packages are immutable)
- when `XDG_DESKTOP_PORTAL_DIR` environment variable is set, the path specified therein
  (meant for tests, disables looking for portal configuration anywhere else)

Let’s introduce our own `NIX_XDG_DESKTOP_PORTAL_DIR` environment variable
that will only control the portal definitions lookup.
We will not use it for searching for configuration
because it would require looking in the parent directory
and `XDG_CONFIG_DIRS` variable is sufficient for us.
This commit is contained in:
Jan Tojnar 2023-11-18 00:35:54 +01:00
commit 3b2f55e89f
4 changed files with 27 additions and 52 deletions

View file

@ -119,19 +119,12 @@ in
let
cfg = config.xdg.portal;
packages = [ pkgs.xdg-desktop-portal ] ++ cfg.extraPortals;
configPackages = cfg.configPackages;
joinedPortals = pkgs.buildEnv {
name = "xdg-portals";
paths = packages;
pathsToLink = [ "/share/xdg-desktop-portal/portals" "/share/applications" ];
};
joinedPortalConfigs = pkgs.buildEnv {
name = "xdg-portal-configs";
paths = configPackages;
pathsToLink = [ "/share/xdg-desktop-portal" ];
};
in
mkIf cfg.enable {
warnings = lib.optional (cfg.configPackages == [ ] && cfg.config == { }) ''
@ -158,17 +151,20 @@ in
systemd.packages = packages;
environment = {
# fixes screen sharing on plasmawayland on non-chromium apps by linking
# share/applications/*.desktop files
# see https://github.com/NixOS/nixpkgs/issues/145174
systemPackages = [ joinedPortals ];
pathsToLink = [ "/share/applications" ];
systemPackages = [
joinedPortals
] ++ cfg.configPackages;
pathsToLink = [
# Upstream desktop environment portal configurations.
"/share/xdg-desktop-portal"
# .desktop files to register fallback icon and app name.
"/share/applications"
];
sessionVariables = {
GTK_USE_PORTAL = mkIf cfg.gtkUsePortal "1";
NIXOS_XDG_OPEN_USE_PORTAL = mkIf cfg.xdgOpenUsePortal "1";
XDG_DESKTOP_PORTAL_DIR = "${joinedPortals}/share/xdg-desktop-portal/portals";
NIXOS_XDG_DESKTOP_PORTAL_CONFIG_DIR = mkIf (cfg.configPackages != [ ]) "${joinedPortalConfigs}/share/xdg-desktop-portal";
NIX_XDG_DESKTOP_PORTAL_DIR = "${joinedPortals}/share/xdg-desktop-portal/portals";
};
etc = lib.concatMapAttrs