From 7a7cffce514f8967cb610399890f252cab75eb6a Mon Sep 17 00:00:00 2001 From: aszlig Date: Sun, 10 Sep 2017 08:01:59 +0200 Subject: games/invisigun-heroes: Factor out into buildUnity There are a lot of Unity games out there, so it's a good idea to have a generic builder just for Unity, which we then can apply to a lot more games. Right now this is a pretty basic abstraction which I've only tested with Invisigun Heroes. Signed-off-by: aszlig --- pkgs/games/build-support/build-unity.nix | 49 ++++++++++++++++++++++++++++++++ pkgs/games/build-support/default.nix | 5 ++++ pkgs/games/default.nix | 7 ++++- pkgs/games/itch/invisigun-heroes.nix | 44 +++++----------------------- 4 files changed, 67 insertions(+), 38 deletions(-) create mode 100644 pkgs/games/build-support/build-unity.nix create mode 100644 pkgs/games/build-support/default.nix (limited to 'pkgs') diff --git a/pkgs/games/build-support/build-unity.nix b/pkgs/games/build-support/build-unity.nix new file mode 100644 index 00000000..701ace91 --- /dev/null +++ b/pkgs/games/build-support/build-unity.nix @@ -0,0 +1,49 @@ +{ stdenv, mesa, xorg, libpulseaudio, libudev }: + +{ name, version, fullName, buildPhase ? "", rpath ? [], ... }@attrs: + +let + arch = if stdenv.system == "x86_64-linux" then "x86_64" else "x86"; + executable = "${fullName}.${arch}"; + dataDir = "${fullName}_Data"; + +in stdenv.mkDerivation ({ + name = "${name}-${version}"; + inherit version arch executable dataDir; + slugName = name; + + buildPhase = let + mainRpath = stdenv.lib.makeLibraryPath ([ + stdenv.cc.cc mesa xorg.libX11 xorg.libXcursor xorg.libXrandr + libpulseaudio libudev + ] ++ rpath); + in '' + runHook preBuild + + patchelf \ + --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ + --set-rpath ${stdenv.lib.escapeShellArg mainRpath} "$executable" + + ${buildPhase} + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + install -vD "$executable" "$out/libexec/$slugName/$slugName" + ln -s "$out/share/$slugName" "$out/libexec/$slugName/Data" + + mkdir -p "$out/bin" + ln -s "$out/libexec/$slugName/$slugName" "$out/bin/$slugName" + + mkdir -p "$out/share" + cp -vRd "$dataDir" "$out/share/$slugName" + + runHook postInstall + ''; + + dontStrip = true; + dontPatchELF = true; +} // removeAttrs attrs [ "name" "version" "fullName" "buildPhase" "rpath" ]) diff --git a/pkgs/games/build-support/default.nix b/pkgs/games/build-support/default.nix new file mode 100644 index 00000000..8b6b466d --- /dev/null +++ b/pkgs/games/build-support/default.nix @@ -0,0 +1,5 @@ +{ callPackage, ... }: + +{ + buildUnity = callPackage ./build-unity.nix {}; +} diff --git a/pkgs/games/default.nix b/pkgs/games/default.nix index cef568cf..b775610d 100644 --- a/pkgs/games/default.nix +++ b/pkgs/games/default.nix @@ -25,12 +25,17 @@ let description = "Available collections of games."; }; }; + + config._module.args.pkgs = let + buildSupport = import ./build-support { + callPackage = lib.callPackageWith (pkgs // buildSupport); + }; + in buildSupport // pkgs; }; in (pkgs.lib.evalModules { modules = [ (if config == null then configFilePath else config) baseModule ./humblebundle ./steam ./itch - { config._module.args.pkgs = pkgs; } ]; }).config.packages diff --git a/pkgs/games/itch/invisigun-heroes.nix b/pkgs/games/itch/invisigun-heroes.nix index 04fd06a8..4ab28f92 100644 --- a/pkgs/games/itch/invisigun-heroes.nix +++ b/pkgs/games/itch/invisigun-heroes.nix @@ -1,13 +1,12 @@ -{ stdenv, fetchItch, unzip, mesa, xorg, libpulseaudio, libudev -, gtk2-x11, gdk_pixbuf, glib -}: +{ stdenv, lib, buildUnity, fetchItch, unzip, gtk2-x11, gdk_pixbuf, glib }: -stdenv.mkDerivation rec { - name = "invisigun-heroes-${version}"; +buildUnity rec { + name = "invisigun-heroes"; + fullName = "Invisigun Heroes"; version = "1.5.30"; src = fetchItch { - name = "${name}.zip"; + name = "${name}-${version}.zip"; gameId = 25561; uploadId = 208583; version = "v${version}"; @@ -18,39 +17,10 @@ stdenv.mkDerivation rec { ${unzip}/bin/unzip -qq -d invisigun-heroes "$src" || : ''; - arch = if stdenv.system == "x86_64-linux" then "x86_64" else "x86"; - executable = "Invisigun Heroes.${arch}"; - buildPhase = let - rpath = stdenv.lib.makeLibraryPath [ - stdenv.cc.cc mesa xorg.libX11 xorg.libXcursor xorg.libXrandr - libpulseaudio libudev - ]; - - ssRpath = stdenv.lib.makeLibraryPath [ - stdenv.cc.cc gtk2-x11 gdk_pixbuf glib - ]; + rpath = lib.makeLibraryPath [ stdenv.cc.cc gtk2-x11 gdk_pixbuf glib ]; in '' - patchelf \ - --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ - --set-rpath ${stdenv.lib.escapeShellArg rpath} "$executable" - - patchelf --set-rpath ${stdenv.lib.escapeShellArg ssRpath} \ + patchelf --set-rpath ${lib.escapeShellArg rpath} \ "Invisigun Heroes_Data/Plugins/x86_64/ScreenSelector.so" ''; - - installPhase = '' - install -vD "$executable" "$out/libexec/invisigun-heroes/invisigun-heroes" - ln -s "$out/share/invisigun-heroes" "$out/libexec/invisigun-heroes/Data" - - mkdir -p "$out/bin" - ln -s "$out/libexec/invisigun-heroes/invisigun-heroes" \ - "$out/bin/invisigun-heroes" - - mkdir -p "$out/share" - cp -vRd "Invisigun Heroes_Data" "$out/share/invisigun-heroes" - ''; - - dontStrip = true; - dontPatchELF = true; } -- cgit 1.4.1