stylix icon indicating copy to clipboard operation
stylix copied to clipboard

gnome-text-editor: doesn't work with individual user themes

Open danth opened this issue 1 year ago • 8 comments

GNOME Text Editor renders code in the system level theme, while my Home Manager theme is different:

Screenshot showing the issue

Here's the same file in VSCode:

Screenshot showing the correct Home Manager theme

I assume this is because the package is installed system wide, so the overlay only applies at the system level.

Is there any way we can install a theme without overriding the package, at least in Home Manager? For example something in ~/.config?

CC @brckd

danth avatar Mar 05 '25 10:03 danth

I have already tried placing configs in the home folder in #747, but had no success. AFAIK the configs have to be placed in a XDG_DATA_DIRS directory, which is located at /run/current-system/sw/share on NixOS.

But that shouldn't be a problem and also the reason for why the overlay for Home Manager exists. You should be able to install the GNOME Text Editor as a home package and enable its Stylix module if you haven't enabled useGlobalPkgs. This way, the package could be overidden for each user individually.

If that doesn't work, perhaps the system package is overriding the home package, which I hope isn't the case. Try disabling the GNOME Text Editor package and Stylix module on NixOS in that case.

Sadly there doesn't seem to be a way to configure it with Home Manager if useGlobalPkgs is enabled. If that's desired, I can file an issue in the GNOME Text Editor repository.

bricked-dev avatar Mar 05 '25 12:03 bricked-dev

It's also possible I forgot to try XDG_DATA_HOME when placing the configs in the home directory, but AFAIK I checked that.

bricked-dev avatar Mar 05 '25 12:03 bricked-dev

I have useGlobalPkgs enabled, so that's why the overlay isn't applying in Home Manager. The default setup is to only install it at the system level, so even with useGlobalPkgs disabled there would still be a need to install the package manually.

Unfortunately there's not much Stylix can do to automate this as we don't want to install it for all users, and there's not always a way to check the NixOS configuration to see if should be installed, as Home Manager might be running independently.

Could we use a wrapper script to add a directory in ~ to $XDG_DATA_DIRS from the overlay, and then install a file in that directory using Home Manager? Or, add a directory which is passed in through an environment variable?

That way the overlay could be applied once at the system level, while being able to override the theme externally. This also avoids duplicating the package for each user.

danth avatar Mar 05 '25 12:03 danth

I created https://gitlab.gnome.org/GNOME/gnome-text-editor/-/issues/780 to make the GNOME Text Editor developers aware of this problem.

If I understand correctly, your suggestion is to copy some local configuration to share/gnome-text-editor whenever the GNOME Text Editor is run. I'm not sure that's possible because that directory is managed by Nix and probably immutable. In any case, it's a hacky solution, but possibly the only one available.

It might be possible to symlink e.g. share/generator-editor/styles/stylix-local.xml to the local configuration. This way, the local configuration can be enabled using DConf.

We could also try adding the local configuration to the XDG_DATA_DIRS environment variable.

bricked-dev avatar Mar 05 '25 14:03 bricked-dev

What I meant is to append a local directory to $XDG_DATA_DIRS, e.g. XDG_DATA_DIRS="$XDG_DATA_DIRS:$STYLIX_GNOME_TEXT_EDITOR_THEME" just before the program starts, so that we can then set $STYLIX_GNOME_TEXT_EDITOR_THEME from Home Manager without needing to override the package

danth avatar Mar 05 '25 16:03 danth

OK that sounds like a good solution! I'll see if the program actually reads the environment variable.

bricked-dev avatar Mar 05 '25 16:03 bricked-dev

On further thought I believe there's a Home Manager option to add paths to $XDG_DATA_DIRS globally, so if it works we could avoid overlays entirely (at the expense of the path being passed to all other applications, but they should just ignore it as $XDG_DATA_DIRS works similarly to $PATH)

danth avatar Mar 05 '25 16:03 danth

According to https://gitlab.gnome.org/GNOME/gnome-text-editor/-/issues/780#note_2370367, styles can be placed in ~/.local/share/gtksourceview-5/styles/! I think that would be the ideal solution. This way, we can also remove the Home Manager overlay alongside the issues it had.

bricked-dev avatar Mar 05 '25 17:03 bricked-dev