summary refs log tree commit diff
path: root/nixos/modules/config/xdg/portal.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/modules/config/xdg/portal.nix')
-rw-r--r--nixos/modules/config/xdg/portal.nix24
1 files changed, 22 insertions, 2 deletions
diff --git a/nixos/modules/config/xdg/portal.nix b/nixos/modules/config/xdg/portal.nix
index 4e85bf794da..89ddf80b575 100644
--- a/nixos/modules/config/xdg/portal.nix
+++ b/nixos/modules/config/xdg/portal.nix
@@ -1,10 +1,12 @@
 { config, pkgs ,lib ,... }:
+
 with lib;
+
 {
   options.xdg.portal = {
     enable =
       mkEnableOption "<link xlink:href='https://github.com/flatpak/xdg-desktop-portal'>xdg desktop integration</link>"//{
-        default = config.services.xserver.enable;
+        default = false;
       };
 
     extraPortals = mkOption {
@@ -19,6 +21,17 @@ with lib;
         environments you probably want to add them yourself.
       '';
     };
+
+    gtkUsePortal = mkOption {
+      type = types.bool;
+      default = false;
+      description = ''
+        Sets environment variable <literal>GTK_USE_PORTAL</literal> to <literal>1</literal>.
+        This is needed for packages ran outside Flatpak to respect and use XDG Desktop Portals.
+        For example, you'd need to set this for non-flatpak Firefox to use native filechoosers.
+        Defaults to <literal>false</literal> to respect its opt-in nature.
+      '';
+    };
   };
 
   config =
@@ -28,10 +41,17 @@ with lib;
 
     in mkIf cfg.enable {
 
+      assertions = [
+        { assertion = (cfg.gtkUsePortal -> cfg.extraPortals != []);
+          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.";
+        }
+      ];
+
       services.dbus.packages  = packages;
       systemd.packages = packages;
+
       environment.variables = {
-        GTK_USE_PORTAL = "1";
+        GTK_USE_PORTAL = optional cfg.gtkUsePortal "1";
         XDG_DESKTOP_PORTAL_PATH = map (p: "${p}/share/xdg-desktop-portal/portals") cfg.extraPortals;
       };
     };