gtk: search immodules.cache in $NIX_PROFILE#14568
gtk: search immodules.cache in $NIX_PROFILE#14568ericsagnes wants to merge 3 commits intoNixOS:masterfrom
Conversation
|
Looks good to me and this solution also sounds better. I'll wait for others to test it just in case but if I understand correctly this shouldn't break any setups anymore. |
There was a problem hiding this comment.
This leaks memory in a few places:
paths, just add ag_strfreev(paths)at the end.cachePathneeds to be freed as well.- What should happen when more than one profile contains the
etc/gtk-3.0/immodules.cachedirectory?
(When running programs in valgrind to check for memory leaks, it is nice if there are no false positives from system libraries. Or more realistically, as few as possible.)
There was a problem hiding this comment.
What should happen when more than one profile contains the etc/gtk-3.0/immodules.cache directory?
In that case, the entry that occurs last in NIX_PROFILES should be used. IIUC, that's what this patch does, but my C is rusty. 😄
There was a problem hiding this comment.
Then all the previous entries will be leaked, three times in total: first because of the allocation in g_strsplit, then g_build_filename, and finally g_strdup--they all allocate their own copy.
Aside from that, shouldn't the environment variable GTK_IM_MODULE_FILE take precedence if it is set?
There was a problem hiding this comment.
@gebner Thanks for the memory leak information, I added g_strfreev(paths); and g_free(cachePath);, is that enough to fix it?
Aside from that, shouldn't the environment variable GTK_IM_MODULE_FILE take precedence if it is set?
It will, as the check for the GTK_IM_MODULE_FILE is after this patch logic and update result.
The code before patching is:
gchar *
gtk_rc_get_im_module_file (void)
{
const gchar *var = g_getenv ("GTK_IM_MODULE_FILE");
gchar *result = NULL;
// patch comes here
if (var)
result = g_strdup (var);
if (!result)
{
if (im_module_file)
result = g_strdup (im_module_file);
else
result = gtk_rc_make_default_dir ("immodules.cache");
}
return result;
}
PS: I have almost no C experience so if you can write a better patch I will be very happy to use it instead :)
There was a problem hiding this comment.
Thanks for the memory leak information, I added g_strfreev(paths); and g_free(cachePath);, is that enough to fix it?
Almost, there is still a leak when 1) there is more than one nix profile containing the immodule.cache file, and 2) if the environment variable GTK_IM_MODULE_FILE is set.
I think the easiest fix is to:
- Move the NIX_PROFILES check below the original one and change the
iftoif (nixProfilesEnv && !result). - Free the result variable before it is overwritten, i.e.
if (result) g_free(result)right before the assignment.
That should fix all of the memory leaks.
There was a problem hiding this comment.
Done, thanks again for all the advice!
60c8135 to
eb1b071
Compare
|
@taku0 Did you had time to test this PR? Also, maybe it would be better to add the |
|
Just to see if I'm reading this right: I have: So this would takes the last |
|
This might not be a big concern, but there is this to keep in mind: I would wonder if it would make sense to first check a variable along the lines of How does that sound? |
|
@cstrahan Thanks for the label! I updated the description so the issue will be easier to understand for persons that are not following it from #14417 and #14019.
Correct. That was unclear so I added the details in the issue description.
Are you using NixOS or Nix only? I find that |
eb1b071 to
cfe062f
Compare
Could you quote the portion you're referring to?
NixOS. |
|
... but my original example was to show that running |
Sorry, the 6 comments starting from this one.
I see, that was something I was unaware of, thanks for explaining. |
In general, one should not expect any GUI program, GTK or otherwise, NixOS or otherwise, to work with sudo. All of the toolkits and X itself rely far too heavily on environment settings. This is compounded by the fact that everything mysteriously depends on D-Bus nowadays 😃 |
|
Any objections to merge this? |
|
@astsmtl Personally, I think it is ready to merge. Speaking of that, I noticed in the manual that mass rebuild PR should be made against |
|
@abbradar I'm fine with this going into staging. |
|
uim still has the problem but I'm fine with merging since it is not critical. |
|
Ugh, I got immersed in other things to do and forgot this one. I'll merge in ~12 hours unless someone votes nay. On May 6, 2016 12:24:41 PM GMT+03:00, Eric Sagnes notifications@github.com wrote:
Nikolay. |
|
Closed by c99b050 |
|
Thanks! |
|
Hi @abbradar, I still cannot use fcitx on GTK after applying this commit. What should I do to debug? |
|
Please tell us:
|
|
@sorpaas After applying the patch did you rebuild your configuration with This commit is quite heavy as it will trigger the source build of In the mean time, if you want to use fcitx you can:
All of these should be quite cheap and trigger only a few rebuilds. Sorry for the inconvenience, I will update and close #14019 as soon as I see this commit reaching the unstable channel. |
|
Hi, I managed to fix this issue. I turned out to be some mis-configurations of my user profile. Sorry about the noise! |
This a fix for #14019 with a different approach than #14417.
See #14417 comments for details.
This PR triggers the rebuild of gtk+3 and gtk+2 and all the packages that depends on them.
Description
GTK im module cache
GTK application need to know the input method on the system to be able to use them.
For that purpose, gtk uses a cache file (
immodule.cache) that list all the paths to the input method library of the matching gtk version (this will be important later).The cache has to be updated everytime a new input method is installed or removed on the system by running the command
gtk-query-immodules-*.The default cache path of gtk is in the gtk package
lib/folder, making it incompatible with nix immutable packages.There are a few ways to override the default
immodules.cachefile,the default logic is (before the patch):
For gtk2
GTK_IM_MODULE_FILE, if present use itgtkrcfileim_module_filesetting, if present use itlib/gtk-2.0/2.10.0/immodules.cacheFor gtk3 (all the logic is deprecated and just for backward compatibility)
GTK_IM_MODULE_FILE, if present use itgtkrcfileim_module_filesetting, if present use itlib/gtk-3.0/3.0.0/immodules.cacheProblems with Nix
So the problems that we are facing with Nix are:
GTK_IM_MODULE_FILEto specify a ad-hoc cache file is fine, but the problem is gtk2 and gtk3 will use the same file, and every entry must point the input method library matching the gtk version-> we cannot make gtk2 and gtk3 work at the same time
Solutions
The first approach (#14417) was to patch gtk3 to make it look for
GTK3_IM_MODULE_FILEand use it if present, that allowed to have 2 different cache files,GTK3_IM_MODULE_FILEfor gtk3 andGTK_IM_MODULE_FILEfor gtk2.There was a problem though, that is if a package installed via
nix-envand not updated after anixos-rebuildwill still readGTK_IM_MODULE_FILEthat point to an input method gtk2 library, that would result in the application crashing.From there, @ttuegel suggested that we could use
NIX_PROFILESas it was done for Qt.That lead us to the current implementation based on
NIX_PROFILES.So the new logic is (after the patch):
For gtk2
GTK_IM_MODULE_FILE, if present use itNIX_PROFILES, and for each entry, check ifetc/gtk-2.0/immodules.cacheexists, use if present (the last entry having the file will have priority) [1]im_module_filesetting in thegtkrcfile, if present use itlib/gtk-2.0/2.10.0/immodules.cacheFor gtk3 (all the logic is deprecated and just for backward compatibility)
GTK_IM_MODULE_FILE, if present use itNIX_PROFILES, and for each entry, check ifetc/gtk-3.0/immodules.cacheexists, use if present (the last entry having the file will have priority) [1]im_module_filesetting in thegtkrcfile, if present use it (the code is here, but I am not even sure that gtk3 is looking for a gtkrc file in the first place)lib/gtk-3.0/3.0.0/immodules.cache[1] Regarding
NIX_PROFILESThe NIX_PROFILES variable is defined by reversing the list of entries in the
environment.profiles.If not changed, the order is
/run/current-system/sw/nix/var/nix/profiles/default$HOME/.nix-profile, from generic to specific.The order seems arbitrary (in the meaning that there is no mention about it in the option description) and can be changed.
But we can consider that few users are changing it, and if they do we can just hope that they respect the specific -> generic order (
NIX_PROFILESuse the reversed list ofenvironment.profiles).Anyway, in a normal use case there shouldn't be a cache file anywhere else than
/run/current-system/swas it is generated by the module system.If there is a cache in more that one location of the $NIX_PROFILE, the user did it on purpose and in my opinion, we can consider that he knows what he is doing.
Things done
nix-build --option build-use-chroot trueor nix.useChroot on NixOS)nix-shell -p nox --run "nox-review wip"./result/bin/)cc @ttuegel @taku0 @astsmtl @abbradar
pkgs/development/libraries/gtk+/3.x.nix.