Pass environment variables to systemd services

I am running kdeconnect with
‘’’
services.kdeconnect = {
enable = true;
indicator = true;
}
‘’’

But it doesn’t pick up my qt theme. I want to pass the env vars to use the kvantum theme in kdeconnect.service. How to do this?

1 Like

qt5.platformTheme should set the qt theme envvars. See NixOS Search

Do you already have this set?

It works. I see that internally it uses enviroment.variables to set QT_QPA_PLATFORM. Guess setting variables with home.sessionVariables does not work well.

Is there a way I can isolate this is home manager?

home.sessionVariables should work for most applications. However, it will not work for applications started (directly or indirectly) through systems. It only affects applications started within your user session.

Not sure if that helps. If not, do you have a specific case (process or executable) that fails to apply the theme?

Yes, most of the systray stuff. Kdeconnect, discord etc. Both are started in the user session.

You can also configure it with the same option in home-manager:

https://rycee.gitlab.io/home-manager/options.html#opt-qt.platformTheme

It seems to set the same 2 environment variables, but it does so using home.sessionVariables: home-manager/qt.nix at 054d9e3187ca00479e8036dc0e92900a384f30fd · nix-community/home-manager · GitHub

Maybe kvantum also needs to be added as a style package in home-manager?

The option Appendix A. Configuration Options needs to be set.

I see a package called libsForQt5.qtstyleplugin-kvantum: NixOS Search

qt.platformTheme docs say that "gtk" is to be used for qtstyleplugins.

From that I think the home-manager config should have something like:

qt.enable = true;
qt.platformTheme = "gtk";
qt.style.package = pkgs.libsForQt5.qtstyleplugin-kvantum;
qt.style.name = "kvantum";

Having the theme in home-manager should be enough and I think it doesn’t need to be in NixOS configuration when you’re using home-manager, but it also cannot hurt to set it in NixOS. I think it should be something like:

qt5.enable = true;
qt5.platformTheme = "gtk2";
environment.systemPackages = [ pkgs.libsForQt5.qtstyleplugin-kvantum ];

I wish there were more overarching configuration options like themes.kvantum.enable = true that just sets the theme everywhere where it is needed (qt, gtk, gnome, etc). This still is a bit cumbersome :sweat_smile:

I am using lxqt to config the themes. Too many glitches when using just kvantum.

The sessionVariables won’t work for systray stuff but the environment.variables does, weird. Maybe sessionVariables aren’t hooked into systemd services.