Application menu of desktop environment not automatically updated

  • Done
  • quality assurance status badge
Details
4 participants
  • Leo Prikler
  • Ludovic Courtès
  • Maxim Cournoyer
  • zimoun
Owner
unassigned
Submitted by
Ludovic Courtès
Severity
important
Merged with
L
L
Ludovic Courtès wrote on 25 Jun 2019 16:12
(address . bug-Guix@gnu.org)
871rzhn483.fsf@gnu.org
This is not news to us, but as
application menu of desktop environments is not automatically updated
when a package is installed or removed. It’d be great if we could
somehow notify the desktop environment.

Ludo’.
L
L
Ludovic Courtès wrote on 27 Jun 2019 17:20
control message for bug #36376
(address . control@debbugs.gnu.org)
87woh7xdf8.fsf@gnu.org
severity 36376 important
quit
L
L
Ludovic Courtès wrote on 3 Nov 2020 23:46
Re: bug#36376: Application menu of desktop environment not automatically updated
(address . 36376@debbugs.gnu.org)
87o8keawju.fsf@gnu.org
Ludovic Courtès <ludo@gnu.org> skribis:

Toggle quote (6 lines)
> This is not news to us, but as
> <https://distrowatch.com/weekly.php?issue=20190624#guixsd> notes, the
> application menu of desktop environments is not automatically updated
> when a package is installed or removed. It’d be great if we could
> somehow notify the desktop environment.

We’ve investigated today on IRC with Maxim and Leo P. and here’s the
summary of our findings:

• GNOME Shell, in ‘appDisplay.js’, “listens” to the
‘installed-changed’ GLib signals and uses that to rebuild its
application menu.

• In ‘shell-app-system.c’, ‘installed-changed’ is emitted when the
GAppInfoMonitor emits ‘changed’:

monitor = g_app_info_monitor_get ();
g_signal_connect (monitor, "changed", G_CALLBACK (installed_changed), self);
installed_changed (monitor, self);

• GLib emits the ‘changed’ signal when ‘g_app_info_monitor_fire’ is
called from ‘desktop_file_dir_changed’, itself called when one of
the directories in $XDG_DATA_DIRS (among others) changes. It uses
‘GFileMonitor’ under the hood, which is essentially inotify.

The GLib patch below is an attempt to monitor ~/.guix-profile and to
treat changes to that symlink as if they were changes to
~/.guix-profile/share/applications (which contains ‘.desktop’ files.)
It actually builds but I haven’t tested it yet. :-)

WDYT?

If we take that route, we could add a ‘replacement’ for GLib.

Thanks,
Ludo’.
Toggle diff (71 lines)
diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
index f1e2fdd..96dcc32 100644
--- a/gio/gdesktopappinfo.c
+++ b/gio/gdesktopappinfo.c
@@ -161,6 +161,7 @@ static DesktopFileDir *desktop_file_dir_user_config = NULL; /* (owned) */
static DesktopFileDir *desktop_file_dir_user_data = NULL; /* (owned) */
static GMutex desktop_file_dir_lock;
static const gchar *gio_launch_desktop_path = NULL;
+static GFileMonitor *guix_profile_monitor = NULL;
/* Monitor 'changed' signal handler {{{2 */
static void desktop_file_dir_reset (DesktopFileDir *dir);
@@ -230,6 +231,22 @@ desktop_file_dir_get_alternative_dir (DesktopFileDir *dir)
return parent;
}
+static void
+guix_profile_changed (GFileMonitor *monitor,
+ GFile *file,
+ GFile *other_file,
+ GFileMonitorEvent event_type,
+ gpointer user_data)
+{
+ DesktopFileDir *dir = user_data;
+
+ desktop_file_dir_reset (dir);
+
+ /* When ~/.guix-profile changes, emit the 'changed' signal so everyone
+ knows. */
+ g_app_info_monitor_fire ();
+}
+
static void
desktop_file_dir_changed (GFileMonitor *monitor,
GFile *file,
@@ -1531,6 +1548,7 @@ desktop_file_dirs_lock (void)
if (desktop_file_dirs == NULL || desktop_file_dirs->len == 0)
{
+ const gchar *home;
const char * const *dirs;
gint i;
@@ -1555,6 +1573,27 @@ desktop_file_dirs_lock (void)
for (i = 0; dirs[i]; i++)
g_ptr_array_add (desktop_file_dirs, desktop_file_dir_new (dirs[i]));
+ home = g_get_home_dir ();
+ if (guix_profile_monitor == NULL && home != NULL)
+ {
+ DesktopFileDir *dir;
+ const gchar *profile, *data_dir;
+ profile = g_build_filename (home, ".guix-profile", NULL);
+ data_dir = g_build_filename (profile, "share", NULL);
+ dir = desktop_file_dir_new (data_dir);
+
+ /* Monitor ~/.guix-profile and treat modifications to
+ ~/.guix-profile as if they were modifications to
+ ~/.guix-profile/share. */
+ guix_profile_monitor =
+ g_local_file_monitor_new_in_worker (profile, FALSE, G_FILE_MONITOR_NONE,
+ guix_profile_changed,
+ desktop_file_dir_ref (dir),
+ closure_notify_cb, NULL);
+
+ g_ptr_array_add (desktop_file_dirs, desktop_file_dir_ref (dir));
+ }
+
/* The list of directories will never change after this, unless
* g_get_user_config_dir() changes due to %G_TEST_OPTION_ISOLATE_DIRS. */
desktop_file_dirs_config_dir = user_config_dir;
L
L
Leo Prikler wrote on 4 Nov 2020 00:28
(name . Maxim Cournoyer)(address . maxim.cournoyer@gmail.com)
63d4101b796673602872997b7680d6b04a189de3.camel@student.tugraz.at
Hi Ludo,

Am Dienstag, den 03.11.2020, 23:46 +0100 schrieb Ludovic Courtès:
Toggle quote (12 lines)
> Ludovic Courtès <ludo@gnu.org> skribis:
>
> > This is not news to us, but as
> > <https://distrowatch.com/weekly.php?issue=20190624#guixsd> notes,
> > the
> > application menu of desktop environments is not automatically
> > updated
> > when a package is installed or removed. It’d be great if we could
> > somehow notify the desktop environment.
>
> We’ve investigated today on IRC with Maxim and Leo P. and here’s the
> summary of our findings:
Seeing my name thrown around more and more lately makes me blush a
little.
Toggle quote (8 lines)
> [...]
>
> The GLib patch below is an attempt to monitor ~/.guix-profile and to
> treat changes to that symlink as if they were changes to
> ~/.guix-profile/share/applications (which contains ‘.desktop’ files.)
> It actually builds but I haven’t tested it yet. :-)
>
> WDYT?
Not having tested it either, I think that we should also listen on
/run/current-system/ (if it exists), so that changes to the system as
done by `reconfigure` are picked up. This includes most importantly
changes to the GNOME ecosystem itself.

Regards, Leo
L
L
Ludovic Courtès wrote on 4 Nov 2020 21:55
control message for bug #36376
(address . control@debbugs.gnu.org)
87lffg7sg5.fsf@gnu.org
merge 36376 35594
quit
M
M
Maxim Cournoyer wrote on 4 Nov 2020 22:41
Re: bug#36376: Application menu of desktop environment not automatically updated
(name . Leo Prikler)(address . leo.prikler@student.tugraz.at)
87v9ekyf2x.fsf@gmail.com
Hello Ludovic and Leo,

Leo Prikler <leo.prikler@student.tugraz.at> writes:

Toggle quote (26 lines)
> Hi Ludo,
>
> Am Dienstag, den 03.11.2020, 23:46 +0100 schrieb Ludovic Courtès:
>> Ludovic Courtès <ludo@gnu.org> skribis:
>>
>> > This is not news to us, but as
>> > <https://distrowatch.com/weekly.php?issue=20190624#guixsd> notes,
>> > the
>> > application menu of desktop environments is not automatically
>> > updated
>> > when a package is installed or removed. It’d be great if we could
>> > somehow notify the desktop environment.
>>
>> We’ve investigated today on IRC with Maxim and Leo P. and here’s the
>> summary of our findings:
> Seeing my name thrown around more and more lately makes me blush a
> little.
>> [...]
>>
>> The GLib patch below is an attempt to monitor ~/.guix-profile and to
>> treat changes to that symlink as if they were changes to
>> ~/.guix-profile/share/applications (which contains ‘.desktop’ files.)
>> It actually builds but I haven’t tested it yet. :-)
>>
>> WDYT?

Pretty cool! It'd keep on working even if we even clean up /etc/profile
from the hardcoded defauts environment variables (say, if we merge one
of the proposed solution of https://issues.guix.gnu.org/22138).

Toggle quote (5 lines)
> Not having tested it either, I think that we should also listen on
> /run/current-system/ (if it exists), so that changes to the system as
> done by `reconfigure` are picked up. This includes most importantly
> changes to the GNOME ecosystem itself.

I agree that it seems useful and important to add a monitor on the
/run/current-system as well.

Thank you!

Maxim
L
L
Ludovic Courtès wrote on 4 Nov 2020 23:15
(name . Leo Prikler)(address . leo.prikler@student.tugraz.at)
878sbg7oqw.fsf@gnu.org
Hi!

Leo Prikler <leo.prikler@student.tugraz.at> skribis:

Toggle quote (16 lines)
> Am Dienstag, den 03.11.2020, 23:46 +0100 schrieb Ludovic Courtès:
>> Ludovic Courtès <ludo@gnu.org> skribis:
>>
>> > This is not news to us, but as
>> > <https://distrowatch.com/weekly.php?issue=20190624#guixsd> notes,
>> > the
>> > application menu of desktop environments is not automatically
>> > updated
>> > when a package is installed or removed. It’d be great if we could
>> > somehow notify the desktop environment.
>>
>> We’ve investigated today on IRC with Maxim and Leo P. and here’s the
>> summary of our findings:
> Seeing my name thrown around more and more lately makes me blush a
> little.

Heheh, you provided useful hints!

Toggle quote (11 lines)
>> The GLib patch below is an attempt to monitor ~/.guix-profile and to
>> treat changes to that symlink as if they were changes to
>> ~/.guix-profile/share/applications (which contains ‘.desktop’ files.)
>> It actually builds but I haven’t tested it yet. :-)
>>
>> WDYT?
> Not having tested it either, I think that we should also listen on
> /run/current-system/ (if it exists), so that changes to the system as
> done by `reconfigure` are picked up. This includes most importantly
> changes to the GNOME ecosystem itself.

Like I wrote in the related bug, I think /run/current-system is less
important because it typically doesn’t change much:


But I guess I’m also being a bit lazy…

Anyhow, I’ve tested the patch in ‘guix system vm
gnu/system/examples/desktop.tmpl’, with a ‘glib’ replacement as shown
below. I strace’d the user’s gnome-shell and ran:

ln -s /run/current-system/profile ~/.guix-profile

The trace showed that this led gnome-shell to traverse files in
~/.guix-profile/share (not just the applications/ sub-directory.)

I wanted to test ‘guix install’ for real, which meant doing it on ‘guix
system vm-image’, but that took too long; so I tried ‘disk-image -t
qcow2’ instead but partition.img.drv fails. So I haven’t been able to
actually test with ‘guix install’.

Anyway, here’s the Guix patch. You need to drop the GLib patch in the
right place.

Thanks,
Ludo’.
Toggle diff (58 lines)
diff --git a/gnu/packages/glib.scm b/gnu/packages/glib.scm
index bba9461d44..1c0de6eaed 100644
--- a/gnu/packages/glib.scm
+++ b/gnu/packages/glib.scm
@@ -181,6 +181,7 @@ shared NFS home directories.")
(package
(name "glib")
(version "2.62.6")
+ (replacement glib-with-gio-patch)
(source (origin
(method url-fetch)
(uri (string-append "mirror://gnome/sources/"
@@ -387,6 +388,14 @@ dynamic loading, and an object system.")
(home-page "https://developer.gnome.org/glib/")
(license license:lgpl2.1+)))
+(define glib-with-gio-patch
+ (package
+ (inherit glib)
+ (source (origin
+ (inherit (package-source glib))
+ (patches (append (search-patches "glib-appinfo-watch.patch")
+ (origin-patches (package-source glib))))))))
+
(define-public glib-with-documentation
;; glib's doc must be built in a separate package since it requires gtk-doc,
;; which in turn depends on glib.
diff --git a/gnu/system/examples/desktop.tmpl b/gnu/system/examples/desktop.tmpl
index 716b9feb8d..4797111c67 100644
--- a/gnu/system/examples/desktop.tmpl
+++ b/gnu/system/examples/desktop.tmpl
@@ -4,7 +4,7 @@
(use-modules (gnu) (gnu system nss))
(use-service-modules desktop xorg)
-(use-package-modules certs gnome)
+(use-package-modules certs gnome linux)
(operating-system
(host-name "antelope")
@@ -57,7 +57,8 @@
;; for HTTPS access
nss-certs
;; for user mounts
- gvfs)
+ gvfs
+ strace)
%base-packages))
;; Add GNOME and Xfce---we can choose at the log-in screen
@@ -65,7 +66,6 @@
;; include the X11 log-in service, networking with
;; NetworkManager, and more.
(services (append (list (service gnome-desktop-service-type)
- (service xfce-desktop-service-type)
(set-xorg-configuration
(xorg-configuration
(keyboard-layout keyboard-layout))))
M
M
Maxim Cournoyer wrote on 4 Nov 2020 23:28
control message for bug #41298
(address . control@debbugs.gnu.org)
87r1p8ycxh.fsf@gmail.com
merge 41298 35594
quit
M
M
Maxim Cournoyer wrote on 5 Nov 2020 07:38
Re: bug#36376: Application menu of desktop environment not automatically updated
(name . Ludovic Courtès)(address . ludo@gnu.org)
87d00swboe.fsf@gmail.com
Hi Ludovic!

Toggle quote (56 lines)
> +static void
> +guix_profile_changed (GFileMonitor *monitor,
> + GFile *file,
> + GFile *other_file,
> + GFileMonitorEvent event_type,
> + gpointer user_data)
> +{
> + DesktopFileDir *dir = user_data;
> +
> + desktop_file_dir_reset (dir);
> +
> + /* When ~/.guix-profile changes, emit the 'changed' signal so everyone
> + knows. */
> + g_app_info_monitor_fire ();
> +}
> +
> static void
> desktop_file_dir_changed (GFileMonitor *monitor,
> GFile *file,
> @@ -1531,6 +1548,7 @@ desktop_file_dirs_lock (void)
>
> if (desktop_file_dirs == NULL || desktop_file_dirs->len == 0)
> {
> + const gchar *home;
> const char * const *dirs;
> gint i;
>
> @@ -1555,6 +1573,27 @@ desktop_file_dirs_lock (void)
> for (i = 0; dirs[i]; i++)
> g_ptr_array_add (desktop_file_dirs, desktop_file_dir_new (dirs[i]));
>
> + home = g_get_home_dir ();
> + if (guix_profile_monitor == NULL && home != NULL)
> + {
> + DesktopFileDir *dir;
> + const gchar *profile, *data_dir;
> + profile = g_build_filename (home, ".guix-profile", NULL);
> + data_dir = g_build_filename (profile, "share", NULL);
> + dir = desktop_file_dir_new (data_dir);
> +
> + /* Monitor ~/.guix-profile and treat modifications to
> + ~/.guix-profile as if they were modifications to
> + ~/.guix-profile/share. */
> + guix_profile_monitor =
> + g_local_file_monitor_new_in_worker (profile, FALSE, G_FILE_MONITOR_NONE,
> + guix_profile_changed,
> + desktop_file_dir_ref (dir),
> + closure_notify_cb, NULL);
> +
> + g_ptr_array_add (desktop_file_dirs, desktop_file_dir_ref (dir));
> + }
> +
> /* The list of directories will never change after this, unless
> * g_get_user_config_dir() changes due to %G_TEST_OPTION_ISOLATE_DIRS. */
> desktop_file_dirs_config_dir = user_config_dir;

I think the attached patch is an improvement over the above, by also
supporting /run/current-system/share, being a bit simpler, and not
adding extra monitors.

I've reused the cool trick of passing FALSE to
g_local_file_monitor_new_in_worker to force it to use its polling mode
fallback.
From a79645c565e56ac201e66936d9f9883ad9387b06 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Thu, 5 Nov 2020 00:24:29 -0500
Subject: [PATCH] gdesktopappinfo: Fix monitoring of a Guix profile
XDG_DATA_DIR.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit


Treat the $HOME/.guix-profile/share and /run/current-system/share
XDG_DATA_DIRS file names specially so that the inotify-based monitors
placed by GLib monitor their parent link rather than an immutable
directory.

Co-authored by Ludovic Courtès <?udo@gnu.org>.
---
gio/gdesktopappinfo.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)

Toggle diff (43 lines)
diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
index f1e2fdd65..e659034d5 100644
--- a/gio/gdesktopappinfo.c
+++ b/gio/gdesktopappinfo.c
@@ -1380,7 +1380,8 @@ closure_notify_cb (gpointer data,
static void
desktop_file_dir_init (DesktopFileDir *dir)
{
- const gchar *watch_dir;
+ const gchar *watch_dir, *guix_profile_data, *system_profile_data;
+ gboolean is_directory = TRUE;
g_assert (!dir->is_setup);
@@ -1390,13 +1391,25 @@ desktop_file_dir_init (DesktopFileDir *dir)
dir->alternatively_watching = desktop_file_dir_get_alternative_dir (dir);
watch_dir = dir->alternatively_watching ? dir->alternatively_watching : dir->path;
+ /* Workaround for Guix: watch the link of a profile, not its
+ * immutable 'share' sub-directory. */
+ guix_profile_data = g_build_filename (g_get_home_dir (), ".guix-profile", "share", NULL);
+ system_profile_data = "/run/current-system/share";
+
+ if (g_str_equal (watch_dir, guix_profile_data)
+ || g_str_equal (watch_dir, system_profile_data))
+ {
+ is_directory = FALSE;
+ watch_dir = g_path_get_dirname (watch_dir);
+ }
+
/* There is a very thin race here if the watch_dir has been _removed_
* between when we checked for it and when we establish the watch.
* Removes probably don't happen in usual operation, and even if it
* does (and we catch the unlikely race), the only degradation is that
* we will fall back to polling.
*/
- dir->monitor = g_local_file_monitor_new_in_worker (watch_dir, TRUE, G_FILE_MONITOR_NONE,
+ dir->monitor = g_local_file_monitor_new_in_worker (watch_dir, is_directory, G_FILE_MONITOR_NONE,
desktop_file_dir_changed,
desktop_file_dir_ref (dir),
closure_notify_cb, NULL);
--
2.28.0
It's untested because 'guix vm' is taking more time to complete than I'm
willing to wait for in the middle of the night :-). I'll try it
tomorrow.

Thanks,

Maxim
L
L
Ludovic Courtès wrote on 6 Nov 2020 17:02
(name . Maxim Cournoyer)(address . maxim.cournoyer@gmail.com)
878sbexylp.fsf@gnu.org
Hi Maxim,

Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:

Toggle quote (17 lines)
> From a79645c565e56ac201e66936d9f9883ad9387b06 Mon Sep 17 00:00:00 2001
> From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
> Date: Thu, 5 Nov 2020 00:24:29 -0500
> Subject: [PATCH] gdesktopappinfo: Fix monitoring of a Guix profile
> XDG_DATA_DIR.
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> Fixes <https://issues.guix.gnu.org/35594>.
>
> Treat the $HOME/.guix-profile/share and /run/current-system/share
> XDG_DATA_DIRS file names specially so that the inotify-based monitors
> placed by GLib monitor their parent link rather than an immutable
> directory.
>
> Co-authored by Ludovic Courtès <?udo@gnu.org>.
^
This is LATIN SMALL LETTER L WITH CEDILLA. :-)

Toggle quote (4 lines)
> ---
> gio/gdesktopappinfo.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)

I like that it’s short and sweet, nice!

Thanks,
Ludo’.
M
M
Maxim Cournoyer wrote on 6 Nov 2020 19:56
(name . Ludovic Courtès)(address . ludo@gnu.org)
87r1p6tiut.fsf@gmail.com
Hey Ludovic,

Ludovic Courtès <ludo@gnu.org> writes:

Toggle quote (30 lines)
> Hi Maxim,
>
> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>
>> From a79645c565e56ac201e66936d9f9883ad9387b06 Mon Sep 17 00:00:00 2001
>> From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
>> Date: Thu, 5 Nov 2020 00:24:29 -0500
>> Subject: [PATCH] gdesktopappinfo: Fix monitoring of a Guix profile
>> XDG_DATA_DIR.
>> MIME-Version: 1.0
>> Content-Type: text/plain; charset=UTF-8
>> Content-Transfer-Encoding: 8bit
>>
>> Fixes <https://issues.guix.gnu.org/35594>.
>>
>> Treat the $HOME/.guix-profile/share and /run/current-system/share
>> XDG_DATA_DIRS file names specially so that the inotify-based monitors
>> placed by GLib monitor their parent link rather than an immutable
>> directory.
>>
>> Co-authored by Ludovic Courtès <?udo@gnu.org>.
> ^
> This is LATIN SMALL LETTER L WITH CEDILLA. :-)
>
>> ---
>> gio/gdesktopappinfo.c | 17 +++++++++++++++--
>> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> I like that it’s short and sweet, nice!

I thought too, but it doesn't work, because these entries never make it
to XDG_DATA_DIRS in the first place, at least for the system profile.

I also gave a try to 1) a modified version of your patch that added
support for /run/current-system and 2) your patch unmodified with
inconclusive results so far.

I did see things being scanned in response to /run/current-system
changing, but I believe this was because I goofed up the dir path to
"/run/current-system/share" (it should have been
""/run/current-system/profile/share"), and there's some code
gdesktopappinfo.c (desktop_file_dir_get_alternative_dir) that sets the
monitored directory to a parent when the directory doesn't exist.

In either version, strace failed to show any activity upon recreating
the ~/.guix-profile (that is /root/.guix-profile since I was testing as
root in the VM) link, different to what you had found.

So, to be continued...

Maxim
L
L
Ludovic Courtès wrote on 10 Nov 2020 16:23
(name . Maxim Cournoyer)(address . maxim.cournoyer@gmail.com)
87lff9nsl0.fsf@gnu.org
Hi Maxim,

So I went further to test the initial GLib patch I posted in “real
conditions”.

‘guix system vm-image’ takes an awful lot of time for big images; I
patiently waited for completion for an image of ‘desktop.tmpl’, but then
its root file system turned out to be too small for me to run ‘guix
install’.

So instead I tried this:

1. ‘guix system vm desktop.tmpl’;

2. ‘guix install inkscape -p /tmp/test’ on my actual machine;

3. Start the GNOME VM created above;

4. Inside the VM, search for Inkscape, notice it’s not there;

5. Inside the VM, have ~/.guix-profile point to the profile created on
the host above, and notice that Inkscape becomes available.

Video!


So I think we should include this fix in 1.2. What do people think?

The main downside is extra grafting, which means extra disk and CPU
usage for our users. However, libx11 (11K dependents) is also grafted,
so it shouldn’t make things worse (GLib has 6K dependents).

Maxim, did you have a variant of the GLib patch that also checks
/run/current-system?

Thanks,
Ludo’.
Z
Z
zimoun wrote on 10 Nov 2020 18:48
(name . Ludovic Courtès)(address . ludo@gnu.org)
CAJ3okZ216jq9Q=ML-yFN-CW-P95sHV5KDAQcw_7O7YJ6Uc-Gvg@mail.gmail.com
On Tue, 10 Nov 2020 at 16:25, Ludovic Courtès <ludo@gnu.org> wrote:

Toggle quote (2 lines)
> Video!

Héhé! Nice :-)

Toggle quote (2 lines)
> So I think we should include this fix in 1.2. What do people think?

You mean only the initial patch. If it works in "real conditions" for
bob on 'antelope' (desktop.tmpl), then it would nice to have for 1.2,


Toggle quote (4 lines)
> The main downside is extra grafting, which means extra disk and CPU
> usage for our users. However, libx11 (11K dependents) is also grafted,
> so it shouldn’t make things worse (GLib has 6K dependents).

No free lunch. :-)
Is it really slow or acceptable?


All the best,
simon
L
L
Ludovic Courtès wrote on 10 Nov 2020 22:23
(name . zimoun)(address . zimon.toutoune@gmail.com)
871rh0oqie.fsf@gnu.org
Hi,

zimoun <zimon.toutoune@gmail.com> skribis:

Toggle quote (2 lines)
> On Tue, 10 Nov 2020 at 16:25, Ludovic Courtès <ludo@gnu.org> wrote:

[...]

Toggle quote (7 lines)
>> The main downside is extra grafting, which means extra disk and CPU
>> usage for our users. However, libx11 (11K dependents) is also grafted,
>> so it shouldn’t make things worse (GLib has 6K dependents).
>
> No free lunch. :-)
> Is it really slow or acceptable?

If you’re installing a graphical applications, it’s already being
grafted, so the extra graft doesn’t make a difference.

Non-graphical applications that depend on GLib will now need to be
grafted, but I think there aren’t many of them, and they too might also
be grafted for other reasons.

Ludo’.
L
L
Ludovic Courtès wrote on 12 Nov 2020 16:56
(name . Maxim Cournoyer)(address . maxim.cournoyer@gmail.com)
87d00iin6w.fsf@gnu.org
Hi!

Ludovic Courtès <ludo@gnu.org> skribis:

Toggle quote (3 lines)
> So I went further to test the initial GLib patch I posted in “real
> conditions”.

I did some more testing using a similar workflow: this time I repeatedly
changed the profile (installing/removing packages), which showed that
the first patch was buggy (it would only notice the creation of
~/.guix-profile and nothing beyond that).

This is in part due to the fact that ‘GFileMonitor’ follows symlinks (it
doesn’t pass the ‘IN_DONT_FOLLOW’ inotify flag). Thus, when it monitors
~/.guix-profile, it’s really monitoring /gnu/store/…-profile, which
never changes.

So with this new patch it’s monitoring /var/guix/profiles/per-user/USER
and /var/guix/profiles instead, which correctly detects changes. It
detects a bit “too much” (for instance, running ‘guix pull’ triggers the
inotify hook because it changes
/var/guix/profiles/per-user/USER/current-guix) but that’s probably OK.

If you’re using GNOME, Xfce, or another GLib-based desktop environment,
I’d welcome tests on the bare metal! Just apply the patch on a checkout
of ‘master’ and run:

sudo -E ./pre-inst-env guix system reconfigure …

If there are no objections, I’d like to apply this patch shortly so we
can go ahead with a last round of pre-release tests.

Ludo’.
L
L
Ludovic Courtès wrote on 13 Nov 2020 21:38
Re: bug#35594: bug#36376: Application menu of desktop environment not automatically updated
(name . Maxim Cournoyer)(address . maxim.cournoyer@gmail.com)
87a6vlat66.fsf@gnu.org
Ludovic Courtès <ludo@gnu.org> skribis:

Toggle quote (15 lines)
>>From 7d03b2b823951219ece46c7f34e25ae36a8ba12c Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
> Date: Thu, 12 Nov 2020 16:35:24 +0100
> Subject: [PATCH] gnu: glib: Graft patch to detect changes to the installed
> applications.
>
> Fixes <https://bugs.gnu.org/35594>.
> Reported by sirgazil <sirgazil@zoho.com> and others.
>
> * gnu/packages/patches/glib-appinfo-watch.patch: New file.
> * gnu/local.mk (dist_patch_DATA): Add it.
> * gnu/packages/glib.scm (glib)[replacement]: New field.
> (glib-with-gio-patch): New variable.
> (glib-with-documentation): Use 'package/inherit'.

Pushed as ae10ec441aa524bf267f9cefd4a319b44d0b8b44 (version-1.2.0).

Ludo’.
Closed
M
M
Maxim Cournoyer wrote on 17 Nov 2020 05:57
Re: bug#36376: Application menu of desktop environment not automatically updated
(name . Ludovic Courtès)(address . ludo@gnu.org)
875z64d1hr.fsf@gmail.com
Hello Ludovic!

Ludovic Courtès <ludo@gnu.org> writes:

[...]

Toggle quote (10 lines)
> So with this new patch it’s monitoring /var/guix/profiles/per-user/USER
> and /var/guix/profiles instead, which correctly detects changes. It
> detects a bit “too much” (for instance, running ‘guix pull’ triggers the
> inotify hook because it changes
> /var/guix/profiles/per-user/USER/current-guix) but that’s probably OK.
>
> If you’re using GNOME, Xfce, or another GLib-based desktop environment,
> I’d welcome tests on the bare metal! Just apply the patch on a checkout
> of ‘master’ and run:

I've now done so! It works :-)! I do have noticed something a bit off,
see the comments below.

[...]

Toggle quote (62 lines)
> diff --git a/gnu/packages/patches/glib-appinfo-watch.patch b/gnu/packages/patches/glib-appinfo-watch.patch
> new file mode 100644
> index 0000000000..638a5e0949
> --- /dev/null
> +++ b/gnu/packages/patches/glib-appinfo-watch.patch
> @@ -0,0 +1,92 @@
> +This patch lets GLib's GDesktopAppInfo API watch and notice changes
> +to the Guix user and system profiles. That way, the list of available
> +applications shown by the desktop environment is immediately updated
> +when the user runs "guix install", "guix remove", or "guix system
> +reconfigure" (see <https://issues.guix.gnu.org/35594>).
> +
> +It does so by monitoring /var/guix/profiles (for changes to the system
> +profile) and /var/guix/profiles/per-user/USER (for changes to the user
> +profile) and crawling their share/applications sub-directory when
> +changes happen.
> +
> +diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
> +index f1e2fdd..095c110 100644
> +--- a/gio/gdesktopappinfo.c
> ++++ b/gio/gdesktopappinfo.c
> +@@ -148,6 +148,7 @@ typedef struct
> + gchar *alternatively_watching;
> + gboolean is_config;
> + gboolean is_setup;
> ++ gchar *guix_profile_watch_dir;
> + GFileMonitor *monitor;
> + GHashTable *app_names;
> + GHashTable *mime_tweaks;
> +@@ -180,6 +181,7 @@ desktop_file_dir_unref (DesktopFileDir *dir)
> + {
> + desktop_file_dir_reset (dir);
> + g_free (dir->path);
> ++ g_free (dir->guix_profile_watch_dir);
> + g_free (dir);
> + }
> + }
> +@@ -204,6 +206,13 @@ desktop_file_dir_get_alternative_dir (DesktopFileDir *dir)
> + {
> + gchar *parent;
> +
> ++ /* If DIR is a profile, watch the specified directory--e.g.,
> ++ * /var/guix/profiles/per-user/$USER/ for the user profile. Do not watch
> ++ * ~/.guix-profile or /run/current-system/profile because GFileMonitor does
> ++ * not pass IN_DONT_FOLLOW and thus cannot notice any change. */
> ++ if (dir->guix_profile_watch_dir != NULL)
> ++ return g_strdup (dir->guix_profile_watch_dir);
> ++
> + /* If the directory itself exists then we need no alternative. */
> + if (g_access (dir->path, R_OK | X_OK) == 0)
> + return NULL;
> +@@ -249,11 +258,11 @@ desktop_file_dir_changed (GFileMonitor *monitor,
> + *
> + * If this is a notification for a parent directory (because the
> + * desktop directory didn't exist) then we shouldn't fire the signal
> +- * unless something actually changed.
> ++ * unless something actually changed or it's in /var/guix/profiles.
> + */
> + g_mutex_lock (&desktop_file_dir_lock);
> +
> +- if (dir->alternatively_watching)
> ++ if (dir->alternatively_watching && dir->guix_profile_watch_dir == NULL)
^^^^^^
Why is this needed/desirable?

OK, I think I get it. The API seems to imply that users (such as
gnome-shell) need to keep asking about a desktop directory entry as they
are otherwise "forgotten". Since we are inserting entries at the level
of glib ourselves, these will never be asked for by gnome-shell, so must
not be cleared. Is that correct?

Toggle quote (21 lines)
> + {
> + gchar *alternative_dir;
> +
> +@@ -1555,6 +1564,32 @@ desktop_file_dirs_lock (void)
> + for (i = 0; dirs[i]; i++)
> + g_ptr_array_add (desktop_file_dirs, desktop_file_dir_new (dirs[i]));
> +
> ++ {
> ++ /* Monitor the system and user profile under /var/guix/profiles and
> ++ * treat modifications to them as if they were modifications to their
> ++ * /share sub-directory. */
> ++ const gchar *user;
> ++ DesktopFileDir *system_profile_dir, *user_profile_dir;
> ++
> ++ system_profile_dir =
> ++ desktop_file_dir_new ("/var/guix/profiles/system/profile/share");
> ++ system_profile_dir->guix_profile_watch_dir = g_strdup ("/var/guix/profiles");
> ++ g_ptr_array_add (desktop_file_dirs, desktop_file_dir_ref (system_profile_dir));
> ++
> ++ user = g_get_user_name ();

This seems to get the user of the running glib application; e.g. for
GNOME Shell it returns 'gdm'...

Toggle quote (14 lines)
> ++ if (user != NULL)
> ++ {
> ++ gchar *profile_dir, *user_data_dir;
> ++
> ++ profile_dir = g_build_filename ("/var/guix/profiles/per-user", user, NULL);
> ++ user_data_dir = g_build_filename (profile_dir, "guix-profile", "share", NULL);
> ++ user_profile_dir = desktop_file_dir_new (user_data_dir);
> ++ user_profile_dir->guix_profile_watch_dir = profile_dir;
> ++ g_ptr_array_add (desktop_file_dirs, desktop_file_dir_ref (user_profile_dir));
> ++ g_free (user_data_dir);
> ++ }
> ++ }
> ++

...which means the above puts the watch on the
"/var/guix/profiles/per-user/gdm" directory, which doesn't exist.

sudo strace -f -s200 -p$(pgrep gnome-shell | head -n1) reports entries
such as:

Toggle snippet (9 lines)
92 00:48:47 poll([{fd=6, events=POLLIN}, {fd=7, events=POLLIN}, {fd=9, events=POLLIN}, {fd=19, events=POLLIN}, {fd=28, events=POLLIN}], 5, -1 <unfinished ...>
390 00:48:47 <... poll resumed>) = 0 (Timeout)
390 00:48:47 inotify_add_watch(17, "/var/guix/profiles/per-user/gdm", IN_MODIFY|IN_ATTRIB|IN_CLOSE_WRITE|IN_MOVED_FROM|IN_MOVED_TO|IN_CREATE|IN_DELETE|IN_DELETE_SELF|IN_MOVE_SELF|IN_UNMOUNT|IN_ONLYDIR) = -1 ENOENT (No such file or directory)
390 00:48:47 poll([{fd=3, events=POLLIN}, {fd=17, events=POLLIN}], 2, 3996) = 0 (Timeout)
390 00:48:51 inotify_add_watch(17, "/var/guix/profiles/per-user/gdm", IN_MODIFY|IN_ATTRIB|IN_CLOSE_WRITE|IN_MOVED_FROM|IN_MOVED_TO|IN_CREATE|IN_DELETE|IN_DELETE_SELF|IN_MOVE_SELF|IN_UNMOUNT|IN_ONLYDIR) = -1 ENOENT (No such file or directory)
390 00:48:51 poll([{fd=3, events=POLLIN}, {fd=17, events=POLLIN}], 2, 3998) = 0 (Timeout)
390 00:48:55 inotify_add_watch(17, "/var/guix/profiles/per-user/gdm", IN_MODIFY|IN_ATTRIB|IN_CLOSE_WRITE|IN_MOVED_FROM|IN_MOVED_TO|IN_CREATE|IN_DELETE|IN_DELETE_SELF|IN_MOVE_SELF|IN_UNMOUNT|IN_ONLYDIR) = -1 ENOENT (No such file or directory)

The fallback mechanism should have been disabled in
desktop_file_dir_changed (dir->guix-profile_watch_dir != NULL so
desktop_file_dir_get_alternative_dir doesn't get called), so it seems
this shouldn't work.

Could it be that the watches used by glib implement a recursive
inotify-based watch and that it works because any changes under the
/var/guix/profiles directory get picked up, including those of user
profiles. The sources seem to suggest so, for example in
gio/inotify/inotify-path.c. If that is the case, it could lead to a new
interesting problems: applications from other users could end up being
shown inadvertently.

I'll try to validate the above hypothesis, but this takes time.

In any case, the current situation is already an improvement, so thank
you for your efforts!

Maxim
L
L
Ludovic Courtès wrote on 17 Nov 2020 10:08
(name . Maxim Cournoyer)(address . maxim.cournoyer@gmail.com)
87eekstkny.fsf@gnu.org
Hi Maxim,

Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:

Toggle quote (17 lines)
> Ludovic Courtès <ludo@gnu.org> writes:
>
> [...]
>
>> So with this new patch it’s monitoring /var/guix/profiles/per-user/USER
>> and /var/guix/profiles instead, which correctly detects changes. It
>> detects a bit “too much” (for instance, running ‘guix pull’ triggers the
>> inotify hook because it changes
>> /var/guix/profiles/per-user/USER/current-guix) but that’s probably OK.
>>
>> If you’re using GNOME, Xfce, or another GLib-based desktop environment,
>> I’d welcome tests on the bare metal! Just apply the patch on a checkout
>> of ‘master’ and run:
>
> I've now done so! It works :-)! I do have noticed something a bit off,
> see the comments below.

Thanks for testing!

Toggle quote (14 lines)
>> +@@ -249,11 +258,11 @@ desktop_file_dir_changed (GFileMonitor *monitor,
>> + *
>> + * If this is a notification for a parent directory (because the
>> + * desktop directory didn't exist) then we shouldn't fire the signal
>> +- * unless something actually changed.
>> ++ * unless something actually changed or it's in /var/guix/profiles.
>> + */
>> + g_mutex_lock (&desktop_file_dir_lock);
>> +
>> +- if (dir->alternatively_watching)
>> ++ if (dir->alternatively_watching && dir->guix_profile_watch_dir == NULL)
> ^^^^^^
> Why is this needed/desirable?

As the comment above states it, the ‘if’ is here so that the “changed”
signal is not fired when we’re just watching a parent directory.

However, in our case, ‘dir->alternatively_watching != NULL’ possibly
means that we’re watching a Guix profile, in which case we do want to
fire the “changed” signal.

This “&&” allows us to disambiguate between “watching a parent
directory” and “watching a Guix profile”.

Toggle quote (38 lines)
>> +@@ -1555,6 +1564,32 @@ desktop_file_dirs_lock (void)
>> + for (i = 0; dirs[i]; i++)
>> + g_ptr_array_add (desktop_file_dirs, desktop_file_dir_new (dirs[i]));
>> +
>> ++ {
>> ++ /* Monitor the system and user profile under /var/guix/profiles and
>> ++ * treat modifications to them as if they were modifications to their
>> ++ * /share sub-directory. */
>> ++ const gchar *user;
>> ++ DesktopFileDir *system_profile_dir, *user_profile_dir;
>> ++
>> ++ system_profile_dir =
>> ++ desktop_file_dir_new ("/var/guix/profiles/system/profile/share");
>> ++ system_profile_dir->guix_profile_watch_dir = g_strdup ("/var/guix/profiles");
>> ++ g_ptr_array_add (desktop_file_dirs, desktop_file_dir_ref (system_profile_dir));
>> ++
>> ++ user = g_get_user_name ();
>
> This seems to get the user of the running glib application; e.g. for
> GNOME Shell it returns 'gdm'...
>
>> ++ if (user != NULL)
>> ++ {
>> ++ gchar *profile_dir, *user_data_dir;
>> ++
>> ++ profile_dir = g_build_filename ("/var/guix/profiles/per-user", user, NULL);
>> ++ user_data_dir = g_build_filename (profile_dir, "guix-profile", "share", NULL);
>> ++ user_profile_dir = desktop_file_dir_new (user_data_dir);
>> ++ user_profile_dir->guix_profile_watch_dir = profile_dir;
>> ++ g_ptr_array_add (desktop_file_dirs, desktop_file_dir_ref (user_profile_dir));
>> ++ g_free (user_data_dir);
>> ++ }
>> ++ }
>> ++
>
> ...which means the above puts the watch on the
> "/var/guix/profiles/per-user/gdm" directory, which doesn't exist.

Yes, that profile is typically never populated.

Toggle quote (16 lines)
> sudo strace -f -s200 -p$(pgrep gnome-shell | head -n1) reports entries
> such as:
>
> 92 00:48:47 poll([{fd=6, events=POLLIN}, {fd=7, events=POLLIN}, {fd=9, events=POLLIN}, {fd=19, events=POLLIN}, {fd=28, events=POLLIN}], 5, -1 <unfinished ...>
> 390 00:48:47 <... poll resumed>) = 0 (Timeout)
> 390 00:48:47 inotify_add_watch(17, "/var/guix/profiles/per-user/gdm", IN_MODIFY|IN_ATTRIB|IN_CLOSE_WRITE|IN_MOVED_FROM|IN_MOVED_TO|IN_CREATE|IN_DELETE|IN_DELETE_SELF|IN_MOVE_SELF|IN_UNMOUNT|IN_ONLYDIR) = -1 ENOENT (No such file or directory)
> 390 00:48:47 poll([{fd=3, events=POLLIN}, {fd=17, events=POLLIN}], 2, 3996) = 0 (Timeout)
> 390 00:48:51 inotify_add_watch(17, "/var/guix/profiles/per-user/gdm", IN_MODIFY|IN_ATTRIB|IN_CLOSE_WRITE|IN_MOVED_FROM|IN_MOVED_TO|IN_CREATE|IN_DELETE|IN_DELETE_SELF|IN_MOVE_SELF|IN_UNMOUNT|IN_ONLYDIR) = -1 ENOENT (No such file or directory)
> 390 00:48:51 poll([{fd=3, events=POLLIN}, {fd=17, events=POLLIN}], 2, 3998) = 0 (Timeout)
> 390 00:48:55 inotify_add_watch(17, "/var/guix/profiles/per-user/gdm", IN_MODIFY|IN_ATTRIB|IN_CLOSE_WRITE|IN_MOVED_FROM|IN_MOVED_TO|IN_CREATE|IN_DELETE|IN_DELETE_SELF|IN_MOVE_SELF|IN_UNMOUNT|IN_ONLYDIR) = -1 ENOENT (No such file or directory)
>
> The fallback mechanism should have been disabled in
> desktop_file_dir_changed (dir->guix-profile_watch_dir != NULL so
> desktop_file_dir_get_alternative_dir doesn't get called), so it seems
> this shouldn't work.

What shouldn’t work?

We keep adding a watch on a non-existent directory, but I think that’s
fine.

Toggle quote (8 lines)
> Could it be that the watches used by glib implement a recursive
> inotify-based watch and that it works because any changes under the
> /var/guix/profiles directory get picked up, including those of user
> profiles. The sources seem to suggest so, for example in
> gio/inotify/inotify-path.c. If that is the case, it could lead to a new
> interesting problems: applications from other users could end up being
> shown inadvertently.

We’re watching /var/guix/profiles (for the system profile) and
/var/guix/profiles/per-user/USER, but .desktop files are loaded from the
user’s own profile, so that should be fine.

Thanks a lot for looking into this!

Ludo’.
M
M
Maxim Cournoyer wrote on 18 Nov 2020 05:34
(name . Ludovic Courtès)(address . ludo@gnu.org)
87d00b8eql.fsf@gmail.com
Hello Ludovic!

Ludovic Courtès <ludo@gnu.org> writes:

Toggle quote (6 lines)
> Hi Maxim,
>
> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>
>> Ludovic Courtès <ludo@gnu.org> writes:

[...]

Toggle quote (24 lines)
>>> +@@ -249,11 +258,11 @@ desktop_file_dir_changed (GFileMonitor *monitor,
>>> + *
>>> + * If this is a notification for a parent directory (because the
>>> + * desktop directory didn't exist) then we shouldn't fire the signal
>>> +- * unless something actually changed.
>>> ++ * unless something actually changed or it's in /var/guix/profiles.
>>> + */
>>> + g_mutex_lock (&desktop_file_dir_lock);
>>> +
>>> +- if (dir->alternatively_watching)
>>> ++ if (dir->alternatively_watching && dir->guix_profile_watch_dir == NULL)
>> ^^^^^^
>> Why is this needed/desirable?
>
> As the comment above states it, the ‘if’ is here so that the “changed”
> signal is not fired when we’re just watching a parent directory.
>
> However, in our case, ‘dir->alternatively_watching != NULL’ possibly
> means that we’re watching a Guix profile, in which case we do want to
> fire the “changed” signal.
>
> This “&&” allows us to disambiguate between “watching a parent
> directory” and “watching a Guix profile”.

Yes, this makes sense. I got confused by the wording of the (existing)
comment that mentions "unless something actually changed". I used to
think this meant the contents of whatever directory is being watched,
but looking more closely, it's really just about if the parent directory
of a non-existing data directory changed... Makes senses, we don't want
that.

Toggle quote (40 lines)
>>> +@@ -1555,6 +1564,32 @@ desktop_file_dirs_lock (void)
>>> + for (i = 0; dirs[i]; i++)
>>> + g_ptr_array_add (desktop_file_dirs, desktop_file_dir_new (dirs[i]));
>>> +
>>> ++ {
>>> ++ /* Monitor the system and user profile under /var/guix/profiles and
>>> ++ * treat modifications to them as if they were modifications to their
>>> ++ * /share sub-directory. */
>>> ++ const gchar *user;
>>> ++ DesktopFileDir *system_profile_dir, *user_profile_dir;
>>> ++
>>> ++ system_profile_dir =
>>> ++ desktop_file_dir_new ("/var/guix/profiles/system/profile/share");
>>> ++ system_profile_dir->guix_profile_watch_dir = g_strdup ("/var/guix/profiles");
>>> ++ g_ptr_array_add (desktop_file_dirs, desktop_file_dir_ref (system_profile_dir));
>>> ++
>>> ++ user = g_get_user_name ();
>>
>> This seems to get the user of the running glib application; e.g. for
>> GNOME Shell it returns 'gdm'...
>>
>>> ++ if (user != NULL)
>>> ++ {
>>> ++ gchar *profile_dir, *user_data_dir;
>>> ++
>>> ++ profile_dir = g_build_filename ("/var/guix/profiles/per-user", user, NULL);
>>> ++ user_data_dir = g_build_filename (profile_dir, "guix-profile", "share", NULL);
>>> ++ user_profile_dir = desktop_file_dir_new (user_data_dir);
>>> ++ user_profile_dir->guix_profile_watch_dir = profile_dir;
>>> ++ g_ptr_array_add (desktop_file_dirs, desktop_file_dir_ref (user_profile_dir));
>>> ++ g_free (user_data_dir);
>>> ++ }
>>> ++ }
>>> ++
>>
>> ...which means the above puts the watch on the
>> "/var/guix/profiles/per-user/gdm" directory, which doesn't exist.
>
> Yes, that profile is typically never populated.

Ah, I now understand the source of my confusion; there are multiple
gnome-shell instances (components?) running, one apparently started by
the greeter (GDM), which doesn't have a profile, and others started by
the users which logged in.

Thanks again for the fix and explanations!

Maxim
?
Your comment

This issue is archived.

To comment on this conversation send an email to 36376@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 36376
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch