2022-01-27 00:19:43 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-07-14 12:49:19 +00:00
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
mkEnableOption
|
|
|
|
mkIf
|
|
|
|
mkOption
|
|
|
|
mkRenamedOptionModule
|
|
|
|
teams
|
|
|
|
types;
|
|
|
|
in
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "services" "flatpak" "extraPortals" ] [ "xdg" "portal" "extraPortals" ])
|
2022-07-14 12:49:19 +00:00
|
|
|
|
|
|
|
({ 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."
|
|
|
|
];
|
|
|
|
}
|
|
|
|
)
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
maintainers = teams.freedesktop.members;
|
|
|
|
};
|
|
|
|
|
|
|
|
options.xdg.portal = {
|
|
|
|
enable =
|
2022-08-12 12:06:08 +00:00
|
|
|
mkEnableOption ''<link xlink:href="https://github.com/flatpak/xdg-desktop-portal">xdg desktop integration</link>'' // {
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
extraPortals = mkOption {
|
|
|
|
type = types.listOf types.package;
|
2022-01-27 00:19:43 +00:00
|
|
|
default = [ ];
|
2020-04-24 23:36:52 +00:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
gtkUsePortal = mkOption {
|
|
|
|
type = types.bool;
|
2022-07-14 12:49:19 +00:00
|
|
|
visible = false;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Sets environment variable <literal>GTK_USE_PORTAL</literal> to <literal>1</literal>.
|
2022-07-14 12:49:19 +00:00
|
|
|
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.
|
2020-04-24 23:36:52 +00:00
|
|
|
Defaults to <literal>false</literal> to respect its opt-in nature.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config =
|
|
|
|
let
|
|
|
|
cfg = config.xdg.portal;
|
|
|
|
packages = [ pkgs.xdg-desktop-portal ] ++ cfg.extraPortals;
|
2022-01-27 00:19:43 +00:00
|
|
|
joinedPortals = pkgs.buildEnv {
|
2020-04-24 23:36:52 +00:00
|
|
|
name = "xdg-portals";
|
2022-01-27 00:19:43 +00:00
|
|
|
paths = packages;
|
|
|
|
pathsToLink = [ "/share/xdg-desktop-portal/portals" "/share/applications" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2022-01-27 00:19:43 +00:00
|
|
|
in
|
|
|
|
mkIf cfg.enable {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
assertions = [
|
2022-01-27 00:19:43 +00:00
|
|
|
{
|
|
|
|
assertion = cfg.extraPortals != [ ];
|
|
|
|
message = "Setting xdg.portal.enable to true requires a portal implementation in xdg.portal.extraPortals such as xdg-desktop-portal-gtk or xdg-desktop-portal-kde.";
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2022-01-27 00:19:43 +00:00
|
|
|
services.dbus.packages = packages;
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.packages = packages;
|
|
|
|
|
2022-01-27 00:19:43 +00:00
|
|
|
environment = {
|
|
|
|
# fixes screen sharing on plasmawayland on non-chromium apps by linking
|
|
|
|
# share/applications/*.desktop files
|
|
|
|
# see https://github.com/NixOS/nixpkgs/issues/145174
|
|
|
|
systemPackages = [ joinedPortals ];
|
|
|
|
pathsToLink = [ "/share/applications" ];
|
|
|
|
|
|
|
|
sessionVariables = {
|
|
|
|
GTK_USE_PORTAL = mkIf cfg.gtkUsePortal "1";
|
|
|
|
XDG_DESKTOP_PORTAL_DIR = "${joinedPortals}/share/xdg-desktop-portal/portals";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|