nixpkgs/pkgs/games/classicube/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

109 lines
2.9 KiB
Nix
Raw Normal View History

{ lib
, stdenv
, fetchFromGitHub
, dos2unix
, makeWrapper
2022-12-27 22:49:58 +01:00
, makeDesktopItem
, copyDesktopItems
, SDL2
, libGL
, curl
, openal
, liberation_ttf
}:
stdenv.mkDerivation rec {
pname = "ClassiCube";
2022-11-02 22:09:59 +01:00
version = "1.3.4";
src = fetchFromGitHub {
owner = "UnknownShadow200";
repo = "ClassiCube";
rev = version;
2022-11-02 22:09:59 +01:00
sha256 = "sha256-m7pg9OL2RuCVKgFD3hMtIeY0XdJ1YviXBFVJH8/T5gI=";
};
2022-12-27 22:49:58 +01:00
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
# ClassiCube doesn't compile with its X11 backend
# because of issues with libXi.
./use-sdl.patch
# For some reason, the Makefile doesn't link
# with libcurl and openal when ClassiCube requires them.
# Also links with SDL2 instead of libX11 and libXi.
./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 = [ SDL2 libGL curl openal liberation_ttf ];
preBuild = "cd src";
postBuild = "cd -";
installPhase = ''
2022-12-22 16:18:26 +01:00
runHook preInstall
2023-01-07 04:02:28 +01:00
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"' \
2022-10-11 00:56:30 +02:00
--run 'cd "$HOME/.local/share/ClassiCube"'
2022-12-22 16:18:26 +01:00
2022-12-27 22:49:58 +01:00
mkdir -p "$out/share/icons/hicolor/256x256/apps"
cp misc/CCicon.png "$out/share/icons/hicolor/256x256/apps"
2023-01-07 04:02:28 +01:00
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 ];
};
}