1 { config, pkgs, lib, ... }:
13 associationOptions = with types; attrsOf (
14 coercedTo (either (listOf str) str) (x: lib.concatStringsSep ";" (lib.toList x)) str
20 (mkRenamedOptionModule [ "services" "flatpak" "extraPortals" ] [ "xdg" "portal" "extraPortals" ])
21 (mkRemovedOptionModule [ "xdg" "portal" "gtkUsePortal" ] "This option has been removed due to being unsupported and discouraged by the GTK developers.")
25 maintainers = teams.freedesktop.members;
28 options.xdg.portal = {
30 mkEnableOption ''[xdg desktop integration](https://github.com/flatpak/xdg-desktop-portal)'' // {
34 extraPortals = mkOption {
35 type = types.listOf types.package;
38 List of additional portals to add to path. Portals allow interaction
39 with system, like choosing files or taking screenshots. At minimum,
40 a desktop portal implementation should be listed. GNOME and KDE already
41 adds `xdg-desktop-portal-gtk`; and
42 `xdg-desktop-portal-kde` respectively. On other desktop
43 environments you probably want to add them yourself.
47 xdgOpenUsePortal = mkOption {
51 Sets environment variable `NIXOS_XDG_OPEN_USE_PORTAL` to `1`
52 This will make `xdg-open` use the portal to open programs, which resolves bugs involving
53 programs opening inside FHS envs or with unexpected env vars set from wrappers.
54 See [#160923](https://github.com/NixOS/nixpkgs/issues/160923) for more info.
59 type = types.attrsOf associationOptions;
63 default = [ "xapp" "gtk" ];
66 default = [ "pantheon" "gtk" ];
67 "org.freedesktop.impl.portal.Secret" = [ "gnome-keyring" ];
74 Sets which portal backend should be used to provide the implementation
75 for the requested interface. For details check {manpage}`portals.conf(5)`.
77 Configs will be linked to `/etc/xdg/xdg-desktop-portal/` with the name `$desktop-portals.conf`
78 for `xdg.portal.config.$desktop` and `portals.conf` for `xdg.portal.config.common`
83 configPackages = mkOption {
84 type = types.listOf types.package;
86 example = lib.literalExpression "[ pkgs.gnome-session ]";
88 List of packages that provide XDG desktop portal configuration, usually in
89 the form of `share/xdg-desktop-portal/$desktop-portals.conf`.
91 Note that configs in `xdg.portal.config` will be preferred if set.
98 cfg = config.xdg.portal;
99 packages = [ pkgs.xdg-desktop-portal ] ++ cfg.extraPortals;
102 warnings = lib.optional (cfg.configPackages == [ ] && cfg.config == { }) ''
103 xdg-desktop-portal 1.17 reworked how portal implementations are loaded, you
104 should either set `xdg.portal.config` or `xdg.portal.configPackages`
105 to specify which portal backend to use for the requested interface.
107 https://github.com/flatpak/xdg-desktop-portal/blob/1.18.1/doc/portals.conf.rst.in
109 If you simply want to keep the behaviour in < 1.17, which uses the first
110 portal implementation found in lexicographical order, use the following:
112 xdg.portal.config.common.default = "*";
117 assertion = cfg.extraPortals != [ ];
118 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.";
122 services.dbus.packages = packages;
123 systemd.packages = packages;
126 systemPackages = packages ++ cfg.configPackages;
128 # Portal definitions and upstream desktop environment portal configurations.
129 "/share/xdg-desktop-portal"
130 # .desktop files to register fallback icon and app name.
131 "/share/applications"
135 NIXOS_XDG_OPEN_USE_PORTAL = mkIf cfg.xdgOpenUsePortal "1";
136 NIX_XDG_DESKTOP_PORTAL_DIR = "/run/current-system/sw/share/xdg-desktop-portal/portals";
139 etc = lib.concatMapAttrs
140 (desktop: conf: lib.optionalAttrs (conf != { }) {
141 "xdg/xdg-desktop-portal/${lib.optionalString (desktop != "common") "${desktop}-"}portals.conf".text =
142 lib.generators.toINI { } { preferred = conf; };