21 attrsOf (coercedTo (either (listOf str) str) (x: lib.concatStringsSep ";" (lib.toList x)) str);
26 (mkRenamedOptionModule [ "services" "flatpak" "extraPortals" ] [ "xdg" "portal" "extraPortals" ])
27 (mkRemovedOptionModule [
31 ] "This option has been removed due to being unsupported and discouraged by the GTK developers.")
35 maintainers = teams.freedesktop.members;
38 options.xdg.portal = {
40 mkEnableOption ''[xdg desktop integration](https://github.com/flatpak/xdg-desktop-portal)''
45 extraPortals = mkOption {
46 type = types.listOf types.package;
49 List of additional portals to add to path. Portals allow interaction
50 with system, like choosing files or taking screenshots. At minimum,
51 a desktop portal implementation should be listed. GNOME and KDE already
52 adds `xdg-desktop-portal-gtk`; and
53 `xdg-desktop-portal-kde` respectively. On other desktop
54 environments you probably want to add them yourself.
58 xdgOpenUsePortal = mkOption {
62 Sets environment variable `NIXOS_XDG_OPEN_USE_PORTAL` to `1`
63 This will make `xdg-open` use the portal to open programs, which resolves bugs involving
64 programs opening inside FHS envs or with unexpected env vars set from wrappers.
65 See [#160923](https://github.com/NixOS/nixpkgs/issues/160923) for more info.
70 type = types.attrsOf associationOptions;
84 "org.freedesktop.impl.portal.Secret" = [ "gnome-keyring" ];
91 Sets which portal backend should be used to provide the implementation
92 for the requested interface. For details check {manpage}`portals.conf(5)`.
94 Configs will be linked to `/etc/xdg/xdg-desktop-portal/` with the name `$desktop-portals.conf`
95 for `xdg.portal.config.$desktop` and `portals.conf` for `xdg.portal.config.common`
100 configPackages = mkOption {
101 type = types.listOf types.package;
103 example = lib.literalExpression "[ pkgs.gnome-session ]";
105 List of packages that provide XDG desktop portal configuration, usually in
106 the form of `share/xdg-desktop-portal/$desktop-portals.conf`.
108 Note that configs in `xdg.portal.config` will be preferred if set.
115 cfg = config.xdg.portal;
116 packages = [ pkgs.xdg-desktop-portal ] ++ cfg.extraPortals;
119 warnings = lib.optional (cfg.configPackages == [ ] && cfg.config == { }) ''
120 xdg-desktop-portal 1.17 reworked how portal implementations are loaded, you
121 should either set `xdg.portal.config` or `xdg.portal.configPackages`
122 to specify which portal backend to use for the requested interface.
124 https://github.com/flatpak/xdg-desktop-portal/blob/1.18.1/doc/portals.conf.rst.in
126 If you simply want to keep the behaviour in < 1.17, which uses the first
127 portal implementation found in lexicographical order, use the following:
129 xdg.portal.config.common.default = "*";
134 assertion = cfg.extraPortals != [ ];
135 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.";
139 services.dbus.packages = packages;
140 systemd.packages = packages;
143 systemPackages = packages ++ cfg.configPackages;
145 # Portal definitions and upstream desktop environment portal configurations.
146 "/share/xdg-desktop-portal"
147 # .desktop files to register fallback icon and app name.
148 "/share/applications"
152 NIXOS_XDG_OPEN_USE_PORTAL = mkIf cfg.xdgOpenUsePortal "1";
153 NIX_XDG_DESKTOP_PORTAL_DIR = "/run/current-system/sw/share/xdg-desktop-portal/portals";
156 etc = lib.concatMapAttrs (
158 lib.optionalAttrs (conf != { }) {
159 "xdg/xdg-desktop-portal/${
160 lib.optionalString (desktop != "common") "${desktop}-"
161 }portals.conf".text =
162 lib.generators.toINI { } { preferred = conf; };