From 90b1197301eb714e64a508c3be2dd073b24caed3 Mon Sep 17 00:00:00 2001 From: Pasquale Date: Wed, 10 Jul 2019 16:01:25 +0200 Subject: [PATCH] nixos/xdg: add portal option This factors the configuration out of the flatpak module. --- nixos/modules/config/xdg/portal.nix | 38 +++++++++++++++++++ nixos/modules/module-list.nix | 1 + nixos/modules/rename.nix | 1 + nixos/modules/services/desktops/flatpak.nix | 22 ++--------- .../services/x11/desktop-managers/gnome3.nix | 2 +- .../services/x11/desktop-managers/plasma5.nix | 2 + 6 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 nixos/modules/config/xdg/portal.nix diff --git a/nixos/modules/config/xdg/portal.nix b/nixos/modules/config/xdg/portal.nix new file mode 100644 index 000000000000..76ca435d434a --- /dev/null +++ b/nixos/modules/config/xdg/portal.nix @@ -0,0 +1,38 @@ +{ config, pkgs ,lib ,... }: +with lib; +{ + options.xdg.portal = { + enable = + mkEnableOption "xdg desktop integration"//{ + default = true; + }; + + extraPortals = mkOption { + type = types.listOf types.package; + default = []; + 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 + adds xdg-desktop-portal-gtk; and + xdg-desktop-portal-kde respectively. On other desktop + environments you probably want to add them yourself. + ''; + }; + }; + + config = + let + cfg = config.xdg.portal; + packages = [ pkgs.xdg-desktop-portal ] ++ cfg.extraPortals; + + in mkIf cfg.enable { + + services.dbus.packages = packages; + systemd.packages = packages; + environment.variables = { + GTK_USE_PORTAL = "1"; + XDG_DESKTOP_PORTAL_PATH = map (p: "${p}/share/xdg-desktop-portal/portals") cfg.extraPortals; + }; + }; +} diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 1d1995eda25a..e7e64bcfee75 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -11,6 +11,7 @@ ./config/xdg/icons.nix ./config/xdg/menus.nix ./config/xdg/mime.nix + ./config/xdg/portal.nix ./config/appstream.nix ./config/xdg/sounds.nix ./config/gtk/gtk-icon-cache.nix diff --git a/nixos/modules/rename.nix b/nixos/modules/rename.nix index 1b77a895d717..23a27f129470 100644 --- a/nixos/modules/rename.nix +++ b/nixos/modules/rename.nix @@ -19,6 +19,7 @@ with lib; let value = getAttrFromPath [ "services" "ddclient" "domain" ] config; in if value != "" then [ value ] else [])) (mkRemovedOptionModule [ "services" "ddclient" "homeDir" ] "") + (mkRenamedOptionModule [ "services" "flatpak" "extraPortals" ] [ "xdg" "portal" "extraPortals" ]) (mkRenamedOptionModule [ "services" "i2pd" "extIp" ] [ "services" "i2pd" "address" ]) (mkRenamedOptionModule [ "services" "kubernetes" "apiserver" "admissionControl" ] [ "services" "kubernetes" "apiserver" "enableAdmissionPlugins" ]) (mkRenamedOptionModule [ "services" "kubernetes" "apiserver" "address" ] ["services" "kubernetes" "apiserver" "bindAddress"]) diff --git a/nixos/modules/services/desktops/flatpak.nix b/nixos/modules/services/desktops/flatpak.nix index cfca1893bd82..824634061180 100644 --- a/nixos/modules/services/desktops/flatpak.nix +++ b/nixos/modules/services/desktops/flatpak.nix @@ -15,38 +15,22 @@ in { options = { services.flatpak = { enable = mkEnableOption "flatpak"; - - extraPortals = mkOption { - type = types.listOf types.package; - default = []; - 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 already - adds xdg-desktop-portal-gtk; for KDE, there - is xdg-desktop-portal-kde. Other desktop - environments will probably want to do the same. - ''; - }; }; }; ###### implementation config = mkIf cfg.enable { + environment.systemPackages = [ pkgs.flatpak ]; - services.dbus.packages = [ pkgs.flatpak pkgs.xdg-desktop-portal ] ++ cfg.extraPortals; + services.dbus.packages = [ pkgs.flatpak ]; - systemd.packages = [ pkgs.flatpak pkgs.xdg-desktop-portal ] ++ cfg.extraPortals; + systemd.packages = [ pkgs.flatpak ]; environment.profiles = [ "$HOME/.local/share/flatpak/exports" "/var/lib/flatpak/exports" ]; - - environment.variables = { - XDG_DESKTOP_PORTAL_PATH = map (p: "${p}/share/xdg-desktop-portal/portals") cfg.extraPortals; - }; }; } diff --git a/nixos/modules/services/x11/desktop-managers/gnome3.nix b/nixos/modules/services/x11/desktop-managers/gnome3.nix index ef6820d33260..4a7a4804e1aa 100644 --- a/nixos/modules/services/x11/desktop-managers/gnome3.nix +++ b/nixos/modules/services/x11/desktop-managers/gnome3.nix @@ -154,7 +154,7 @@ in { services.hardware.bolt.enable = mkDefault true; services.xserver.libinput.enable = mkDefault true; # for controlling touchpad settings via gnome control center systemd.packages = [ pkgs.gnome3.vino ]; - services.flatpak.extraPortals = [ pkgs.xdg-desktop-portal-gtk ]; + xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-gtk ]; # If gnome3 is installed, build vim for gtk3 too. nixpkgs.config.vim.gui = "gtk3"; diff --git a/nixos/modules/services/x11/desktop-managers/plasma5.nix b/nixos/modules/services/x11/desktop-managers/plasma5.nix index dc8bfc7dc172..ce8d4956bab1 100644 --- a/nixos/modules/services/x11/desktop-managers/plasma5.nix +++ b/nixos/modules/services/x11/desktop-managers/plasma5.nix @@ -224,6 +224,8 @@ in security.pam.services.sddm.enableKwallet = true; security.pam.services.slim.enableKwallet = true; + xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-kde ]; + # Update the start menu for each user that is currently logged in system.userActivationScripts.plasmaSetup = '' # The KDE icon cache is supposed to update itself