1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-26 21:19:45 +01:00

qt: use sessionVariablesExtra to export QT_PLUGIN_PATH/QML2_IMPORT_PATH

This commit is contained in:
Thiago Kenji Okada 2023-10-18 19:51:00 +01:00
parent eaee696b6e
commit 55eee5bd67
2 changed files with 26 additions and 18 deletions

View file

@ -28,8 +28,7 @@ in {
GTK_IM_MODULE = "fcitx";
QT_IM_MODULE = "fcitx";
XMODIFIERS = "@im=fcitx";
# Using mkDefault here since we override this value in qt module if enabled
QT_PLUGIN_PATH = lib.mkDefault
QT_PLUGIN_PATH =
"$QT_PLUGIN_PATH\${QT_PLUGIN_PATH:+:}${fcitx5Package}/${pkgs.qt6.qtbase.qtPluginPrefix}";
};

View file

@ -154,25 +154,23 @@ in {
config = let
# Necessary because home.sessionVariables doesn't support mkIf
envVars = let
inherit (config.home) profileDirectory;
qtVersions = with pkgs; [ qt5 qt6 ];
makeQtPath = prefix: basePath: qt: "${basePath}/${qt.qtbase.${prefix}}";
in lib.filterAttrs (n: v: v != null) {
envVars = lib.filterAttrs (n: v: v != null) {
QT_QPA_PLATFORMTHEME =
styleNames.${cfg.platformTheme} or cfg.platformTheme;
QT_STYLE_OVERRIDE = cfg.style.name;
};
envVarsExtra = let
inherit (config.home) profileDirectory;
qtVersions = with pkgs; [ qt5 qt6 ];
makeQtPath = prefix:
lib.concatStringsSep ":"
(map (qt: "${profileDirectory}/${qt.qtbase.${prefix}}") qtVersions);
in {
QT_PLUGIN_PATH = "$QT_PLUGIN_PATH\${QT_PLUGIN_PATH:+:}"
+ (lib.concatStringsSep ":"
# Workaround issue with home.sessionVariables that does not support
# multiple different values since fcitx5 also needs to set QT_PLUGIN_PATH.
(lib.optional (config.i18n.inputMethod == "fcitx5")
(makeQtPath "qtPluginPrefix" config.i18n.inputMethod.package
pkgs.qt6) ++ (map (makeQtPath "qtPluginPrefix" profileDirectory)
qtVersions)));
+ (makeQtPath "qtPluginPrefix");
QML2_IMPORT_PATH = "$QML2_IMPORT_PATH\${QML2_IMPORT_PATH:+:}"
+ (lib.concatStringsSep ":"
(map (makeQtPath "qtQmlPrefix" profileDirectory) qtVersions));
+ (makeQtPath "qtQmlPrefix");
};
in lib.mkIf (cfg.enable && cfg.platformTheme != null) {
@ -188,10 +186,21 @@ in {
qt.style.package = lib.mkIf (cfg.style.name != null)
(lib.mkDefault (stylePackages.${lib.toLower cfg.style.name} or null));
home.sessionVariables = envVars;
home = {
sessionVariables = envVars;
# home.sessionVariables does not support setting the same environment
# variable to different values.
# Since some other modules may set the QT_PLUGIN_PATH or QML2_IMPORT_PATH
# to their own value, e.g.: fcitx5, we avoid conflicts by setting
# the values in home.sessionVariablesExtra instead.
sessionVariablesExtra = ''
export QT_PLUGIN_PATH=${envVarsExtra.QT_PLUGIN_PATH}
export QML2_IMPORT_PATH=${envVarsExtra.QML2_IMPORT_PATH}
'';
};
# Apply theming also to apps started by systemd.
systemd.user.sessionVariables = envVars;
systemd.user.sessionVariables = envVars // envVarsExtra;
home.packages = (platformPackages.${cfg.platformTheme} or [ ])
++ lib.optionals (cfg.style.package != null)