about summary refs log tree commit diff
path: root/pkgs/games/fallout-ce/build.nix
blob: c220895db08cee532d6586e087220f43ce88afe7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{ cmake
, fpattern
, lib
, SDL2
, stdenv
, writeShellScript

, extraBuildInputs ? [ ]
, extraMeta
, pname
, version
, src
}:

let
  launcher = writeShellScript "${pname}" ''
    set -eu
    assetDir="''${XDG_DATA_HOME:-$HOME/.local/share}/${pname}"
    [ -d "$assetDir" ] || mkdir -p "$assetDir"
    cd "$assetDir"

    notice=0 fault=0
    requiredFiles=(master.dat critter.dat)
    for f in "''${requiredFiles[@]}"; do
      if [ ! -f "$f" ]; then
        echo "Required file $f not found in $PWD, note the files are case-sensitive"
        notice=1 fault=1
      fi
    done

    if [ ! -d "data/sound/music" ]; then
      echo "data/sound/music directory not found in $PWD. This may prevent in-game music from functioning."
      notice=1
    fi

    if [ $notice -ne 0 ]; then
      echo "Please reference the installation instructions at https://github.com/alexbatalov/fallout2-ce"
    fi

    if [ $fault -ne 0 ]; then
      exit $fault;
    fi

    exec @out@/libexec/${pname} "$@"
  '';
in
stdenv.mkDerivation {
  inherit pname version src;

  nativeBuildInputs = [ cmake ];
  buildInputs = [ SDL2 ] ++ extraBuildInputs;
  hardeningDisable = [ "format" ];
  cmakeBuildType = "RelWithDebInfo";

  postPatch = ''
    substituteInPlace third_party/fpattern/CMakeLists.txt \
      --replace "FetchContent_Populate" "#FetchContent_Populate" \
      --replace "{fpattern_SOURCE_DIR}" "${fpattern}/include" \
      --replace "$/nix/" "/nix/"
  '';

  installPhase = ''
    runHook preInstall

    install -D ${pname} $out/libexec/${pname}
    install -D ${launcher} $out/bin/${pname}
    substituteInPlace $out/bin/${pname} --subst-var out

    runHook postInstall
  '';

  meta = with lib; {
    license = licenses.sustainableUse;
    maintainers = with maintainers; [ hughobrien TheBrainScrambler ];
    platforms = platforms.linux;
  } // extraMeta;
}