3
0
Fork 0
forked from mirrors/nixpkgs

nixos/xdg/portal: Add config and configPackages option

In x-d-p 1.17, when no configs are given, you apps will likely not
able to find a backend. Let users aware of the changes.
This commit is contained in:
Bobby Rong 2023-09-17 22:02:40 +08:00 committed by Jan Tojnar
parent e2ad581c95
commit d7a8877d9d
3 changed files with 70 additions and 0 deletions

View file

@ -4,6 +4,8 @@
"mpd.conf(5)": "https://mpd.readthedocs.io/en/latest/mpd.conf.5.html", "mpd.conf(5)": "https://mpd.readthedocs.io/en/latest/mpd.conf.5.html",
"nix.conf(5)": "https://nixos.org/manual/nix/stable/command-ref/conf-file.html", "nix.conf(5)": "https://nixos.org/manual/nix/stable/command-ref/conf-file.html",
"portals.conf(5)": "https://github.com/flatpak/xdg-desktop-portal/blob/1.18.1/doc/portals.conf.rst.in",
"journald.conf(5)": "https://www.freedesktop.org/software/systemd/man/journald.conf.html", "journald.conf(5)": "https://www.freedesktop.org/software/systemd/man/journald.conf.html",
"logind.conf(5)": "https://www.freedesktop.org/software/systemd/man/logind.conf.html", "logind.conf(5)": "https://www.freedesktop.org/software/systemd/man/logind.conf.html",
"networkd.conf(5)": "https://www.freedesktop.org/software/systemd/man/networkd.conf.html", "networkd.conf(5)": "https://www.freedesktop.org/software/systemd/man/networkd.conf.html",

View file

@ -8,6 +8,10 @@ let
mkRenamedOptionModule mkRenamedOptionModule
teams teams
types; types;
associationOptions = with types; attrsOf (
coercedTo (either (listOf str) str) (x: lib.concatStringsSep ";" (lib.toList x)) str
);
in in
{ {
@ -72,20 +76,76 @@ in
See [#160923](https://github.com/NixOS/nixpkgs/issues/160923) for more info. See [#160923](https://github.com/NixOS/nixpkgs/issues/160923) for more info.
''; '';
}; };
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 = lib.mdDoc ''
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 ]";
description = lib.mdDoc ''
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.
'';
};
}; };
config = config =
let let
cfg = config.xdg.portal; cfg = config.xdg.portal;
packages = [ pkgs.xdg-desktop-portal ] ++ cfg.extraPortals; packages = [ pkgs.xdg-desktop-portal ] ++ cfg.extraPortals;
configPackages = cfg.configPackages;
joinedPortals = pkgs.buildEnv { joinedPortals = pkgs.buildEnv {
name = "xdg-portals"; name = "xdg-portals";
paths = packages; paths = packages;
pathsToLink = [ "/share/xdg-desktop-portal/portals" "/share/applications" ]; pathsToLink = [ "/share/xdg-desktop-portal/portals" "/share/applications" ];
}; };
joinedPortalConfigs = pkgs.buildEnv {
name = "xdg-portal-configs";
paths = configPackages;
pathsToLink = [ "/share/xdg-desktop-portal" ];
};
in in
mkIf cfg.enable { mkIf cfg.enable {
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/main/doc/portals-conf.rst
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 = "*";
'';
assertions = [ assertions = [
{ {
@ -108,7 +168,14 @@ in
GTK_USE_PORTAL = mkIf cfg.gtkUsePortal "1"; GTK_USE_PORTAL = mkIf cfg.gtkUsePortal "1";
NIXOS_XDG_OPEN_USE_PORTAL = mkIf cfg.xdgOpenUsePortal "1"; NIXOS_XDG_OPEN_USE_PORTAL = mkIf cfg.xdgOpenUsePortal "1";
XDG_DESKTOP_PORTAL_DIR = "${joinedPortals}/share/xdg-desktop-portal/portals"; XDG_DESKTOP_PORTAL_DIR = "${joinedPortals}/share/xdg-desktop-portal/portals";
NIXOS_XDG_DESKTOP_PORTAL_CONFIG_DIR = mkIf (cfg.configPackages != [ ]) "${joinedPortalConfigs}/share/xdg-desktop-portal";
}; };
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;
}; };
}; };
} }

View file

@ -18,6 +18,7 @@ in other cases, you will need to add something like the following to your
{file}`configuration.nix`: {file}`configuration.nix`:
``` ```
xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-gtk ]; xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-gtk ];
xdg.portal.config.common.default = "gtk";
``` ```
Then, you will need to add a repository, for example, Then, you will need to add a repository, for example,