From a166a7294c0306bb02ac0800adb2d247a08690e5 Mon Sep 17 00:00:00 2001 From: Aidan Gauland Date: Thu, 4 May 2023 17:00:01 +1200 Subject: [PATCH] heroic: Rewrite using mkDerivation+fetchYarnDeps Use stdenv.mkDerivation with fetchYarnDeps instead of mkYarnPackage to make the build process cleaner, and to not require vendoring any upstream source file. Also build for all upstream-supported platforms. --- pkgs/games/heroic/default.nix | 81 ++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/pkgs/games/heroic/default.nix b/pkgs/games/heroic/default.nix index e31027b20581..8e668be5aa0b 100644 --- a/pkgs/games/heroic/default.nix +++ b/pkgs/games/heroic/default.nix @@ -1,14 +1,20 @@ { lib -, mkYarnPackage +, stdenv , fetchFromGitHub +, fetchYarnDeps , gitUpdater +, yarn +, fixup_yarn_lock +, nodejs +, python3 , makeWrapper , electron , gogdl , legendary-gl }: -mkYarnPackage rec { +let appName = "heroic"; +in stdenv.mkDerivation rec { pname = "heroic-unwrapped"; version = "2.7.1"; @@ -19,46 +25,71 @@ mkYarnPackage rec { sha256 = "sha256-l2eVLn1N+1nGxr8Oa2ecQgBmO0w/VJ8AY06GYQ0HiiI="; }; - packageJSON = ./package.json; - yarnLock = ./yarn.lock; - yarnNix = ./yarn.nix; + offlineCache = fetchYarnDeps { + yarnLock = "${src}/yarn.lock"; + sha256 = "sha256-R0lZrVfUH8NucuwarcE47jQ8ex5FY2hK6jJJ2TIRSWY="; + }; nativeBuildInputs = [ + yarn + fixup_yarn_lock + nodejs + python3 makeWrapper ]; - DISABLE_ESLINT_PLUGIN = "true"; + configurePhase = '' + runHook preConfigure - postBuild = let - yarnCmd = "yarn --offline --frozen-lockfile --ignore-engines --ignore-scripts --lockfile ${yarnLock}"; - in '' - rm deps/heroic/node_modules - ln -s ../../node_modules deps/heroic/ - ${yarnCmd} vite build + export HOME=$(mktemp -d) + yarn config --offline set yarn-offline-mirror $offlineCache + fixup_yarn_lock yarn.lock + yarn install --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive + patchShebangs node_modules/ + + runHook postConfigure ''; - # Disable bundling into a tar archive. - doDist = false; + buildPhase = '' + runHook preBuild + + yarn --offline vite build + + # Remove dev dependencies. + yarn install --production --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive + + runHook postBuild + ''; # --disable-gpu-compositing is to work around upstream bug # https://github.com/electron/electron/issues/32317 - postInstall = let - deps = "$out/libexec/heroic/deps/heroic"; + installPhase = let + binPlatform = if stdenv.isDarwin then "darwin" else "linux"; in '' - rm -rf "${deps}/public/bin" "${deps}/build/bin" - mkdir -p "${deps}/build/bin/linux" - ln -s "${gogdl}/bin/gogdl" "${legendary-gl}/bin/legendary" "${deps}/build/bin/linux" + runHook preInstall + + mkdir -p $out/share/{applications,${appName}} + cp -r . $out/share/${appName} + rm -rf $out/share/${appName}/{.devcontainer,.vscode,.husky,.idea,.github} + + chmod -R u+w "$out/share/${appName}/public/bin" "$out/share/${appName}/build/bin" + rm -rf "$out/share/${appName}/public/bin" "$out/share/${appName}/build/bin" + mkdir -p "$out/share/${appName}/build/bin/${binPlatform}" + ln -s "${gogdl}/bin/gogdl" "${legendary-gl}/bin/legendary" "$out/share/${appName}/build/bin/${binPlatform}" makeWrapper "${electron}/bin/electron" "$out/bin/heroic" \ --inherit-argv0 \ --add-flags --disable-gpu-compositing \ - --add-flags "${deps}" + --add-flags $out/share/${appName} \ + --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" - substituteInPlace "${deps}/flatpak/com.heroicgameslauncher.hgl.desktop" \ + substituteInPlace "$out/share/${appName}/flatpak/com.heroicgameslauncher.hgl.desktop" \ --replace "Exec=heroic-run" "Exec=heroic" mkdir -p "$out/share/applications" "$out/share/icons/hicolor/512x512/apps" - ln -s "${deps}/flatpak/com.heroicgameslauncher.hgl.desktop" "$out/share/applications" - ln -s "${deps}/flatpak/com.heroicgameslauncher.hgl.png" "$out/share/icons/hicolor/512x512/apps" + ln -s "$out/share/${appName}/flatpak/com.heroicgameslauncher.hgl.desktop" "$out/share/applications" + ln -s "$out/share/${appName}/flatpak/com.heroicgameslauncher.hgl.png" "$out/share/icons/hicolor/512x512/apps" + + runHook postInstall ''; passthru.updateScript = gitUpdater { @@ -71,7 +102,7 @@ mkYarnPackage rec { changelog = "https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher/releases"; license = licenses.gpl3Only; maintainers = with maintainers; [ aidalgol ]; - platforms = [ "x86_64-linux" ]; - mainProgram = "heroic"; + platforms = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; + mainProgram = appName; }; }