@@ -1,10 +1,12 @@
11{ config, pkgs ,lib ,... }:
2+
23with lib;
4+
35{
46 options.xdg.portal = {
57 enable =
68 mkEnableOption "<link xlink:href='https://github.com/flatpak/xdg-desktop-portal'>xdg desktop integration</link>"//{
7− default = config.services.xserver.enable;
9+ default = false;
810 };
911
1012 extraPortals = mkOption {
@@ -19,6 +21,17 @@ with lib;
1921 environments you probably want to add them yourself.
2022 '';
2123 };
24+
25+ gtkUsePortal = mkOption {
26+ type = types.bool;
27+ default = false;
28+ description = ''
29+ Sets environment variable <literal>GTK_USE_PORTAL</literal> to <literal>1</literal>.
30+ This is needed for packages ran outside Flatpak to respect and use XDG Desktop Portals.
31+ For example, you'd need to set this for non-flatpak Firefox to use native filechoosers.
32+ Defaults to <literal>false</literal> to respect its opt-in nature.
33+ '';
34+ };
2235 };
2336
2437 config =
@@ -28,10 +41,17 @@ with lib;
2841
2942 in mkIf cfg.enable {
3043
44+ assertions = [
45+ { assertion = (cfg.gtkUsePortal -> cfg.extraPortals != []);
46+ message = "Setting xdg.portal.gtkUsePortal to true requires a portal implementation in xdg.portal.extraPortals such as xdg-desktop-portal-gtk or xdg-desktop-portal-kde.";
47+ }
48+ ];
49+
3150 services.dbus.packages = packages;
3251 systemd.packages = packages;
52+
3353 environment.variables = {
34− GTK_USE_PORTAL = "1";
54+ GTK_USE_PORTAL = optional cfg.gtkUsePortal "1";
3555 XDG_DESKTOP_PORTAL_PATH = map (p: "${p}/share/xdg-desktop-portal/portals") cfg.extraPortals;
3656 };
3757 };