2021-12-02 23:10:08 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
2019-07-27 04:54:19 +02:00
|
|
|
|
2022-06-22 21:25:40 +02:00
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
mkEnableOption
|
|
|
|
mkIf
|
|
|
|
mkOption
|
|
|
|
mkRenamedOptionModule
|
2024-07-31 11:27:11 +02:00
|
|
|
mkRemovedOptionModule
|
2022-06-22 21:25:40 +02:00
|
|
|
teams
|
|
|
|
types;
|
2023-09-17 16:02:40 +02:00
|
|
|
|
|
|
|
associationOptions = with types; attrsOf (
|
|
|
|
coercedTo (either (listOf str) str) (x: lib.concatStringsSep ";" (lib.toList x)) str
|
|
|
|
);
|
2022-06-22 21:25:40 +02:00
|
|
|
in
|
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" ])
|
2024-07-31 11:27:11 +02:00
|
|
|
(mkRemovedOptionModule [ "xdg" "portal" "gtkUsePortal" ] "This option has been removed due to being unsupported and discouraged by the GTK developers.")
|
2019-12-10 02:51:19 +01:00
|
|
|
];
|
|
|
|
|
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 =
|
2021-12-02 23:10:08 +01:00
|
|
|
mkEnableOption ''[xdg desktop integration](https://github.com/flatpak/xdg-desktop-portal)'' // {
|
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;
|
2021-12-02 23:10:08 +01:00
|
|
|
default = [ ];
|
2019-07-10 16:01:25 +02: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
|
2022-08-13 05:15:06 +02:00
|
|
|
adds `xdg-desktop-portal-gtk`; and
|
|
|
|
`xdg-desktop-portal-kde` respectively. On other desktop
|
2019-07-10 16:01:25 +02:00
|
|
|
environments you probably want to add them yourself.
|
|
|
|
'';
|
|
|
|
};
|
2019-07-27 04:54:19 +02:00
|
|
|
|
2022-10-21 22:19:24 +02:00
|
|
|
xdgOpenUsePortal = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
2023-09-17 16:02:40 +02: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" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
description = ''
|
|
|
|
Sets which portal backend should be used to provide the implementation
|
|
|
|
for the requested interface. For details check {manpage}`portals.conf(5)`.
|
|
|
|
|
2024-05-26 00:26:15 +02:00
|
|
|
Configs will be linked to `/etc/xdg/xdg-desktop-portal/` with the name `$desktop-portals.conf`
|
2023-09-17 16:02:40 +02:00
|
|
|
for `xdg.portal.config.$desktop` and `portals.conf` for `xdg.portal.config.common`
|
|
|
|
as an exception.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
configPackages = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [ ];
|
2024-08-28 23:56:05 +02:00
|
|
|
example = lib.literalExpression "[ pkgs.gnome-session ]";
|
2023-09-17 16:02:40 +02:00
|
|
|
description = ''
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
2019-07-10 16:01:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config =
|
|
|
|
let
|
|
|
|
cfg = config.xdg.portal;
|
|
|
|
packages = [ pkgs.xdg-desktop-portal ] ++ cfg.extraPortals;
|
2021-12-02 23:10:08 +01:00
|
|
|
in
|
|
|
|
mkIf cfg.enable {
|
2023-09-17 16:02:40 +02: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.
|
|
|
|
|
2023-11-18 13:28:48 +01:00
|
|
|
https://github.com/flatpak/xdg-desktop-portal/blob/1.18.1/doc/portals.conf.rst.in
|
2023-09-17 16:02:40 +02:00
|
|
|
|
|
|
|
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 = "*";
|
|
|
|
'';
|
2019-07-10 16:01:25 +02:00
|
|
|
|
2019-07-27 04:54:19 +02:00
|
|
|
assertions = [
|
2021-12-02 23:10:08 +01: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.";
|
2019-07-27 04:54:19 +02:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2021-12-02 23:10:08 +01:00
|
|
|
services.dbus.packages = packages;
|
2019-07-10 16:01:25 +02:00
|
|
|
systemd.packages = packages;
|
2019-07-27 04:54:19 +02:00
|
|
|
|
2021-12-02 23:10:08 +01:00
|
|
|
environment = {
|
2023-11-18 00:54:36 +01:00
|
|
|
systemPackages = packages ++ cfg.configPackages;
|
2023-11-18 00:35:54 +01:00
|
|
|
pathsToLink = [
|
2023-11-18 00:54:36 +01:00
|
|
|
# Portal definitions and upstream desktop environment portal configurations.
|
2023-11-18 00:35:54 +01:00
|
|
|
"/share/xdg-desktop-portal"
|
|
|
|
# .desktop files to register fallback icon and app name.
|
|
|
|
"/share/applications"
|
|
|
|
];
|
2021-12-02 23:10:08 +01:00
|
|
|
|
|
|
|
sessionVariables = {
|
2022-10-21 22:19:24 +02:00
|
|
|
NIXOS_XDG_OPEN_USE_PORTAL = mkIf cfg.xdgOpenUsePortal "1";
|
2023-11-18 00:54:36 +01:00
|
|
|
NIX_XDG_DESKTOP_PORTAL_DIR = "/run/current-system/sw/share/xdg-desktop-portal/portals";
|
2021-12-02 23:10:08 +01:00
|
|
|
};
|
2023-09-17 16:02:40 +02: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;
|
2019-07-10 16:01:25 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|