From 791b95cd71cc2184e7c83e8a297c808eacab2ed5 Mon Sep 17 00:00:00 2001 From: Jakub Trzeciak Date: Sat, 21 Oct 2023 11:35:42 +0200 Subject: Heroic Launcher 🫠 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .flake.lock | 117 +++++++++++++++++ flake.lock | 30 ++--- makefile | 5 +- nixos/configuration.nix | 11 +- overlays/default.nix | 18 +-- pkgs/heroic-launcher/default.nix | 118 +++++++++++++++++ pkgs/heroic-launcher/fhsenv.nix | 139 +++++++++++++++++++++ pkgs/heroic-launcher/fix-non-steam-shortcuts.patch | 13 ++ pkgs/heroic-launcher/remove-drm-support.patch | 24 ++++ 9 files changed, 448 insertions(+), 27 deletions(-) create mode 100644 .flake.lock create mode 100644 pkgs/heroic-launcher/default.nix create mode 100644 pkgs/heroic-launcher/fhsenv.nix create mode 100644 pkgs/heroic-launcher/fix-non-steam-shortcuts.patch create mode 100644 pkgs/heroic-launcher/remove-drm-support.patch diff --git a/.flake.lock b/.flake.lock new file mode 100644 index 0000000..98e73b5 --- /dev/null +++ b/.flake.lock @@ -0,0 +1,117 @@ +{ + "nodes": { + "base16-schemes": { + "flake": false, + "locked": { + "lastModified": 1680729003, + "narHash": "sha256-M9LHTL24/W4oqgbYRkz0B2qpNrkefTs98pfj3MxIXnU=", + "owner": "tinted-theming", + "repo": "base16-schemes", + "rev": "dc048afa066287a719ddbab62b3e19e4b5110cf0", + "type": "github" + }, + "original": { + "owner": "tinted-theming", + "repo": "base16-schemes", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1695108154, + "narHash": "sha256-gSg7UTVtls2yO9lKtP0yb66XBHT1Fx5qZSZbGMpSn2c=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "07682fff75d41f18327a871088d20af2710d4744", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "release-23.05", + "repo": "home-manager", + "type": "github" + } + }, + "nix-colors": { + "inputs": { + "base16-schemes": "base16-schemes", + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1682108218, + "narHash": "sha256-tMr7BbxualFQlN+XopS8rMMgf2XR9ZfRuwIZtjsWmfI=", + "owner": "misterio77", + "repo": "nix-colors", + "rev": "b92df8f5eb1fa20d8e09810c03c9dc0d94ef2820", + "type": "github" + }, + "original": { + "owner": "misterio77", + "repo": "nix-colors", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1694937365, + "narHash": "sha256-iHZSGrb9gVpZRR4B2ishUN/1LRKWtSHZNO37C8z1SmA=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5d017a8822e0907fb96f7700a319f9fe2434de02", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1680397293, + "narHash": "sha256-wBpJ73+tJ8fZSWb4tzNbAVahC4HSo2QG3nICDy4ExBQ=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "b18d328214ca3c627d3cc3f51fd9d1397fdbcd7a", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1694959747, + "narHash": "sha256-CXQ2MuledDVlVM5dLC4pB41cFlBWxRw4tCBsFrq3cRk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "970a59bd19eff3752ce552935687100c46e820a5", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager", + "nix-colors": "nix-colors", + "nixpkgs": "nixpkgs", + "nixpkgs-unstable": "nixpkgs-unstable" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.lock b/flake.lock index 98e73b5..34c2441 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "base16-schemes": { "flake": false, "locked": { - "lastModified": 1680729003, - "narHash": "sha256-M9LHTL24/W4oqgbYRkz0B2qpNrkefTs98pfj3MxIXnU=", + "lastModified": 1689473676, + "narHash": "sha256-L0RhUr9+W5EPWBpLcmkKpUeCEWRs/kLzVMF3Vao2ZU0=", "owner": "tinted-theming", "repo": "base16-schemes", - "rev": "dc048afa066287a719ddbab62b3e19e4b5110cf0", + "rev": "d95123ca6377cd849cfdce92c0a24406b0c6a789", "type": "github" }, "original": { @@ -43,11 +43,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1682108218, - "narHash": "sha256-tMr7BbxualFQlN+XopS8rMMgf2XR9ZfRuwIZtjsWmfI=", + "lastModified": 1695388192, + "narHash": "sha256-2jelpE7xK+4M7jZNyWL7QYOYegQLYBDQS5bvdo8XRUQ=", "owner": "misterio77", "repo": "nix-colors", - "rev": "b92df8f5eb1fa20d8e09810c03c9dc0d94ef2820", + "rev": "37227f274b34a3b51649166deb94ce7fec2c6a4c", "type": "github" }, "original": { @@ -58,11 +58,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1694937365, - "narHash": "sha256-iHZSGrb9gVpZRR4B2ishUN/1LRKWtSHZNO37C8z1SmA=", + "lastModified": 1697655685, + "narHash": "sha256-79Kuv+QdgsVc+rkibuAgWHnh8IXrLBTOKg5nM0Qvux0=", "owner": "nixos", "repo": "nixpkgs", - "rev": "5d017a8822e0907fb96f7700a319f9fe2434de02", + "rev": "80c1aab725151632ddc2a20caeb914e76dd0673c", "type": "github" }, "original": { @@ -74,11 +74,11 @@ }, "nixpkgs-lib": { "locked": { - "lastModified": 1680397293, - "narHash": "sha256-wBpJ73+tJ8fZSWb4tzNbAVahC4HSo2QG3nICDy4ExBQ=", + "lastModified": 1694911725, + "narHash": "sha256-8YqI+YU1DGclEjHsnrrGfqsQg3Wyga1DfTbJrN3Ud0c=", "owner": "nix-community", "repo": "nixpkgs.lib", - "rev": "b18d328214ca3c627d3cc3f51fd9d1397fdbcd7a", + "rev": "819180647f428a3826bfc917a54449da1e532ce0", "type": "github" }, "original": { @@ -89,11 +89,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1694959747, - "narHash": "sha256-CXQ2MuledDVlVM5dLC4pB41cFlBWxRw4tCBsFrq3cRk=", + "lastModified": 1697456312, + "narHash": "sha256-roiSnrqb5r+ehnKCauPLugoU8S36KgmWraHgRqVYndo=", "owner": "nixos", "repo": "nixpkgs", - "rev": "970a59bd19eff3752ce552935687100c46e820a5", + "rev": "ca012a02bf8327be9e488546faecae5e05d7d749", "type": "github" }, "original": { diff --git a/makefile b/makefile index 62d98a4..92174b4 100644 --- a/makefile +++ b/makefile @@ -1,2 +1,5 @@ -sync: +switch: sudo nixos-rebuild switch --flake .#x270 --show-trace --impure + +update: + sudo nixos-rebuild switch --upgrade --flake .#x270 --show-trace --impure diff --git a/nixos/configuration.nix b/nixos/configuration.nix index 911d0e4..50d679b 100644 --- a/nixos/configuration.nix +++ b/nixos/configuration.nix @@ -264,7 +264,6 @@ pika-backup pavucontrol logseq - heroic lxappearance fontpreview ffmpeg @@ -303,8 +302,16 @@ #openttd dolphin-emu prismlauncher - ] ++ [ + ] ++ (with pkgs.unstable; [ + winetricks + gamemode + heroic + gogdl + ]) ++ [ (pkgs.nnn.override { withNerdIcons = true; }) + #(pkgs.unstable.callPackage ../pkgs/heroic-launcher { + # electron = pkgs.unstable.electron_24; + #}) ]; } diff --git a/overlays/default.nix b/overlays/default.nix index 3037a94..cd7a878 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -10,6 +10,15 @@ in { # This one brings our custom packages from the 'pkgs' directory additions = final: _prev: import ../pkgs {pkgs = final;}; + # When applied, the unstable nixpkgs set (declared in the flake inputs) will + # be accessible through 'pkgs.unstable' + unstable-packages = final: _prev: { + unstable = import inputs.nixpkgs-unstable { + system = final.system; + config.allowUnfree = true; + }; + }; + # This one contains whatever you want to overlay # You can change versions, add patches, set compilation flags, anything really. # https://nixos.wiki/wiki/Overlays @@ -30,13 +39,4 @@ in { ] ++ old.buildInputs; }); }; - - # When applied, the unstable nixpkgs set (declared in the flake inputs) will - # be accessible through 'pkgs.unstable' - unstable-packages = final: _prev: { - unstable = import inputs.nixpkgs-unstable { - system = final.system; - config.allowUnfree = true; - }; - }; } diff --git a/pkgs/heroic-launcher/default.nix b/pkgs/heroic-launcher/default.nix new file mode 100644 index 0000000..96ece24 --- /dev/null +++ b/pkgs/heroic-launcher/default.nix @@ -0,0 +1,118 @@ +{ lib +, stdenv +, fetchFromGitHub +, fetchYarnDeps +, yarn +, fixup_yarn_lock +, nodejs +, python3 +, makeWrapper +, electron +, vulkan-helper +, gogdl +, legendary-gl +, nile +}: + +let appName = "heroic"; +in stdenv.mkDerivation rec { + pname = "heroic-unwrapped"; + version = "2.9.1"; + + src = fetchFromGitHub { + owner = "Heroic-Games-Launcher"; + repo = "HeroicGamesLauncher"; + rev = "v${version}"; + hash = "sha256-kCvMUhN1kjGb5rV+lkKm1FFYBJUSQGOKTY1DQdiAWLU="; + }; + + offlineCache = fetchYarnDeps { + yarnLock = "${src}/yarn.lock"; + hash = "sha256-kHZL7TENVK58dvr8PBFtWYZ2PSKEYESX4e1xYmMA5+Y="; + }; + + nativeBuildInputs = [ + yarn + fixup_yarn_lock + nodejs + python3 + makeWrapper + ]; + + patches = [ + # Reverts part of upstream PR 2761 so that we don't have to use a non-free Electron fork. + # https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher/pull/2761 + ./remove-drm-support.patch + # Make Heroic create Steam shortcuts (to non-steam games) with the correct path to heroic. + ./fix-non-steam-shortcuts.patch + ]; + + configurePhase = '' + runHook preConfigure + + 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 + ''; + + 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 + installPhase = let + binPlatform = if stdenv.isDarwin then "darwin" else "linux"; + in '' + 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" \ + "${nile}/bin/nile" \ + "${lib.optionalString stdenv.isLinux "${vulkan-helper}/bin/vulkan-helper"}" \ + "$out/share/${appName}/build/bin/${binPlatform}" + + makeWrapper "${electron}/bin/electron" "$out/bin/heroic" \ + --inherit-argv0 \ + --add-flags --disable-gpu-compositing \ + --add-flags $out/share/${appName} \ + --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime}}" + + 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 "$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 + ''; + + meta = with lib; { + description = "A Native GOG, Epic, and Amazon Games Launcher for Linux, Windows and Mac"; + homepage = "https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher"; + changelog = "https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher/releases"; + license = licenses.gpl3Only; + maintainers = with maintainers; [ aidalgol ]; + platforms = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; + mainProgram = appName; + }; +} diff --git a/pkgs/heroic-launcher/fhsenv.nix b/pkgs/heroic-launcher/fhsenv.nix new file mode 100644 index 0000000..19b44b2 --- /dev/null +++ b/pkgs/heroic-launcher/fhsenv.nix @@ -0,0 +1,139 @@ +{ buildFHSEnv +, heroic-unwrapped +, extraPkgs ? pkgs: [ ] +, extraLibraries ? pkgs: [ ] +}: + +buildFHSEnv { + name = "heroic"; + + runScript = "heroic"; + + # Many Wine and native games need 32-bit libraries. + multiArch = true; + + # required by Electron + unshareIpc = false; + + targetPkgs = pkgs: with pkgs; [ + heroic-unwrapped + gamemode + curl + gawk + gnome.zenity + plasma5Packages.kdialog + mangohud + nettools + opencl-headers + p7zip + perl + psmisc + python3 + which + xorg.xrandr + zstd + ] ++ extraPkgs pkgs; + + multiPkgs = let + xorgDeps = pkgs: with pkgs.xorg; [ + libpthreadstubs + libSM + libX11 + libXaw + libxcb + libXcomposite + libXcursor + libXdmcp + libXext + libXi + libXinerama + libXmu + libXrandr + libXrender + libXv + libXxf86vm + ]; + gstreamerDeps = pkgs: with pkgs.gst_all_1; [ + gstreamer + gst-plugins-base + gst-plugins-good + gst-plugins-ugly + gst-plugins-bad + gst-libav + ]; + in pkgs: with pkgs; [ + alsa-lib + alsa-plugins + bash + cabextract + cairo + coreutils + cups + dbus + freealut + freetype + fribidi + giflib + glib + gnutls + gtk3 + lcms2 + libevdev + libgcrypt + libGLU + libglvnd + libgpg-error + libgudev + libjpeg + libkrb5 + libmpeg2 + libogg + libopus + libpng + libpulseaudio + libselinux + libsndfile + libsoup + libtheora + libtiff + libusb1 + libv4l + libva + libvdpau + libvorbis + libvpx + libwebp + libxkbcommon + libxml2 + mpg123 + ncurses + ocl-icd + openal + openldap + openssl + pango + pipewire + samba4 + sane-backends + SDL2 + speex + sqlite + udev + unixODBC + util-linux + v4l-utils + vulkan-loader + wayland + zlib + ] ++ xorgDeps pkgs + ++ gstreamerDeps pkgs + ++ extraLibraries pkgs; + + extraInstallCommands = '' + mkdir -p $out/share + ln -s ${heroic-unwrapped}/share/applications $out/share + ln -s ${heroic-unwrapped}/share/icons $out/share + ''; + + meta = heroic-unwrapped.meta; +} diff --git a/pkgs/heroic-launcher/fix-non-steam-shortcuts.patch b/pkgs/heroic-launcher/fix-non-steam-shortcuts.patch new file mode 100644 index 0000000..7b46473 --- /dev/null +++ b/pkgs/heroic-launcher/fix-non-steam-shortcuts.patch @@ -0,0 +1,13 @@ +diff --git a/src/backend/shortcuts/nonesteamgame/nonesteamgame.ts b/src/backend/shortcuts/nonesteamgame/nonesteamgame.ts +index ebef6aa4..c8bd853d 100644 +--- a/src/backend/shortcuts/nonesteamgame/nonesteamgame.ts ++++ b/src/backend/shortcuts/nonesteamgame/nonesteamgame.ts +@@ -252,7 +252,7 @@ async function addNonSteamGame(props: { + // add new Entry + const newEntry = {} as ShortcutEntry + newEntry.AppName = props.gameInfo.title +- newEntry.Exe = `"${app.getPath('exe')}"` ++ newEntry.Exe = `"heroic"` + newEntry.StartDir = `"${process.cwd()}"` + + if (isFlatpak) { diff --git a/pkgs/heroic-launcher/remove-drm-support.patch b/pkgs/heroic-launcher/remove-drm-support.patch new file mode 100644 index 0000000..f3cd80f --- /dev/null +++ b/pkgs/heroic-launcher/remove-drm-support.patch @@ -0,0 +1,24 @@ +diff --git a/src/backend/main.ts b/src/backend/main.ts +index 2cd1a28f..a60e04d0 100644 +--- a/src/backend/main.ts ++++ b/src/backend/main.ts +@@ -19,8 +19,7 @@ import { + powerSaveBlocker, + protocol, + screen, +- clipboard, +- components ++ clipboard + } from 'electron' + import 'backend/updater' + import { autoUpdater } from 'electron-updater' +@@ -286,8 +285,7 @@ if (!gotTheLock) { + initImagesCache() + + if (!process.env.CI) { +- await components.whenReady() +- logInfo(['DRM module staus', components.status()]) ++ logInfo('DRM modules disabled for nixpkgs') + } + + // try to fix notification app name on windows -- cgit v1.2.3