Automate Battle.net client tweaks via home activation

This commit is contained in:
Joshua Yuen 2026-10-06 19:42:36 -04:00
parent 79ba19161f
commit eb480a205c
Signed by: josh
GPG Key ID: 530DA0331EFE99F5
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,48 @@
{
config,
lib,
pkgs,
...
}:
with lib;
let
cfg = config.modules.battlenet;
yq = "${pkgs.yq}/bin/yq";
jq = "${pkgs.jq}/bin/jq";
in
{
config = mkIf cfg.enable {
# Battle.net is installed manually through Lutris, which creates the game
# config and wine prefix outside of Home Manager's control. The Lutris
# installer script writes HardwareAcceleration "false" (software rendering,
# which breaks Battle.net's CEF UI repainting under XWayland), so patch it
# and the game env after every rebuild. Re-run the rebuild after installing
# Battle.net for these tweaks to land.
home.activation.battlenetClientTweaks = hm.dag.entryAfter [ "writeBoundary" ] ''
shopt -s nullglob
for game in "$HOME"/.local/share/lutris/games/battlenet*.yml; do
prefix=$(${yq} -r '.game.prefix // ""' "$game" 2>/dev/null) || continue
for configFile in "$prefix"/drive_c/users/*/AppData/Roaming/Battle.net/Battle.net.config; do
[ -e "$configFile" ] || continue
if [ "$(${jq} -r '.Client.HardwareAcceleration // ""' "$configFile" 2>/dev/null)" != "true" ]; then
${jq} '.Client.HardwareAcceleration = "true"' "$configFile" > "$configFile.tmp" && mv "$configFile.tmp" "$configFile"
fi
done
# GE-Proton's Wayland driver breaks Battle.net's CEF window sizing and
# painting, and Xalia misrenders the client, so pin both off.
if [ "$(${yq} -r '.system.env.PROTON_USE_XALIA // ""' "$game" 2>/dev/null)" != "0" ]; then
${yq} --in-place --yaml-output '.system.env.PROTON_USE_XALIA = "0"' "$game"
fi
if [ "$(${yq} -r '.system.env.WINE_SIMULATE_WRITECOPY // ""' "$game" 2>/dev/null)" != "1" ]; then
${yq} --in-place --yaml-output '.system.env.WINE_SIMULATE_WRITECOPY = "1"' "$game"
fi
if [ -n "$(${yq} -r '.system.env.PROTON_ENABLE_WAYLAND // ""' "$game" 2>/dev/null)" ]; then
${yq} --in-place --yaml-output 'del(.system.env.PROTON_ENABLE_WAYLAND)' "$game"
fi
done
shopt -u nullglob
'';
};
}

View File

@ -3,6 +3,7 @@
}: }:
{ {
imports = [ imports = [
./battlenet.nix
./direnv.nix ./direnv.nix
./discord.nix ./discord.nix
./dictation.nix ./dictation.nix