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

nixos/portals: point $XDG_DESKTOP_PORTAL_DIR at the current system #186857

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nixos/modules/config/xdg/portal.nix
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ in
# share/applications/*.desktop files
# see https://github.com/NixOS/nixpkgs/issues/145174
systemPackages = [ joinedPortals ];
pathsToLink = [ "/share/applications" ];
inherit (joinedPortals) pathsToLink;

sessionVariables = {
GTK_USE_PORTAL = mkIf cfg.gtkUsePortal "1";
XDG_DESKTOP_PORTAL_DIR = "${joinedPortals}/share/xdg-desktop-portal/portals";
XDG_DESKTOP_PORTAL_DIR = "/run/current-system/sw/share/xdg-desktop-portal/portals";
Copy link
Contributor

@kira-bruneau kira-bruneau Oct 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! 🙂 It looks like my PR to change this to use sessionVariables introduced this problem.

I wonder if maybe we should just set the variable directly on the systemd service as an override, rather than trying to set it globally:

diff --git a/nixos/modules/config/xdg/portal.nix b/nixos/modules/config/xdg/portal.nix
index e28ff74e5d80..c6ce43c03c3e 100644
--- a/nixos/modules/config/xdg/portal.nix
+++ b/nixos/modules/config/xdg/portal.nix
@@ -84,7 +84,16 @@ in
       ];
 
       services.dbus.packages = packages;
-      systemd.packages = packages;
+
+      systemd = {
+        inherit packages;
+        user.services.xdg-desktop-portal = {
+          restartIfChanged = true;
+          environment = {
+            XDG_DESKTOP_PORTAL_DIR = "${joinedPortals}/share/xdg-desktop-portal/portals";
+          };
+        };
+      };
 
       environment = {
         # fixes screen sharing on plasmawayland on non-chromium apps by linking
@@ -92,10 +101,8 @@ in
         # see https://github.com/NixOS/nixpkgs/issues/145174
         systemPackages = [ joinedPortals ];
         pathsToLink = [ "/share/applications" ];
-
-        sessionVariables = {
+        variables = {
           GTK_USE_PORTAL = mkIf cfg.gtkUsePortal "1";
-          XDG_DESKTOP_PORTAL_DIR = "${joinedPortals}/share/xdg-desktop-portal/portals";
         };
       };
     };

That way it's more self-contained, and still updates on rebuilds.

@Atemu With your fix, do the portal changes get applied without restarting the service? It looks like the portals are loaded in main through load_installed_portals and wouldn't be reloaded if the path changes while it's running.

@jtojnar I'm pretty sure XDG_DATA_PORTAL_DIRS is only used by xdg-desktop-portal.service, do you know if there would be any impact by not exporting this globally?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restarting the service is a good idea but I think we should still keep the environment variable around globally to account for people's custom setups.

Copy link
Member

@jtojnar jtojnar Oct 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think the environment variable is only used for dispatch by x-d-p.

I like the self-contained approach more. The possibility of breaking custom setups is unfortunate but reliance on a global variable is breaking custom configs as well, requiring hacks like this:

https://github.com/lilyinstarlight/foosteros/blob/78110a51c9066020cb21b662fbd48768ea5a7501/modules/nixos/programs/sway.nix#L13

I have seen several people on Matrix confused by x-d-p not receiving the variable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If users truly need the variable, they can actually set it themselves because xdp are now in the global share. I'll try to get it into the user service but I don't know how well that will turn out since we don't actually generate it ourselves.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For existing services, the NixOS module will just use systemd “drop-in” overrides, see https://www.freedesktop.org/software/systemd/man/systemd.unit.html.

};
};
};
Expand Down