How to override qt6Packages.qtbase to add patch

I’m trying to add a patch to qt6Packages.qtbase using the ff. overlay

(final: prev: {
  qt6Packages = prev.qt6Packages.overrideScope (
    selfx: prevx: {
      qtbase = prevx.qtbase.overrideAttrs (oldAttrs: {
        patches = oldAttrs.patches ++ [
          (prev.fetchpatch2 {
            url = "https://github.com/qt/qtbase/commit/e25150ca29437ab315e3686aa801b8636e201e2a.patch";
            hash = "sha256-8WOjjffI48Vlx7gQIiOzfUtPloLys5lf06RQi1lsTys=";
          })
        ];
      });
    }
  );
})

The patch seems to work fine except for some packages. I’m getting the ff. when trying to nixos-rebuild

> Error: detected mismatched Qt dependencies:
>     /nix/store/g322vdmjrc2jh0h93hw00ya8xcjwsmzy-qtbase-6.8.0
>     /nix/store/bgfalfi93kbn8j1wfwz0x0dnk1wx9wdp-qtbase-6.8.0
For full logs, run 'nix log /nix/store/1sp2qw13wzj2fvka7p5n9h6l6ki09hdj-sddm-unwrapped-0.21.0.drv'.

If your only issue is with the broken themes, there is a nice workaround that repackages them without symlinks, which is better than patching qt since you don’t have to recompile it.

I’ve modified it a bit to accept multiple themes and it’s working great:

# FIXME: remove with qt6-6.8.1
# https://codereview.qt-project.org/c/qt/qtbase/+/597856
environment.variables.QT_PLUGIN_PATH =
  let
    derefTheme =
      themes:
      map (
        theme:
        pkgs.runCommand "${lib.getName theme}-workaround" { } ''
          plugins="${theme.outPath}/${pkgs.qt6.qtbase.qtPluginPrefix}"
          cp -r --dereference "$plugins" $out
        ''
      ) themes;
  in
  derefTheme (
    with pkgs;
    [
      kdePackages.breeze
      kdePackages.qtstyleplugin-kvantum
    ]
  );

Wish that it looked cleaner, though :sweat_smile:

thanks, this workaround works. I have applied the above to home-manager.

  home.sessionVariables.QT_PLUGIN_PATH =
    let
      deferTheme =
        themes:
        map (
          theme:
          pkgs.runCommand "${pkgs.lib.getName theme}-workaround" { } ''
            plugins="${theme.outPath}/${pkgs.qt6.qtbase.qtPluginPrefix}"
            cp -r --dereference "$plugins" $out
          ''
        ) themes;

      toStr = lib.concatMapStrings (x: ":" + x) (
        deferTheme (
          with pkgs;
          [
            self.packages.${pkgs.system}.lightly-qt6
            qt6ct
          ]
        )
      );
    in
    "$QT_PLUGIN_PATH${toStr}";

this applies the lightly-qt6 package, though if using qt6ct the custom colorscheme is not applied.

will use this for now.

1 Like