summary refs log tree commit diff
path: root/pkgs/games/ut2004/wrapper.nix
blob: 31d0763be4d259b00d83f165cb75200d6090a81a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{ stdenv, lib, runCommand, buildEnv, makeWrapper, makeDesktopItem, gamePacks, libstdcxx5, SDL, openal }:

let
  game = buildEnv {
    name = "ut2004-game";
    paths = gamePacks;
    ignoreCollisions = true;
    pathsToLink = [ "/" "/System" ];
    postBuild = ''
      ln -s ${lib.getLib SDL}/lib/libSDL-1.2.so.0 $out/System
      ln -s ${lib.getLib openal}/lib/libopenal.so $out/System/openal.so
      for i in $out/System/*-bin; do
        path="$(readlink -f "$i")"
        rm "$i"
        cp "$path" "$i"
        chmod +w "$i"
        patchelf \
          --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) \
          --set-rpath "$out/System:${lib.makeLibraryPath [ libstdcxx5 ]}" \
          "$i"
      done
    '';
  };

  desktop = makeDesktopItem {
    name = "ut2004";
    desktopName = "Unreal Tournament 2004";
    comment = "A first-person shooter video game developed by Epic Games and Digital Extreme";
    genericName = "First-person shooter";
    categories = "Application;Game;";
    exec = "ut2004";
  };

in runCommand "ut2004" {
  nativeBuildInputs = [ makeWrapper ];
} ''
  mkdir -p $out/bin
  for i in ${game}/System/*-bin; do
    name="$(basename "$i")"
    makeWrapper $i $out/bin/''${name%-bin} \
      --run "cd ${game}/System"
  done

  mkdir -p $out/share/applications
  ln -s ${desktop}/share/applications/* $out/share/applications
''