···11+{ stdenv, fetchurl }:
22+33+let
44+ arch =
55+ if stdenv.system == "x86_64-linux" then "amd64"
66+ else if stdenv.system == "i686-linux" then "x86"
77+ else throw "Unsupported architecture";
88+99+in stdenv.mkDerivation rec {
1010+ name = "ut2004-demo-${version}";
1111+ version = "3334";
1212+1313+ src = fetchurl {
1414+ url = "http://treefort.icculus.org/ut2004/UT2004-LNX-Demo${version}.run.gz";
1515+ sha256 = "0d5f84qz8l1rg16yzx2k4ikr46n9iwj68na1bqi87wrww7ck6jh7";
1616+ };
1717+1818+ buildCommand = ''
1919+ cat $src | gunzip > setup.run
2020+ chmod +x setup.run
2121+ ./setup.run --noexec --target .
2222+ mkdir $out
2323+ tar -xaf ut2004demo.tar.bz2 -C $out
2424+ tar -xaf linux-${arch}.tar.bz2 -C $out
2525+2626+ rm $out/System/libSDL-1.2.so.0
2727+ rm $out/System/openal.so
2828+ '';
2929+3030+ dontStrip = true;
3131+ dontPatchELF = true;
3232+3333+ meta = with stdenv.lib; {
3434+ description = "A first-person shooter video game developed by Epic Games and Digital Extreme -- demo version";
3535+ homepage = "http://www.unrealtournament2004.com";
3636+ license = licenses.unfree;
3737+ maintainers = with maintainers; [ abbradar ];
3838+ platforms = [ "x86_64-linux" "i686-linux" ];
3939+ };
4040+}
+46
pkgs/games/ut2004/wrapper.nix
···11+{ stdenv, lib, runCommand, buildEnv, makeWrapper, makeDesktopItem, gamePacks, libstdcxx5, SDL, openal }:
22+33+let
44+ game = buildEnv {
55+ name = "ut2004-game";
66+ paths = gamePacks;
77+ ignoreCollisions = true;
88+ pathsToLink = [ "/" "/System" ];
99+ postBuild = ''
1010+ ln -s ${lib.getLib SDL}/lib/libSDL-1.2.so.0 $out/System
1111+ ln -s ${lib.getLib openal}/lib/libopenal.so $out/System/openal.so
1212+ for i in $out/System/*-bin; do
1313+ path="$(readlink -f "$i")"
1414+ rm "$i"
1515+ cp "$path" "$i"
1616+ chmod +w "$i"
1717+ patchelf \
1818+ --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) \
1919+ --set-rpath "$out/System:${lib.makeLibraryPath [ libstdcxx5 ]}" \
2020+ "$i"
2121+ done
2222+ '';
2323+ };
2424+2525+ desktop = makeDesktopItem {
2626+ name = "ut2004";
2727+ desktopName = "Unreal Tournament 2004";
2828+ comment = "A first-person shooter video game developed by Epic Games and Digital Extreme";
2929+ genericName = "First-person shooter";
3030+ categories = "Application;Game;";
3131+ exec = "ut2004";
3232+ };
3333+3434+in runCommand "ut2004" {
3535+ nativeBuildInputs = [ makeWrapper ];
3636+} ''
3737+ mkdir -p $out/bin
3838+ for i in ${game}/System/*-bin; do
3939+ name="$(basename "$i")"
4040+ makeWrapper $i $out/bin/''${name%-bin} \
4141+ --run "cd ${game}/System"
4242+ done
4343+4444+ mkdir -p $out/share/applications
4545+ ln -s ${desktop}/share/applications/* $out/share/applications
4646+''
-29
pkgs/games/ut2004demo/builder.sh
···11-source $stdenv/setup
22-33-skip=7976
44-55-bunzip2 < $src | (dd bs=1 count=$skip of=/dev/null && dd bs=1M) | tar xvf - ut2004demo.tar
66-77-mkdir $out
88-99-(cd $out && tar xvf -) < ut2004demo.tar
1010-1111-1212-# Patch the executable from ELF OS/ABI type `Linux' (3) to `SVR4' (0).
1313-# This doesn't seem to matter to ld-linux.so.2 at all, except that it
1414-# refuses to load `Linux' executables when invokes explicitly, that
1515-# is, when we do `ld-linux.so.2 $out/System/ut2004-bin', which we need
1616-# to override the hardcoded ELF interpreter with our own.
1717-1818-# This is a horrible hack, of course. A better solution would be to
1919-# patch Glibc so it accepts the `Linux' ELF type as well (why doesn't
2020-# it?); or to use FreeBSD's `brandelf' program to set to ELF type
2121-# (which is a bit cleaner than patching using `dd' :-) ).
2222-2323-#(cd $out/System && (echo -en "\000" | dd bs=1 seek=7 of=ut2004-bin conv=notrunc))
2424-2525-2626-# Set the ELF interpreter to our own Glibc.
2727-for i in "$out/System/ucc-bin" "$out/System/ut2004-bin"; do
2828- patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$i"
2929-done