pytrainer: unpin python 3.10
[NixPkgs.git] / pkgs / games / 0ad / game.nix
blob676c14fd1fc91bf5eeba7c5af99aee783bc6dd1a
1 { stdenv, lib, fetchpatch, fetchpatch2, perl, fetchurl, python3, fmt, libidn
2 , pkg-config, spidermonkey_78, boost, icu, libxml2, libpng, libsodium
3 , libjpeg, zlib, curl, libogg, libvorbis, enet, miniupnpc
4 , openal, libGLU, libGL, xorgproto, libX11, libXcursor, nspr, SDL2
5 , gloox, nvidia-texture-tools, freetype
6 , withEditor ? true, wxGTK
7 }:
9 # You can find more instructions on how to build 0ad here:
10 #    https://trac.wildfiregames.com/wiki/BuildInstructions
12 let
13   # the game requires a special version 78.6.0 of spidermonkey, otherwise
14   # we get compilation errors. We override the src attribute of spidermonkey_78
15   # in order to reuse that declartion, while giving it a different source input.
16   spidermonkey_78_6 = spidermonkey_78.overrideAttrs(old: rec {
17     version = "78.6.0";
18     src = fetchurl {
19       url = "mirror://mozilla/firefox/releases/${version}esr/source/firefox-${version}esr.source.tar.xz";
20       sha256 = "0lyg65v380j8i2lrylwz8a5ya80822l8vcnlx3dfqpd3s6zzjsay";
21     };
22     patches = (old.patches or []) ++ [
23       ./spidermonkey-cargo-toml.patch
24     ];
25   });
27 stdenv.mkDerivation rec {
28   pname = "0ad";
29   version = "0.0.26";
31   src = fetchurl {
32     url = "http://releases.wildfiregames.com/0ad-${version}-alpha-unix-build.tar.xz";
33     sha256 = "Lhxt9+MxLnfF+CeIZkz/w6eNO/YGBsAAOSdeHRPA7ks=";
34   };
36   nativeBuildInputs = [ python3 perl pkg-config ];
38   buildInputs = [
39     spidermonkey_78_6 boost icu libxml2 libpng libjpeg
40     zlib curl libogg libvorbis enet miniupnpc openal libidn
41     libGLU libGL xorgproto libX11 libXcursor nspr SDL2 gloox
42     nvidia-texture-tools libsodium fmt freetype
43   ] ++ lib.optional withEditor wxGTK;
45   env.NIX_CFLAGS_COMPILE = toString [
46     "-I${xorgproto}/include"
47     "-I${libX11.dev}/include"
48     "-I${libXcursor.dev}/include"
49     "-I${SDL2}/include/SDL2"
50     "-I${fmt.dev}/include"
51     "-I${nvidia-texture-tools.dev}/include"
52   ];
54   NIX_CFLAGS_LINK = toString [
55     "-L${nvidia-texture-tools.lib}/lib/static"
56   ];
58   patches = [
59     ./rootdir_env.patch
61     # Fix build with libxml v2.12
62     # FIXME: Remove with next package update
63     (fetchpatch {
64       name = "libxml-2.12-fix.patch";
65       url = "https://github.com/0ad/0ad/commit/d242631245edb66816ef9960bdb2c61b68e56cec.patch";
66       hash = "sha256-Ik8ThkewB7wyTPTI7Y6k88SqpWUulXK698tevfSBr6I=";
67     })
68     # Fix build with GCC 13
69     # FIXME: Remove with next package update
70     (fetchpatch {
71       name = "gcc-13-fix.patch";
72       url = "https://github.com/0ad/0ad/commit/093e1eb23519ab4a4633a999a555a58e4fd5343e.patch";
73       hash = "sha256-NuWO64narU1JID/F3cj7lJKjo96XR7gSW0w8I3/hhuw=";
74     })
75     # Fix build with miniupnpc 2.2.8
76     # https://github.com/0ad/0ad/pull/45
77     (fetchpatch2 {
78       url = "https://github.com/0ad/0ad/commit/1575580bbc5278576693f3fbbb32de0b306aa27e.patch?full_index=1";
79       hash = "sha256-iXiUYTJCWwJpb2U3P58jTV4OpyW6quofu8Jq6xNEq48=";
80     })
81   ];
83   configurePhase = ''
84     # Delete shipped libraries which we don't need.
85     rm -rf libraries/source/{enet,miniupnpc,nvtt,spidermonkey}
87     # Update Makefiles
88     pushd build/workspaces
89     ./update-workspaces.sh \
90       --with-system-nvtt \
91       --with-system-mozjs \
92       ${lib.optionalString withEditor "--enable-atlas"} \
93       --bindir="$out"/bin \
94       --libdir="$out"/lib/0ad \
95       --without-tests \
96       -j $NIX_BUILD_CORES
97     popd
99     # Move to the build directory.
100     pushd build/workspaces/gcc
101   '';
103   enableParallelBuilding = true;
105   installPhase = ''
106     popd
108     # Copy executables.
109     install -Dm755 binaries/system/pyrogenesis "$out"/bin/0ad
110     ${lib.optionalString withEditor ''
111       install -Dm755 binaries/system/ActorEditor "$out"/bin/ActorEditor
112     ''}
114     # Copy l10n data.
115     install -Dm755 -t $out/share/0ad/data/l10n binaries/data/l10n/*
117     # Copy libraries.
118     install -Dm644 -t $out/lib/0ad        binaries/system/*.so
120     # Copy icon.
121     install -D build/resources/0ad.png     $out/share/icons/hicolor/128x128/apps/0ad.png
122     install -D build/resources/0ad.desktop $out/share/applications/0ad.desktop
123   '';
125   meta = with lib; {
126     description = "Free, open-source game of ancient warfare";
127     homepage = "https://play0ad.com/";
128     license = with licenses; [
129       gpl2Plus lgpl21 mit cc-by-sa-30
130       licenses.zlib # otherwise masked by pkgs.zlib
131     ];
132     maintainers = with maintainers; [ chvp ];
133     platforms = subtractLists platforms.i686 platforms.linux;
134     mainProgram = "0ad";
135   };