Skip to content

Commit

Permalink
heroic: fix packaging
Browse files Browse the repository at this point in the history
Make this package closer to the upstream release build by running the
electron-build task.
  • Loading branch information
aidalgol committed Jan 1, 2025
1 parent 7b438af commit a97234e
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions pkgs/games/heroic/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
nix-update-script,
pnpm,
nodejs,
python3,
makeWrapper,
electron,
vulkan-helper,
Expand Down Expand Up @@ -33,6 +34,7 @@ stdenv.mkDerivation (finalAttrs: {
nativeBuildInputs = [
nodejs
pnpm.configHook
python3
makeWrapper
];

Expand All @@ -41,21 +43,25 @@ stdenv.mkDerivation (finalAttrs: {
./fix-non-steam-shortcuts.patch
];

postPatch = ''
# We are not packaging this as an Electron application bundle, so Electron
# reports to the application that is is not "packaged", which causes Heroic
# to take some incorrect codepaths meant for development environments.
substituteInPlace src/**/*.ts --replace-quiet 'app.isPackaged' 'true'
'';
env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";

buildPhase = ''
runHook preBuild
# set nodedir to prevent node-gyp from downloading headers
# taken from https://nixos.org/manual/nixpkgs/stable/#javascript-tool-specific
mkdir -p $HOME/.node-gyp/${nodejs.version}
echo 9 > $HOME/.node-gyp/${nodejs.version}/installVersion
ln -sfv ${nodejs}/include $HOME/.node-gyp/${nodejs.version}
export npm_config_nodedir=${nodejs}
pnpm --offline electron-vite build
# Remove dev dependencies.
pnpm --ignore-scripts prune --prod
# Clean up broken symlinks left behind by `pnpm prune`
find node_modules/.bin -xtype l -delete
pnpm --offline electron-builder \
--linux \
--dir \
-c.asarUnpack="**/*.node" \
-c.electronDist=${electron.dist} \
-c.electronVersion=${electron.version}
runHook postBuild
'';
Expand All @@ -65,33 +71,32 @@ stdenv.mkDerivation (finalAttrs: {
installPhase = ''
runHook preInstall
mkdir -p $out/share/{applications,heroic}
cp -r . $out/share/heroic
rm -rf $out/share/heroic/{.devcontainer,.vscode,.husky,.idea,.github}
mkdir -p "$out/opt/heroic"
cp -r dist/linux-unpacked/resources "$out/opt/heroic"
chmod -R u+w "$out/share/heroic/public/bin" "$out/share/heroic/build/bin"
rm -rf "$out/share/heroic/public/bin" "$out/share/heroic/build/bin"
mkdir -p "$out/share/heroic/build/bin/x64/linux"
cp -r public "$out/opt/heroic/resources/app.asar.unpacked/build"
rm -rf "$out/opt/heroic/resources/app.asar.unpacked/build/bin"
mkdir -p "$out/opt/heroic/resources/app.asar.unpacked/build/bin/x64/linux"
ln -s \
"${lib.getExe gogdl}" \
"${lib.getExe legendary-gl}" \
"${lib.getExe nile}" \
"${lib.getExe comet-gog}" \
"${lib.getExe vulkan-helper}" \
"$out/share/heroic/build/bin/x64/linux/"
"$out/opt/heroic/resources/app.asar.unpacked/build/bin/x64/linux"
makeWrapper "${electron}/bin/electron" "$out/bin/heroic" \
--inherit-argv0 \
--set ELECTRON_FORCE_IS_PACKAGED 1 \
--add-flags --disable-gpu-compositing \
--add-flags $out/share/heroic \
--add-flags $out/opt/heroic/resources/app.asar \
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}"
substituteInPlace "$out/share/heroic/flatpak/com.heroicgameslauncher.hgl.desktop" \
install -D "flatpak/com.heroicgameslauncher.hgl.desktop" "$out/share/applications/com.heroicgameslauncher.hgl.desktop"
install -D "src/frontend/assets/heroic-icon.svg" "$out/share/icons/hicolor/scalable/apps/com.heroicgameslauncher.hgl.svg"
substituteInPlace "$out/share/applications/com.heroicgameslauncher.hgl.desktop" \
--replace-fail "StartupWMClass=Heroic" "StartupWMClass=heroic" \
--replace-fail "Exec=heroic-run" "Exec=heroic"
mkdir -p "$out/share/applications" "$out/share/icons/hicolor/scalable/apps"
ln -s "$out/share/heroic/flatpak/com.heroicgameslauncher.hgl.desktop" "$out/share/applications"
ln -s "$out/share/heroic/src/frontend/assets/heroic-icon.svg" "$out/share/icons/hicolor/scalable/apps/com.heroicgameslauncher.hgl.svg"
runHook postInstall
'';
Expand Down

0 comments on commit a97234e

Please sign in to comment.