about summary refs log tree commit diff
path: root/pkgs/games/build-support
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2017-09-10 08:01:59 +0200
committeraszlig <aszlig@redmoonstudios.org>2017-09-10 08:14:09 +0200
commit7a7cffce514f8967cb610399890f252cab75eb6a (patch)
tree0b9e102f3f0a4a4266b4b4168d7b5c91f14d1757 /pkgs/games/build-support
parent5402b030e2cc78e510414b4604d9528afbec43d2 (diff)
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 <aszlig@redmoonstudios.org>
Diffstat (limited to 'pkgs/games/build-support')
-rw-r--r--pkgs/games/build-support/build-unity.nix49
-rw-r--r--pkgs/games/build-support/default.nix5
2 files changed, 54 insertions, 0 deletions
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 {};
+}