about summary refs log tree commit diff
path: root/pkgs/games/classicube/default.nix
blob: ec2490196abba3d926b5adf69a05d32f19086a8a (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{ lib
, stdenv
, fetchFromGitHub
, dos2unix
, makeWrapper
, makeDesktopItem
, copyDesktopItems
, libX11
, libXi
, libGL
, curl
, openal
, liberation_ttf
}:

stdenv.mkDerivation rec {
  pname = "ClassiCube";
  version = "1.3.5";

  src = fetchFromGitHub {
    owner = "UnknownShadow200";
    repo = "ClassiCube";
    rev = version;
    sha256 = "sha256-anBi9hPwX1AAIc8dXsKyX4u7UbkKqC1P+7f7wdKWAig=";
  };

  nativeBuildInputs = [ dos2unix makeWrapper copyDesktopItems ];

  desktopItems = [
    (makeDesktopItem {
      name = pname;
      desktopName = pname;
      genericName = "Sandbox Block Game";
      exec = "ClassiCube";
      icon = "CCicon";
      comment = "Minecraft Classic inspired sandbox game";
      categories = [ "Game" ];
    })
  ];

  prePatch = ''
    # The ClassiCube sources have DOS-style newlines
    # which causes problems with diff/patch.
    dos2unix 'src/Platform_Posix.c' 'src/Core.h'
  '';

  patches = [
    # Fix hardcoded font paths
    ./font-location.patch
    # For some reason, the Makefile doesn't link
    # with libcurl and openal when ClassiCube requires them.
    ./fix-linking.patch
  ];

  font_path = "${liberation_ttf}/share/fonts/truetype";

  enableParallelBuilding = true;

  postPatch = ''
    # ClassiCube hardcodes locations of fonts.
    # This changes the hardcoded location
    # to the path of liberation_ttf instead
    substituteInPlace src/Platform_Posix.c \
      --replace '%NIXPKGS_FONT_PATH%' "${font_path}"
    # ClassiCube's Makefile hardcodes JOBS=1 for some reason,
    # even though it works perfectly well multi-threaded.
    substituteInPlace src/Makefile \
      --replace 'JOBS=1' "JOBS=$NIX_BUILD_CORES"
  '';

  buildInputs = [ libX11 libXi libGL curl openal liberation_ttf ];

  preBuild = "cd src";

  postBuild = "cd -";

  installPhase = ''
    runHook preInstall

    mkdir -p "$out/bin"
    cp 'src/ClassiCube' "$out/bin"
    # ClassiCube puts downloaded resources
    # next to the location of the executable by default.
    # This doesn't work with Nix
    # as the location of the executable is read-only.
    # We wrap the program to make it put its resources
    # in ~/.local/share instead.
    wrapProgram "$out/bin/ClassiCube" \
      --run 'mkdir -p "$HOME/.local/share/ClassiCube"' \
      --run 'cd       "$HOME/.local/share/ClassiCube"'

    mkdir -p "$out/share/icons/hicolor/256x256/apps"
    cp misc/CCicon.png "$out/share/icons/hicolor/256x256/apps"

    runHook postInstall
  '';

  meta = with lib; {
    homepage = "https://www.classicube.net/";
    description = "A lightweight, custom Minecraft Classic/ClassiCube client with optional additions written from scratch in C";
    license = licenses.bsd3;
    platforms = platforms.linux;
    maintainers = with maintainers; [ _360ied ];
  };
}