2019-07-10 16:01:25 +02:00
|
|
|
{ config, pkgs ,lib ,... }:
|
2019-07-27 04:54:19 +02:00
|
|
|
|
2019-07-10 16:01:25 +02:00
|
|
|
with lib;
|
2019-07-27 04:54:19 +02:00
|
|
|
|
2019-07-10 16:01:25 +02:00
|
|
|
{
|
2019-12-10 02:51:19 +01:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "services" "flatpak" "extraPortals" ] [ "xdg" "portal" "extraPortals" ])
|
|
|
|
];
|
|
|
|
|
2020-04-02 02:16:24 +02:00
|
|
|
meta = {
|
|
|
|
maintainers = teams.freedesktop.members;
|
|
|
|
};
|
|
|
|
|
2019-07-10 16:01:25 +02:00
|
|
|
options.xdg.portal = {
|
|
|
|
enable =
|
|
|
|
mkEnableOption "<link xlink:href='https://github.com/flatpak/xdg-desktop-portal'>xdg desktop integration</link>"//{
|
2019-07-27 04:33:49 +02:00
|
|
|
default = false;
|
2019-07-10 16:01:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extraPortals = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
List of additional portals to add to path. Portals allow interaction
|
|
|
|
with system, like choosing files or taking screenshots. At minimum,
|
|
|
|
a desktop portal implementation should be listed. GNOME and KDE already
|
|
|
|
adds <package>xdg-desktop-portal-gtk</package>; and
|
|
|
|
<package>xdg-desktop-portal-kde</package> respectively. On other desktop
|
|
|
|
environments you probably want to add them yourself.
|
|
|
|
'';
|
|
|
|
};
|
2019-07-27 04:54:19 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
2019-07-10 16:01:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config =
|
|
|
|
let
|
|
|
|
cfg = config.xdg.portal;
|
|
|
|
packages = [ pkgs.xdg-desktop-portal ] ++ cfg.extraPortals;
|
2020-02-08 06:57:47 +01:00
|
|
|
joinedPortals = pkgs.symlinkJoin {
|
|
|
|
name = "xdg-portals";
|
|
|
|
paths = cfg.extraPortals;
|
|
|
|
};
|
2019-07-10 16:01:25 +02:00
|
|
|
|
|
|
|
in mkIf cfg.enable {
|
|
|
|
|
2019-07-27 04:54:19 +02:00
|
|
|
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.";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2019-07-10 16:01:25 +02:00
|
|
|
services.dbus.packages = packages;
|
|
|
|
systemd.packages = packages;
|
2019-07-27 04:54:19 +02:00
|
|
|
|
2021-01-11 05:42:02 +01:00
|
|
|
environment.sessionVariables = {
|
2019-08-01 23:51:51 +02:00
|
|
|
GTK_USE_PORTAL = mkIf cfg.gtkUsePortal "1";
|
2020-02-08 06:57:47 +01:00
|
|
|
XDG_DESKTOP_PORTAL_DIR = "${joinedPortals}/share/xdg-desktop-portal/portals";
|
2019-07-10 16:01:25 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|