From 6bcd4fe4effb0c8984feaf57b85a581376489618 Mon Sep 17 00:00:00 2001 From: Patrick Chilton Date: Tue, 1 Jun 2021 09:59:58 +0200 Subject: [PATCH] gnome-flashback: add module support to gnome-panel for installing applets Co-authored-by: Jan Tojnar --- .../services/x11/desktop-managers/gnome.nix | 12 +++++ .../gnome/misc/gnome-flashback/default.nix | 44 ++++++++++++++----- .../gnome/misc/gnome-panel/default.nix | 7 +++ .../misc/gnome-panel/modulesdir-env-var.patch | 31 +++++++++++++ 4 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 pkgs/desktops/gnome/misc/gnome-panel/modulesdir-env-var.patch diff --git a/nixos/modules/services/x11/desktop-managers/gnome.nix b/nixos/modules/services/x11/desktop-managers/gnome.nix index c5e6caeea902..1b534096f5ba 100644 --- a/nixos/modules/services/x11/desktop-managers/gnome.nix +++ b/nixos/modules/services/x11/desktop-managers/gnome.nix @@ -261,6 +261,17 @@ in default = []; description = "Other GNOME Flashback sessions to enable."; }; + + panelModulePackages = mkOption { + default = [ pkgs.gnome.gnome-applets ]; + type = types.listOf types.path; + description = '' + Packages containing modules that should be made available to gnome-panel (usually for applets). + + If you're packaging something to use here, please install the modules in $out/lib/gnome-panel/modules. + ''; + example = literalExample "[ pkgs.gnome.gnome-applets ]"; + }; }; }; @@ -323,6 +334,7 @@ in (wm: pkgs.gnome.gnome-flashback.mkSessionForWm { inherit (wm) wmName wmLabel wmCommand enableGnomePanel; + inherit (cfg.flashback) panelModulePackages; } ) flashbackWms; diff --git a/pkgs/desktops/gnome/misc/gnome-flashback/default.nix b/pkgs/desktops/gnome/misc/gnome-flashback/default.nix index 2e8662ede0c7..3df9d7450cd7 100644 --- a/pkgs/desktops/gnome/misc/gnome-flashback/default.nix +++ b/pkgs/desktops/gnome/misc/gnome-flashback/default.nix @@ -23,10 +23,10 @@ , pam , wrapGAppsHook , writeTextFile -, writeShellScriptBin , xkeyboard_config , xorg , runCommand +, buildEnv }: let pname = "gnome-flashback"; @@ -126,7 +126,7 @@ let versionPolicy = "odd-unstable"; }; - mkSessionForWm = { wmName, wmLabel, wmCommand, enableGnomePanel }: + mkSessionForWm = { wmName, wmLabel, wmCommand, enableGnomePanel, panelModulePackages }: let wmApplication = writeTextFile { name = "gnome-flashback-${wmName}-wm"; @@ -155,15 +155,39 @@ let ''; }; - executable = writeShellScriptBin "gnome-flashback-${wmName}" '' - if [ -z $XDG_CURRENT_DESKTOP ]; then - export XDG_CURRENT_DESKTOP="GNOME-Flashback:GNOME" - fi + # gnome-panel will only look for applets in a single directory so symlink them into here. + panelModulesEnv = buildEnv { + name = "gnome-panel-modules-env"; + # We always want to find the built-in panel applets. + paths = [ gnome-panel gnome-flashback ] ++ panelModulePackages; + pathsToLink = [ "/lib/gnome-panel/modules" ]; + }; - export XDG_DATA_DIRS=${wmApplication}/share:${gnomeSession}/share:${gnome-flashback}/share:${gnome-panel}/share:$XDG_DATA_DIRS + executable = stdenv.mkDerivation { + name = "gnome-flashback-${wmName}"; + nativeBuildInputs = [ glib wrapGAppsHook ]; + buildInputs = [ gnome-flashback ] ++ lib.optionals enableGnomePanel ([ gnome-panel ] ++ panelModulePackages); - exec ${gnome-session}/bin/gnome-session --session=gnome-flashback-${wmName} "$@" - ''; + # We want to use the wrapGAppsHook mechanism to wrap gnome-session + # with the environment that gnome-flashback and gnome-panel need to + # run, including the configured applet packages. This is only possible + # in the fixup phase, so turn everything else off. + dontUnpack = true; + dontConfigure = true; + dontBuild = true; + dontInstall = true; + dontWrapGApps = true; # We want to do the wrapping ourselves. + + # gnome-flashback and gnome-panel need to be added to XDG_DATA_DIRS so that their .desktop files can be found by gnome-session. + preFixup = '' + makeWrapper ${gnome-session}/bin/gnome-session $out \ + --add-flags "--session=gnome-flashback-${wmName}" \ + --set-default XDG_CURRENT_DESKTOP 'GNOME-Flashback:GNOME' \ + --prefix XDG_DATA_DIRS : '${lib.makeSearchPath "share" ([ wmApplication gnomeSession gnome-flashback ] ++ lib.optional enableGnomePanel gnome-panel)}' \ + "''${gappsWrapperArgs[@]}" \ + ${lib.optionalString enableGnomePanel "--set NIX_GNOME_PANEL_MODULESDIR '${panelModulesEnv}/lib/gnome-panel/modules'"} + ''; + }; in writeTextFile @@ -174,7 +198,7 @@ let [Desktop Entry] Name=GNOME Flashback (${wmLabel}) Comment=This session logs you into GNOME Flashback with ${wmLabel} - Exec=${executable}/bin/gnome-flashback-${wmName} + Exec=${executable} TryExec=${wmCommand} Type=Application DesktopNames=GNOME-Flashback;GNOME; diff --git a/pkgs/desktops/gnome/misc/gnome-panel/default.nix b/pkgs/desktops/gnome/misc/gnome-panel/default.nix index 4e42f91e1e3c..8ab1a87d01ce 100644 --- a/pkgs/desktops/gnome/misc/gnome-panel/default.nix +++ b/pkgs/desktops/gnome/misc/gnome-panel/default.nix @@ -32,6 +32,13 @@ stdenv.mkDerivation rec { hash = "sha256-nxNQde3GZs8rnKkd41xnA+KxdxwQp3B0FPtlbCilmzs="; }; + patches = [ + # Load modules from path in `NIX_GNOME_PANEL_MODULESDIR` environment variable + # instead of gnome-panel’s libdir so that the NixOS module can make gnome-panel + # load modules from other packages as well. + ./modulesdir-env-var.patch + ]; + # make .desktop Exec absolute postPatch = '' patch -p0 <