···1+{ stdenv, fetchurl }:
2+3+let
4+ arch =
5+ if stdenv.system == "x86_64-linux" then "amd64"
6+ else if stdenv.system == "i686-linux" then "x86"
7+ else throw "Unsupported architecture";
8+9+in stdenv.mkDerivation rec {
10+ name = "ut2004-demo-${version}";
11+ version = "3334";
12+13+ src = fetchurl {
14+ url = "http://treefort.icculus.org/ut2004/UT2004-LNX-Demo${version}.run.gz";
15+ sha256 = "0d5f84qz8l1rg16yzx2k4ikr46n9iwj68na1bqi87wrww7ck6jh7";
16+ };
17+18+ buildCommand = ''
19+ cat $src | gunzip > setup.run
20+ chmod +x setup.run
21+ ./setup.run --noexec --target .
22+ mkdir $out
23+ tar -xaf ut2004demo.tar.bz2 -C $out
24+ tar -xaf linux-${arch}.tar.bz2 -C $out
25+26+ rm $out/System/libSDL-1.2.so.0
27+ rm $out/System/openal.so
28+ '';
29+30+ dontStrip = true;
31+ dontPatchELF = true;
32+33+ meta = with stdenv.lib; {
34+ description = "A first-person shooter video game developed by Epic Games and Digital Extreme -- demo version";
35+ homepage = "http://www.unrealtournament2004.com";
36+ license = licenses.unfree;
37+ maintainers = with maintainers; [ abbradar ];
38+ platforms = [ "x86_64-linux" "i686-linux" ];
39+ };
40+}
+46
pkgs/games/ut2004/wrapper.nix
···0000000000000000000000000000000000000000000000
···1+{ stdenv, lib, runCommand, buildEnv, makeWrapper, makeDesktopItem, gamePacks, libstdcxx5, SDL, openal }:
2+3+let
4+ game = buildEnv {
5+ name = "ut2004-game";
6+ paths = gamePacks;
7+ ignoreCollisions = true;
8+ pathsToLink = [ "/" "/System" ];
9+ postBuild = ''
10+ ln -s ${lib.getLib SDL}/lib/libSDL-1.2.so.0 $out/System
11+ ln -s ${lib.getLib openal}/lib/libopenal.so $out/System/openal.so
12+ for i in $out/System/*-bin; do
13+ path="$(readlink -f "$i")"
14+ rm "$i"
15+ cp "$path" "$i"
16+ chmod +w "$i"
17+ patchelf \
18+ --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) \
19+ --set-rpath "$out/System:${lib.makeLibraryPath [ libstdcxx5 ]}" \
20+ "$i"
21+ done
22+ '';
23+ };
24+25+ desktop = makeDesktopItem {
26+ name = "ut2004";
27+ desktopName = "Unreal Tournament 2004";
28+ comment = "A first-person shooter video game developed by Epic Games and Digital Extreme";
29+ genericName = "First-person shooter";
30+ categories = "Application;Game;";
31+ exec = "ut2004";
32+ };
33+34+in runCommand "ut2004" {
35+ nativeBuildInputs = [ makeWrapper ];
36+} ''
37+ mkdir -p $out/bin
38+ for i in ${game}/System/*-bin; do
39+ name="$(basename "$i")"
40+ makeWrapper $i $out/bin/''${name%-bin} \
41+ --run "cd ${game}/System"
42+ done
43+44+ mkdir -p $out/share/applications
45+ ln -s ${desktop}/share/applications/* $out/share/applications
46+''
-29
pkgs/games/ut2004demo/builder.sh
···1-source $stdenv/setup
2-3-skip=7976
4-5-bunzip2 < $src | (dd bs=1 count=$skip of=/dev/null && dd bs=1M) | tar xvf - ut2004demo.tar
6-7-mkdir $out
8-9-(cd $out && tar xvf -) < ut2004demo.tar
10-11-12-# Patch the executable from ELF OS/ABI type `Linux' (3) to `SVR4' (0).
13-# This doesn't seem to matter to ld-linux.so.2 at all, except that it
14-# refuses to load `Linux' executables when invokes explicitly, that
15-# is, when we do `ld-linux.so.2 $out/System/ut2004-bin', which we need
16-# to override the hardcoded ELF interpreter with our own.
17-18-# This is a horrible hack, of course. A better solution would be to
19-# patch Glibc so it accepts the `Linux' ELF type as well (why doesn't
20-# it?); or to use FreeBSD's `brandelf' program to set to ELF type
21-# (which is a bit cleaner than patching using `dd' :-) ).
22-23-#(cd $out/System && (echo -en "\000" | dd bs=1 seek=7 of=ut2004-bin conv=notrunc))
24-25-26-# Set the ELF interpreter to our own Glibc.
27-for i in "$out/System/ucc-bin" "$out/System/ut2004-bin"; do
28- patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$i"
29-done