btrbk: add mainProgram (#356350)
[NixPkgs.git] / pkgs / by-name / un / unvanquished / package.nix
blob764dd605a015ab07d84da6c026db3e30549671d1
1 { lib
2 , stdenv
3 , fetchzip
4 , fetchFromGitHub
5 , SDL2
6 , buildFHSEnv
7 , cmake
8 , copyDesktopItems
9 , curl
10 , freetype
11 , gcc
12 , geoip
13 , glew
14 , gmp
15 , libGL
16 , libjpeg
17 , libogg
18 , libopus
19 , libpng
20 , libvorbis
21 , libwebp
22 , lua5
23 , makeDesktopItem
24 , ncurses
25 , nettle
26 , openal
27 , opusfile
28 , zlib
29 # to download assets
30 , aria2
31 , cacert
34 let
35   version = "0.55.0";
36   binary-deps-version = "10";
38   src = fetchFromGitHub {
39     owner = "Unvanquished";
40     repo = "Unvanquished";
41     rev = "v${version}";
42     fetchSubmodules = true;
43     hash = "sha256-4ONge+GnrpV/FHKuA66o7uK7jIygBYizZl8JAUr8x/0=";
44   };
46   unvanquished-binary-deps = stdenv.mkDerivation rec {
47     # DISCLAIMER: this is selected binary crap from the NaCl SDK
48     name = "unvanquished-binary-deps";
49     version = binary-deps-version;
51     src = fetchzip {
52       url = "https://dl.unvanquished.net/deps/linux-amd64-default_${version}.tar.xz ";
53       hash = "sha256-5n8gRvTuke4e7EaZ/5G+dtCG6qmnawhtA1IXIFQPkzA=";
54     };
56     dontPatchELF = true;
58     preFixup = ''
59       # We are not using the autoPatchelfHook, because it would make
60       # nacl_bootstrap_helper unable to load nacl_loader:
61       # "nacl_loader: ELF file has unreasonable e_phnum=13"
62       interpreter="$(< "$NIX_CC/nix-support/dynamic-linker")"
63       for f in pnacl/bin/*; do
64         if [ -f "$f" && -x "$f" ]; then
65           echo "Patching $f"
66           patchelf --set-interpreter "$interpreter" "$f"
67         fi
68       done
69     '';
71     preCheck = ''
72       # check it links correctly
73       pnacl/bin/clang -v
74     '';
76     installPhase = ''
77       runHook preInstall
79       mkdir -p $out
80       cp -R ./* $out/
82       runHook postInstall
83     '';
84   };
86   libstdcpp-preload-for-unvanquished-nacl = stdenv.mkDerivation {
87     name = "libstdcpp-preload-for-unvanquished-nacl";
89     propagatedBuildInputs = [ gcc.cc.lib ];
91     buildCommand = ''
92       mkdir $out/etc -p
93       echo ${gcc.cc.lib}/lib/libstdc++.so.6 > $out/etc/ld-nix.so.preload
94     '';
95   };
97   fhsEnv = buildFHSEnv {
98     name = "unvanquished-fhs-wrapper";
100     targetPkgs = pkgs: [ libstdcpp-preload-for-unvanquished-nacl ];
101   };
103   wrapBinary = binary: wrappername: ''
104     cat > $out/lib/${binary}-wrapper <<-EOT
105     #!/bin/sh
106     exec $out/lib/${binary} -pakpath ${unvanquished-assets} "\$@"
107     EOT
108     chmod +x $out/lib/${binary}-wrapper
110     cat > $out/bin/${wrappername} <<-EOT
111     #!/bin/sh
112     exec ${fhsEnv}/bin/unvanquished-fhs-wrapper $out/lib/${binary}-wrapper "\$@"
113     EOT
114     chmod +x $out/bin/${wrappername}
115   '';
117   unvanquished-assets = stdenv.mkDerivation {
118     pname = "unvanquished-assets";
119     inherit version src;
121     outputHash = "sha256-FDDhwBvmv4EvmSh5g6Cb0HYLuY9T++k7q8egxzo04J8=";
122     outputHashMode = "recursive";
124     nativeBuildInputs = [ aria2 cacert ];
126     buildCommand = ''
127       bash $src/download-paks --cache=$(pwd) --version=${version} $out
128     '';
129   };
131 # this really is the daemon game engine, the game itself is in the assets
132 in stdenv.mkDerivation rec {
133   pname = "unvanquished";
134   inherit version src binary-deps-version;
136   preConfigure = ''
137     TARGET="linux-amd64-default_${binary-deps-version}"
138     mkdir daemon/external_deps/"$TARGET"
139     cp -r ${unvanquished-binary-deps}/* daemon/external_deps/"$TARGET"/
140     chmod +w -R daemon/external_deps/"$TARGET"/
141   '';
143   nativeBuildInputs = [
144     cmake
145     unvanquished-binary-deps
146     copyDesktopItems
147   ];
149   buildInputs = [
150     gmp
151     libGL
152     zlib
153     ncurses
154     geoip
155     lua5
156     nettle
157     curl
158     SDL2
159     freetype
160     glew
161     openal
162     libopus
163     opusfile
164     libogg
165     libvorbis
166     libjpeg
167     libwebp
168     libpng
169   ];
171   cmakeFlags = [
172     "-DBUILD_CGAME=NO"
173     "-DBUILD_SGAME=NO"
174     "-DUSE_HARDENING=TRUE"
175     "-DUSE_LTO=TRUE"
176     "-DOpenGL_GL_PREFERENCE=LEGACY" # https://github.com/DaemonEngine/Daemon/issues/474
177   ];
179   desktopItems = [
180     (makeDesktopItem {
181       name = "net.unvanquished.Unvanquished.desktop";
182       desktopName = "Unvanquished";
183       comment = "FPS/RTS Game - Aliens vs. Humans";
184       icon = "unvanquished";
185       exec = "unvanquished";
186       categories = [ "Game" "ActionGame" "StrategyGame" ];
187       prefersNonDefaultGPU = true;
188     })
189     (makeDesktopItem {
190       name = "net.unvanquished.UnvanquishedProtocolHandler.desktop";
191       desktopName = "Unvanquished (protocol handler)";
192       noDisplay = true;
193       exec = "unvanquished -connect %u";
194       mimeTypes = [ "x-scheme-handler/unv" ];
195       prefersNonDefaultGPU = true;
196     })
197   ];
199   installPhase = ''
200     runHook preInstall
202     for f in daemon daemon-tty daemonded nacl_loader nacl_helper_bootstrap; do
203       install -Dm0755 -t $out/lib/ $f
204     done
205     install -Dm0644 -t $out/lib/ irt_core-amd64.nexe
207     mkdir $out/bin/
208     ${wrapBinary "daemon"     "unvanquished"}
209     ${wrapBinary "daemon-tty" "unvanquished-tty"}
210     ${wrapBinary "daemonded"  "unvanquished-server"}
212     for d in ${src}/dist/icons/*; do
213       install -Dm0644 -t $out/share/icons/hicolor/$(basename $d)/apps/ $d/unvanquished.png
214     done
216     runHook postInstall
217   '';
219   meta = {
220     homepage = "https://unvanquished.net/";
221     downloadPage = "https://unvanquished.net/download/";
222     description = "Fast paced, first person strategy game";
223     # don't replace the following lib.licenses.zlib with just "zlib",
224     # or you would end up with the package instead
225     license = with lib.licenses; [
226       mit gpl3Plus lib.licenses.zlib bsd3 # engine
227       cc-by-sa-25 cc-by-sa-30 cc-by-30 cc-by-sa-40 cc0 # assets
228     ];
229     sourceProvenance = with lib.sourceTypes; [
230       fromSource
231       binaryNativeCode  # unvanquished-binary-deps
232     ];
233     maintainers = with lib.maintainers; [ afontain ];
234     platforms = [ "x86_64-linux" ];
235   };