From c4d06eff3fd41bc71aa9d48f0122b20a28bb2c52 Mon Sep 17 00:00:00 2001 From: worldofpeace Date: Fri, 26 Jul 2019 22:33:49 -0400 Subject: [PATCH 1/5] nixos/xdg: disable portal (again) --- nixos/modules/config/xdg/portal.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/config/xdg/portal.nix b/nixos/modules/config/xdg/portal.nix index 4e85bf794da..6a72fab3a4a 100644 --- a/nixos/modules/config/xdg/portal.nix +++ b/nixos/modules/config/xdg/portal.nix @@ -4,7 +4,7 @@ with lib; options.xdg.portal = { enable = mkEnableOption "xdg desktop integration"//{ - default = config.services.xserver.enable; + default = false; }; extraPortals = mkOption { From 785158fd648a3b4996a3aa68a0ba6575336cc43a Mon Sep 17 00:00:00 2001 From: worldofpeace Date: Fri, 26 Jul 2019 22:35:50 -0400 Subject: [PATCH 2/5] nixos/flatpak: require xdg.portal to be enabled --- nixos/modules/services/desktops/flatpak.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nixos/modules/services/desktops/flatpak.nix b/nixos/modules/services/desktops/flatpak.nix index 82463406118..1492d855aa0 100644 --- a/nixos/modules/services/desktops/flatpak.nix +++ b/nixos/modules/services/desktops/flatpak.nix @@ -22,6 +22,12 @@ in { ###### implementation config = mkIf cfg.enable { + assertions = [ + { assertion = (config.xdg.portal.enable == true); + message = "To use Flatpak you must enable XDG Desktop Portals with xdg.portal.enable."; + } + ]; + environment.systemPackages = [ pkgs.flatpak ]; services.dbus.packages = [ pkgs.flatpak ]; From 16c6f169a286502fe6fc7ef5e3f01fadb696974e Mon Sep 17 00:00:00 2001 From: worldofpeace Date: Fri, 26 Jul 2019 22:36:14 -0400 Subject: [PATCH 3/5] nixos/gnome3: enable xdg.portal --- nixos/modules/services/x11/desktop-managers/gnome3.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nixos/modules/services/x11/desktop-managers/gnome3.nix b/nixos/modules/services/x11/desktop-managers/gnome3.nix index 4a7a4804e1a..6ab9ab28a77 100644 --- a/nixos/modules/services/x11/desktop-managers/gnome3.nix +++ b/nixos/modules/services/x11/desktop-managers/gnome3.nix @@ -154,6 +154,7 @@ in { services.hardware.bolt.enable = mkDefault true; services.xserver.libinput.enable = mkDefault true; # for controlling touchpad settings via gnome control center systemd.packages = [ pkgs.gnome3.vino ]; + xdg.portal.enable = true; xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-gtk ]; # If gnome3 is installed, build vim for gtk3 too. From 1e4d9e08cdafdf51620985cbad906212737505e5 Mon Sep 17 00:00:00 2001 From: worldofpeace Date: Fri, 26 Jul 2019 22:36:32 -0400 Subject: [PATCH 4/5] nixos/plasma5: enable xdg.portal --- nixos/modules/services/x11/desktop-managers/plasma5.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/x11/desktop-managers/plasma5.nix b/nixos/modules/services/x11/desktop-managers/plasma5.nix index 98c9ae86cee..6d148fba895 100644 --- a/nixos/modules/services/x11/desktop-managers/plasma5.nix +++ b/nixos/modules/services/x11/desktop-managers/plasma5.nix @@ -170,7 +170,7 @@ in xdg-user-dirs # Update user dirs as described in https://freedesktop.org/wiki/Software/xdg-user-dirs/ ] - + # Phonon audio backend ++ lib.optional (cfg.phononBackend == "gstreamer") libsForQt5.phonon-backend-gstreamer ++ lib.optional (cfg.phononBackend == "gstreamer" && cfg.enableQt4Support) pkgs.phonon-backend-gstreamer @@ -233,6 +233,7 @@ in security.pam.services.sddm.enableKwallet = true; security.pam.services.slim.enableKwallet = true; + xdg.portal.enable = true; xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-kde ]; # Update the start menu for each user that is currently logged in From 1b21c9db91e41c1773ea55c328d03013ac4e3327 Mon Sep 17 00:00:00 2001 From: worldofpeace Date: Fri, 26 Jul 2019 22:54:19 -0400 Subject: [PATCH 5/5] 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. --- nixos/modules/config/xdg/portal.nix | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/nixos/modules/config/xdg/portal.nix b/nixos/modules/config/xdg/portal.nix index 6a72fab3a4a..89ddf80b575 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 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. + Defaults to false 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; }; };