From 2551d9717eb849dbca795586a96ba5e5e6d65645 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sat, 3 Sep 2016 16:52:39 +0300 Subject: [PATCH] ut2004demo: refactor, 3120 -> 3334 --- pkgs/games/ut2004/default.nix | 9 ++++++ pkgs/games/ut2004/demo.nix | 40 +++++++++++++++++++++++ pkgs/games/ut2004/wrapper.nix | 46 +++++++++++++++++++++++++++ pkgs/games/ut2004demo/builder.sh | 29 ----------------- pkgs/games/ut2004demo/default.nix | 34 -------------------- pkgs/games/ut2004demo/make-wrapper.sh | 13 -------- pkgs/top-level/all-packages.nix | 4 ++- 7 files changed, 98 insertions(+), 77 deletions(-) create mode 100644 pkgs/games/ut2004/default.nix create mode 100644 pkgs/games/ut2004/demo.nix create mode 100644 pkgs/games/ut2004/wrapper.nix delete mode 100644 pkgs/games/ut2004demo/builder.sh delete mode 100644 pkgs/games/ut2004demo/default.nix delete mode 100644 pkgs/games/ut2004demo/make-wrapper.sh diff --git a/pkgs/games/ut2004/default.nix b/pkgs/games/ut2004/default.nix new file mode 100644 index 000000000000..3f306ac6eb54 --- /dev/null +++ b/pkgs/games/ut2004/default.nix @@ -0,0 +1,9 @@ +{ callPackage }: + +{ + ut2004-demo = callPackage ./demo.nix { }; + + ut2004 = gamePacks: callPackage ./wrapper.nix { + inherit gamePacks; + }; +} diff --git a/pkgs/games/ut2004/demo.nix b/pkgs/games/ut2004/demo.nix new file mode 100644 index 000000000000..f5fcdc088c8f --- /dev/null +++ b/pkgs/games/ut2004/demo.nix @@ -0,0 +1,40 @@ +{ stdenv, fetchurl }: + +let + arch = + if stdenv.system == "x86_64-linux" then "amd64" + else if stdenv.system == "i686-linux" then "x86" + else throw "Unsupported architecture"; + +in stdenv.mkDerivation rec { + name = "ut2004-demo-${version}"; + version = "3334"; + + src = fetchurl { + url = "http://treefort.icculus.org/ut2004/UT2004-LNX-Demo${version}.run.gz"; + sha256 = "0d5f84qz8l1rg16yzx2k4ikr46n9iwj68na1bqi87wrww7ck6jh7"; + }; + + buildCommand = '' + cat $src | gunzip > setup.run + chmod +x setup.run + ./setup.run --noexec --target . + mkdir $out + tar -xaf ut2004demo.tar.bz2 -C $out + tar -xaf linux-${arch}.tar.bz2 -C $out + + rm $out/System/libSDL-1.2.so.0 + rm $out/System/openal.so + ''; + + dontStrip = true; + dontPatchELF = true; + + meta = with stdenv.lib; { + description = "A first-person shooter video game developed by Epic Games and Digital Extreme -- demo version"; + homepage = "http://www.unrealtournament2004.com"; + license = licenses.unfree; + maintainers = with maintainers; [ abbradar ]; + platforms = [ "x86_64-linux" "i686-linux" ]; + }; +} diff --git a/pkgs/games/ut2004/wrapper.nix b/pkgs/games/ut2004/wrapper.nix new file mode 100644 index 000000000000..31d0763be4d2 --- /dev/null +++ b/pkgs/games/ut2004/wrapper.nix @@ -0,0 +1,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 +'' diff --git a/pkgs/games/ut2004demo/builder.sh b/pkgs/games/ut2004demo/builder.sh deleted file mode 100644 index ca6b4fe1092c..000000000000 --- a/pkgs/games/ut2004demo/builder.sh +++ /dev/null @@ -1,29 +0,0 @@ -source $stdenv/setup - -skip=7976 - -bunzip2 < $src | (dd bs=1 count=$skip of=/dev/null && dd bs=1M) | tar xvf - ut2004demo.tar - -mkdir $out - -(cd $out && tar xvf -) < ut2004demo.tar - - -# Patch the executable from ELF OS/ABI type `Linux' (3) to `SVR4' (0). -# This doesn't seem to matter to ld-linux.so.2 at all, except that it -# refuses to load `Linux' executables when invokes explicitly, that -# is, when we do `ld-linux.so.2 $out/System/ut2004-bin', which we need -# to override the hardcoded ELF interpreter with our own. - -# This is a horrible hack, of course. A better solution would be to -# patch Glibc so it accepts the `Linux' ELF type as well (why doesn't -# it?); or to use FreeBSD's `brandelf' program to set to ELF type -# (which is a bit cleaner than patching using `dd' :-) ). - -#(cd $out/System && (echo -en "\000" | dd bs=1 seek=7 of=ut2004-bin conv=notrunc)) - - -# Set the ELF interpreter to our own Glibc. -for i in "$out/System/ucc-bin" "$out/System/ut2004-bin"; do - patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$i" -done diff --git a/pkgs/games/ut2004demo/default.nix b/pkgs/games/ut2004demo/default.nix deleted file mode 100644 index 27b81edf630b..000000000000 --- a/pkgs/games/ut2004demo/default.nix +++ /dev/null @@ -1,34 +0,0 @@ -{stdenv, fetchurl, xorg, mesa}: - -assert stdenv.system == "i686-linux"; - -let { - - raw = stdenv.mkDerivation { - name = "ut2004-demo-3120"; - src = fetchurl { - urls = [ - ("http://store.node-10.ds-servers.com/file/BcFLgoIgAADQA7kw0qZctDAF+4cj" - + "mbnDMFOJTAyM0-cejkEIuDvQ6Uv9ZbvcWMnRmXXxhA0LyvzoKdvsnXne0D1DGTLiR0" - + "I1CmM2M-E5ryH-tD3yweCXyNyH1WGI3Wh09ja29mHtzGF1rxEyhRfQ7ggCKdfCrhvz" - + "H9oTJXSCAtGuSKdVDhe6tNtrqa151MIircZtRLPxQcGmJ+n3-iUeWYgHuqbmrK4ur7" - + "Qcy6QrAhYa+e5jcfYjgPF3VGsw4qx+0ilxJUCiuYCX2H8A6X3rxJILa26w3O425W2G" - + "kHPiQWrhFT8cIOyqSr8+dMO5Xi5-/ut2004-lnx-demo-3120.run.bz2") - http://ftp.gameaholic.com/pub/demos/ut2004-lnx-demo-3120.run.bz2 - ]; - sha256 = "1lravfkb1gsallqqird5dcbz42vwjg36m1qk76nmmnyyyghwqnli"; - }; - builder = ./builder.sh; - }; - - body = stdenv.mkDerivation { - name = raw.name; - builder = ./make-wrapper.sh; - inherit raw mesa; - inherit (xorg) libX11 libXext; - }; - -} - -# http://mirror1.icculus.org/ut2004/ut2004-lnxpatch3204.tar.bz2 -# 5f659552095b878a029b917d216d9664 diff --git a/pkgs/games/ut2004demo/make-wrapper.sh b/pkgs/games/ut2004demo/make-wrapper.sh deleted file mode 100644 index 53ef90a615b0..000000000000 --- a/pkgs/games/ut2004demo/make-wrapper.sh +++ /dev/null @@ -1,13 +0,0 @@ -source $stdenv/setup - -mkdir -p $out/bin - -cat > $out/bin/ut2004demo <