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;
|
2024-01-02 11:29:13 +00:00
|
|
|
|
|
|
|
associationOptions = with types; attrsOf (
|
|
|
|
coercedTo (either (listOf str) str) (x: lib.concatStringsSep ";" (lib.toList x)) str
|
|
|
|
);
|
2022-07-14 12:49:19 +00:00
|
|
|
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 [
|
2023-05-24 13:37:59 +00:00
|
|
|
"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 unforeseen side-effects."
|
2022-07-14 12:49:19 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
)
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
maintainers = teams.freedesktop.members;
|
|
|
|
};
|
|
|
|
|
|
|
|
options.xdg.portal = {
|
|
|
|
enable =
|
2024-04-21 15:54:59 +00:00
|
|
|
mkEnableOption ''[xdg desktop integration](https://github.com/flatpak/xdg-desktop-portal)'' // {
|
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 = [ ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
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
|
2022-08-21 13:32:41 +00:00
|
|
|
adds `xdg-desktop-portal-gtk`; and
|
|
|
|
`xdg-desktop-portal-kde` respectively. On other desktop
|
2020-04-24 23:36:52 +00:00
|
|
|
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;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-09-09 14:08:57 +00:00
|
|
|
Sets environment variable `GTK_USE_PORTAL` to `1`.
|
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.
|
2022-09-09 14:08:57 +00:00
|
|
|
Defaults to `false` to respect its opt-in nature.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
2022-12-17 10:02:37 +00:00
|
|
|
|
|
|
|
xdgOpenUsePortal = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-12-17 10:02:37 +00:00
|
|
|
Sets environment variable `NIXOS_XDG_OPEN_USE_PORTAL` to `1`
|
|
|
|
This will make `xdg-open` use the portal to open programs, which resolves bugs involving
|
|
|
|
programs opening inside FHS envs or with unexpected env vars set from wrappers.
|
|
|
|
See [#160923](https://github.com/NixOS/nixpkgs/issues/160923) for more info.
|
|
|
|
'';
|
|
|
|
};
|
2024-01-02 11:29:13 +00:00
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
type = types.attrsOf associationOptions;
|
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
x-cinnamon = {
|
|
|
|
default = [ "xapp" "gtk" ];
|
|
|
|
};
|
|
|
|
pantheon = {
|
|
|
|
default = [ "pantheon" "gtk" ];
|
|
|
|
"org.freedesktop.impl.portal.Secret" = [ "gnome-keyring" ];
|
|
|
|
};
|
|
|
|
common = {
|
|
|
|
default = [ "gtk" ];
|
|
|
|
};
|
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2024-01-02 11:29:13 +00:00
|
|
|
Sets which portal backend should be used to provide the implementation
|
|
|
|
for the requested interface. For details check {manpage}`portals.conf(5)`.
|
|
|
|
|
|
|
|
Configs will be linked to `/etx/xdg/xdg-desktop-portal/` with the name `$desktop-portals.conf`
|
|
|
|
for `xdg.portal.config.$desktop` and `portals.conf` for `xdg.portal.config.common`
|
|
|
|
as an exception.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
configPackages = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [ ];
|
|
|
|
example = lib.literalExpression "[ pkgs.gnome.gnome-session ]";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2024-01-02 11:29:13 +00:00
|
|
|
List of packages that provide XDG desktop portal configuration, usually in
|
|
|
|
the form of `share/xdg-desktop-portal/$desktop-portals.conf`.
|
|
|
|
|
|
|
|
Note that configs in `xdg.portal.config` will be preferred if set.
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config =
|
|
|
|
let
|
|
|
|
cfg = config.xdg.portal;
|
|
|
|
packages = [ pkgs.xdg-desktop-portal ] ++ cfg.extraPortals;
|
2022-01-27 00:19:43 +00:00
|
|
|
in
|
|
|
|
mkIf cfg.enable {
|
2024-01-02 11:29:13 +00:00
|
|
|
warnings = lib.optional (cfg.configPackages == [ ] && cfg.config == { }) ''
|
|
|
|
xdg-desktop-portal 1.17 reworked how portal implementations are loaded, you
|
|
|
|
should either set `xdg.portal.config` or `xdg.portal.configPackages`
|
|
|
|
to specify which portal backend to use for the requested interface.
|
|
|
|
|
|
|
|
https://github.com/flatpak/xdg-desktop-portal/blob/1.18.1/doc/portals.conf.rst.in
|
|
|
|
|
|
|
|
If you simply want to keep the behaviour in < 1.17, which uses the first
|
|
|
|
portal implementation found in lexicographical order, use the following:
|
|
|
|
|
|
|
|
xdg.portal.config.common.default = "*";
|
|
|
|
'';
|
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 = {
|
2024-02-29 20:09:43 +00:00
|
|
|
systemPackages = packages ++ cfg.configPackages;
|
|
|
|
pathsToLink = [
|
|
|
|
# Portal definitions and upstream desktop environment portal configurations.
|
|
|
|
"/share/xdg-desktop-portal"
|
|
|
|
# .desktop files to register fallback icon and app name.
|
|
|
|
"/share/applications"
|
|
|
|
];
|
2022-01-27 00:19:43 +00:00
|
|
|
|
|
|
|
sessionVariables = {
|
|
|
|
GTK_USE_PORTAL = mkIf cfg.gtkUsePortal "1";
|
2022-12-17 10:02:37 +00:00
|
|
|
NIXOS_XDG_OPEN_USE_PORTAL = mkIf cfg.xdgOpenUsePortal "1";
|
2024-02-29 20:09:43 +00:00
|
|
|
NIX_XDG_DESKTOP_PORTAL_DIR = "/run/current-system/sw/share/xdg-desktop-portal/portals";
|
2022-01-27 00:19:43 +00:00
|
|
|
};
|
2024-01-02 11:29:13 +00:00
|
|
|
|
|
|
|
etc = lib.concatMapAttrs
|
|
|
|
(desktop: conf: lib.optionalAttrs (conf != { }) {
|
|
|
|
"xdg/xdg-desktop-portal/${lib.optionalString (desktop != "common") "${desktop}-"}portals.conf".text =
|
|
|
|
lib.generators.toINI { } { preferred = conf; };
|
|
|
|
}) cfg.config;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|