@@ -0,0 +1,104 @@
1+{ stdenv, fetchurl
2+
3+# Build-time dependencies
4+, makeWrapper
5+, file
6+
7+# Runtime dependencies
8+, fontconfig
9+, freetype
10+, libX11
11+, libXext
12+, libXinerama
13+, libXrandr
14+, libXrender
15+, openal}:
16+
17+let
18+ version = "1.0";
19+ pkgversion = "1";
20+
21+ arch = if stdenv.system == "x86_64-linux" then
22+ "x64"
23+ else if stdenv.system == "i686-linux" then
24+ "x86"
25+ else
26+ abort "Unsupported platform";
27+
28+in
29+ stdenv.mkDerivation {
30+ name = "unigine-valley-${version}-${pkgversion}";
31+
32+ src = fetchurl {
33+ url = "http://assets.unigine.com/d/Unigine_Valley-${version}.run";
34+ sha256 = "5f0c8bd2431118551182babbf5f1c20fb14e7a40789697240dcaf546443660f4";
35+ };
36+
37+ sourceRoot = "Unigine_Valley-${version}";
38+
39+ buildInputs = [file makeWrapper];
40+
41+ libPath = stdenv.lib.makeLibraryPath [
42+ stdenv.cc.cc # libstdc++.so.6
43+ fontconfig
44+ freetype
45+ libX11
46+ libXext
47+ libXinerama
48+ libXrandr
49+ libXrender
50+ openal
51+ ];
52+
53+ unpackPhase = ''
54+ cp $src extractor.run
55+ chmod +x extractor.run
56+ ./extractor.run --target $sourceRoot
57+ '';
58+
59+ # The executable loads libGPUMonitor_${arch}.so "manually" (i.e. not through the ELF interpreter).
60+ # However, it still uses the RPATH to look for it.
61+ patchPhase = ''
62+ # Patch ELF files.
63+ elfs=$(find bin -type f | xargs file | grep ELF | cut -d ':' -f 1)
64+ for elf in $elfs; do
65+ echo "Patching $elf"
66+ patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux-x86-64.so.2 $elf || true
67+ done
68+ '';
69+
70+ configurePhase = "";
71+ buildPhase = "";
72+
73+ installPhase = ''
74+ instdir=$out/opt/unigine/valley
75+
76+ # Install executables and libraries
77+ mkdir -p $instdir/bin
78+ install -m 0755 bin/browser_${arch} $instdir/bin
79+ install -m 0755 bin/libApp{Stereo,Surround,Wall}_${arch}.so $instdir/bin
80+ install -m 0755 bin/libGPUMonitor_${arch}.so $instdir/bin
81+ install -m 0755 bin/libQt{Core,Gui,Network,WebKit,Xml}Unigine_${arch}.so.4 $instdir/bin
82+ install -m 0755 bin/libUnigine_${arch}.so $instdir/bin
83+ install -m 0755 bin/valley_${arch} $instdir/bin
84+ install -m 0755 valley $instdir
85+
86+ # Install other files
87+ cp -R data documentation $instdir
88+
89+ # Install and wrap executable
90+ mkdir -p $out/bin
91+ install -m 0755 valley $out/bin/valley
92+ wrapProgram $out/bin/valley \
93+ --run "cd $instdir" \
94+ --prefix LD_LIBRARY_PATH : /run/opengl-driver/lib:$instdir/bin:$libPath
95+ '';
96+
97+ meta = {
98+ description = "The Unigine Valley GPU benchmarking tool";
99+ homepage = "http://unigine.com/products/benchmarks/valley/";
100+ license = stdenv.lib.licenses.unfree; # see also: /nix/store/*-unigine-valley-1.0/opt/unigine/valley/documentation/License.pdf
101+ maintainers = [ stdenv.lib.maintainers.kierdavis ];
102+ platforms = ["x86_64-linux" "i686-linux"];
103+ };
104+ }