about summary refs log tree commit diff
path: root/nixos/modules/config/xdg
diff options
context:
space:
mode:
authorworldofpeace <worldofpeace@protonmail.ch>2019-07-26 22:54:19 -0400
committerworldofpeace <worldofpeace@protonmail.ch>2019-07-29 21:47:09 -0400
commit1b21c9db91e41c1773ea55c328d03013ac4e3327 (patch)
treed2f9a9419cdc3db3ef5eb9bd5f23969d4c985744 /nixos/modules/config/xdg
parent1e4d9e08cdafdf51620985cbad906212737505e5 (diff)
downloadnixlib-1b21c9db91e41c1773ea55c328d03013ac4e3327.tar
nixlib-1b21c9db91e41c1773ea55c328d03013ac4e3327.tar.gz
nixlib-1b21c9db91e41c1773ea55c328d03013ac4e3327.tar.bz2
nixlib-1b21c9db91e41c1773ea55c328d03013ac4e3327.tar.lz
nixlib-1b21c9db91e41c1773ea55c328d03013ac4e3327.tar.xz
nixlib-1b21c9db91e41c1773ea55c328d03013ac4e3327.tar.zst
nixlib-1b21c9db91e41c1773ea55c328d03013ac4e3327.zip
nixos/xdg: add gtkUsePortal option to portals
Prior to this change GTK_USE_PORTAL was unconditionally
set to "1". For this to not break things you have to have some
sort of portal implementation in extraPortals.

Setting GTK_USE_PORTAL in this manner is actually only useful
when using portals for applications outside flatpak. For example
people using non-flatpak Firefox who want native filechoosers.
It's also WIP for electron applications to support this.
Diffstat (limited to 'nixos/modules/config/xdg')
-rw-r--r--nixos/modules/config/xdg/portal.nix22
1 files changed, 21 insertions, 1 deletions
diff --git a/nixos/modules/config/xdg/portal.nix b/nixos/modules/config/xdg/portal.nix
index 6a72fab3a4a4..89ddf80b5755 100644
--- a/nixos/modules/config/xdg/portal.nix
+++ b/nixos/modules/config/xdg/portal.nix
@@ -1,5 +1,7 @@
 { config, pkgs ,lib ,... }:
+
 with lib;
+
 {
   options.xdg.portal = {
     enable =
@@ -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;
       };
     };