k3s: format with nixfmt-rfc-style
[NixPkgs.git] / pkgs / games / ja2-stracciatella / default.nix
blobea363c969429d51c2d5b77087b09fcfb17dd4e39
1 { stdenv, lib, fetchurl, fetchFromGitHub, cmake, python3, rustPlatform, SDL2, fltk, rapidjson, gtest, Carbon, Cocoa }:
2 let
3   version = "0.17.0";
4   src = fetchFromGitHub {
5     owner = "ja2-stracciatella";
6     repo = "ja2-stracciatella";
7     rev = "v${version}";
8     sha256 = "0m6rvgkba29jy3yq5hs1sn26mwrjl6mamqnv4plrid5fqaivhn6j";
9   };
10   libstracciatella = rustPlatform.buildRustPackage {
11     pname = "libstracciatella";
12     inherit version;
13     src = "${src}/rust";
14     cargoHash = "sha256-asUt+wUpwwDvSyuNZds6yMC4Ef4D8woMYWamzcJJiy4=";
16     preBuild = ''
17       mkdir -p $out/include/stracciatella
18       export HEADER_LOCATION=$out/include/stracciatella/stracciatella.h
19     '';
20   };
21   stringTheoryUrl = "https://github.com/zrax/string_theory/archive/3.1.tar.gz";
22   stringTheory = fetchurl {
23     url = stringTheoryUrl;
24     sha256 = "1flq26kkvx2m1yd38ldcq2k046yqw07jahms8a6614m924bmbv41";
25   };
27 stdenv.mkDerivation {
28   pname = "ja2-stracciatella";
29   inherit src version;
31   nativeBuildInputs = [ cmake python3 ];
32   buildInputs = [ SDL2 fltk rapidjson gtest ] ++ lib.optionals stdenv.isDarwin [ Carbon Cocoa ];
34   patches = [
35     ./remove-rust-buildstep.patch
36   ];
38   preConfigure = ''
39     # Use rust library built with nix
40     substituteInPlace CMakeLists.txt \
41       --replace lib/libstracciatella_c_api.a ${libstracciatella}/lib/libstracciatella_c_api.a \
42       --replace include/stracciatella ${libstracciatella}/include/stracciatella \
43       --replace bin/ja2-resource-pack ${libstracciatella}/bin/ja2-resource-pack
45     # Patch dependencies that are usually loaded by url
46     substituteInPlace dependencies/lib-string_theory/builder/CMakeLists.txt.in \
47       --replace ${stringTheoryUrl} file://${stringTheory}
49     cmakeFlagsArray+=("-DLOCAL_RAPIDJSON_LIB=OFF" "-DLOCAL_GTEST_LIB=OFF" "-DEXTRA_DATA_DIR=$out/share/ja2")
50   '';
52   doInstallCheck = true;
53   installCheckPhase = ''
54     HOME=/tmp $out/bin/ja2 -unittests
55   '';
57   meta = {
58     description = "Jagged Alliance 2, with community fixes";
59     license = "SFI Source Code license agreement";
60     homepage = "https://ja2-stracciatella.github.io/";
61   };