From 5d5c2ef49b1d513cdc9dca8b690b1cc48ed24c64 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Wed, 22 Jun 2022 21:25:40 +0200 Subject: [PATCH 1/2] nixos/xdg.portal: avoid with statement --- nixos/modules/config/xdg/portal.nix | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nixos/modules/config/xdg/portal.nix b/nixos/modules/config/xdg/portal.nix index 088f2af59e22..377962e9fe5c 100644 --- a/nixos/modules/config/xdg/portal.nix +++ b/nixos/modules/config/xdg/portal.nix @@ -1,6 +1,14 @@ { config, pkgs, lib, ... }: -with lib; +let + inherit (lib) + mkEnableOption + mkIf + mkOption + mkRenamedOptionModule + teams + types; +in { imports = [ From ebde08adf37932ff59c27b5935840aa733965bdb Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Wed, 22 Jun 2022 22:32:10 +0200 Subject: [PATCH 2/2] nixos/xdg.portal: deprecate gtkUsePortal option It was never meant to be used for anything other than testing and setting it globally can cause weird loops in GTK-based portals, where the portal will end up waiting for itself until it times out. https://github.com/NixOS/nixpkgs/issues/135898 Or it can mess up fonts: https://github.com/NixOS/nixpkgs/issues/155291#issuecomment-1166199585 Having the option in NixOS makes it look like it is okay or even desirable to enable, when in fact it is a hack that can subtly break apps. Some apps allow opting into using portal-based APIs, e.g. for Firefox, you can set `widget.use-xdg-desktop-portal.file-picker` to `1` in about:config. Otherwise, you can set the `GTK_USE_PORTAL` environment variable to 1 for individual apps. People who really want it and aware of the downsides can just set `environment.sessionVariables.GTK_USE_PORTAL = "1";` NixOS option directly to set the environment variable globally. --- nixos/modules/config/xdg/portal.nix | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/nixos/modules/config/xdg/portal.nix b/nixos/modules/config/xdg/portal.nix index 377962e9fe5c..1e6ddd7c4a26 100644 --- a/nixos/modules/config/xdg/portal.nix +++ b/nixos/modules/config/xdg/portal.nix @@ -13,6 +13,18 @@ in { imports = [ (mkRenamedOptionModule [ "services" "flatpak" "extraPortals" ] [ "xdg" "portal" "extraPortals" ]) + + ({ config, lib, options, ... }: + let + from = [ "xdg" "portal" "gtkUsePortal" ]; + fromOpt = lib.getAttrFromPath from options; + in + { + warnings = lib.mkIf config.xdg.portal.gtkUsePortal [ + "The option `${lib.showOption from}' defined in ${lib.showFiles fromOpt.files} has been deprecated. Setting the variable globally with `environment.sessionVariables' NixOS option can have unforseen side-effects." + ]; + } + ) ]; meta = { @@ -40,11 +52,12 @@ in gtkUsePortal = mkOption { type = types.bool; + visible = false; default = false; description = '' Sets environment variable GTK_USE_PORTAL to 1. - 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. + This will force GTK-based programs ran outside Flatpak to respect and use XDG Desktop Portals + for features like file chooser but it is an unsupported hack that can easily break things. Defaults to false to respect its opt-in nature. ''; };