NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.31k stars 14.27k forks source link

`qtct` is generally poorly supported by NixOS/HM #260696

Open e-tho opened 1 year ago

e-tho commented 1 year ago

These issues apply to my Hyprland + greetd environment, I haven't tested outside of it. Here's my current configuration:

  qt = {
    enable = true;
    platformTheme = "qtct"; # or "qt5ct" if using NixOS module
    style = {
      package = pkgs.colloid-kde;
      name = "kvantum";
    };
  };

When using the qt NixOS module, applications launched via systemd services aren't themed, but applications launched via Hyprland are.

When using the qt HM module, applications launched via Hyprland aren't themed, but applications launched via systemd services are.

There is currently a bug preventing qt6ct from accessing the Kvantum style.

It is currently impossible for pinentry-qt to use the theme correctly.

    gnupg = {
      agent = {
        enable = true;
        pinentryFlavor = "qt";
        enableSSHSupport = true;
      };
      dirmngr.enable = true;
    };
  }; 

When I overwrite the xdg lxqt portal style with kvantum, the style is correctly applied but the icons are missing.

  portal = {
    enable = true;
    lxqt = {
      enable = true;
      styles = [
        pkgs.libsForQt5.qtstyleplugin-kvantum
      ];
    };

When using the HM module, forcing variables QT_QPA_PLATFORMTHEME and QT_STYLE_OVERRIDE via env in the Hyprland configuration (equivalent to a wrapper script) file fixes the use of the theme for applications launched by it.

It's a shame because setting up Gtk with the HM module is quite a flawless experience, but qt with qtct is something else.

@romildo, @rycee, @thiagokokada, @corngood

thiagokokada commented 1 year ago

Yes, the Qt integration in both NixOS and Home-Manager is a mess right now. They are similar but doesn't support the same feature set (for example, the Home-Manager one allows for setting qt.platformTheme = "qt5ct and qt.style.name = "kvantum", that is recommended by Kvantum itself, however the NixOS modules does not because setting both is an assertion error).

Would be great if we could sync those two modules and get them to feature parity. CC @romildo since he maintains the NixOS module (I am the maintainer of the Home-Manager one).

There is currently a https://github.com/NixOS/nixpkgs/issues/239909 preventing qt6ct from accessing the Kvantum style.

See this comment for a workaround: https://github.com/NixOS/nixpkgs/issues/239909#issuecomment-1766317147. Yes, setting the module for both Home-Manager and NixOS is ugly, but it works right now.

When using the HM module, forcing variables QT_QPA_PLATFORMTHEME and QT_STYLE_OVERRIDE via env in the Hyprland configuration (equivalent to a wrapper script) file fixes the use of the theme for applications launched by it.

I think this is sadly expected. If you're launching any Wayland based Window Manager from anything else other than from shell (e.g.: greetd or a display manager), the Window Manager will not have access to the variables inside the user profile. I ended up just sourcing all environment variables from Home-Manager like this: https://github.com/thiagokokada/nix-configs/blob/194da66d00d543b2319527dd8edddad4557ed8c9/home-manager/desktop/sway/default.nix#L101-L102.

Using the NixOS module works as expected because this happens at system level (from /etc/profile), but of course Home-Manager has no permissions to touch those files and needs some "hacks" to set the user environment variables. While this mostly works as expected if you're starting a shell anyway, if you don't you're in your own.

thiagokokada commented 1 year ago

There is currently a https://github.com/NixOS/nixpkgs/issues/239909 preventing qt6ct from accessing the Kvantum style.

Opened a PR to fix this issue in Home-Manager: https://github.com/nix-community/home-manager/pull/4579.

thiagokokada commented 1 year ago

Opened a PR to fix the remaining issues in the NixOS module: https://github.com/NixOS/nixpkgs/pull/262051.

When using the qt NixOS module, applications launched via systemd services aren't themed, but applications launched via Hyprland are.

Are you talking about systemd services launched by Home-Manager right? You will need to import the correct variables (QT_QPA_PLATFORMTHEME, QT_STYLE_OVERRIDE, QT_PLUGIN_PATH and QML2_IMPORT_PATH) using systemd.user.sessionVariables to make it work correctly.

e-tho commented 1 year ago

I ended up just sourcing all environment variables from Home-Manager like this

Thanks for the tip, extraSessionCommands is not available in the Hyprland module but I did find a way to import HM-defined variables using the env option in the configuration file.

wayland.windowManager.hyprland.env = lib.mapAttrsToList (name: value: "${name},${builtins.toString value}") config.home.sessionVariables;

Yes, setting the module for both Home-Manager and NixOS is ugly, but it works right now.

Indeed, setting the module for both worked, and even enabled pinentry-qt to use the Kvantum style correctly. Unfortunately, the same problem occurs as with xdg-desktop-portal-lxqt: the application doesn't use the icon theme set by qt5ct.

Are you talking about systemd services launched by Home-Manager right?

After checking, this also affects pinentry-qt which is defined by the NixOS module gnupg.

thiagokokada commented 1 year ago

Indeed, setting the module for both worked, and even enabled pinentry-qt to use the Kvantum style correctly. Unfortunately, the same problem occurs as with xdg-desktop-portal-lxqt: the application doesn't use the icon theme set by qt5ct.

Without more info this looks like an issue with your config. Maybe pinentry-qt is not getting your config because it is a system service and you set qt5ct configuration only for your user?

After checking, this also affects pinentry-qt which is defined by the NixOS module gnupg.

Huh, this can be an issue with NixOS module not loading the required environment variables. Sadly different from Home Manager (that runs user services), it is not recommended to just import environment variables at the system level (e.g.: systemctl import-environment).

You can manually workaround this by setting QT_QPA_PLATFORMTHEME and QT_STYLE_OVERRIDE inside the pinentry-qt service, it should work.

e-tho commented 1 year ago

Maybe pinentry-qt is not getting your config because it is a system service and you set qt5ct configuration only for your user?

I've set it for both NixOS and Home Manager, importing variables to systemd does not fix the issue there is something wrong with qt5ct at system level, please can you try to reproduce it by setting gnupg.agent.pinentryFlavor = "qt"; and running a command such as echo "test" | gpg --clearsign to display pinentry