nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 pkg-config,
6 SDL2,
7 libGLU,
8 libGL,
9 openal,
10 luajit,
11 lua5_1,
12 freetype,
13 physfs,
14 libmodplug,
15 mpg123,
16 libvorbis,
17 libogg,
18 libtheora,
19 which,
20 libtool,
21 libx11,
22 cmake,
23}:
24
25stdenv.mkDerivation rec {
26 pname = "love";
27 version = "11.5";
28
29 src = fetchFromGitHub {
30 owner = "love2d";
31 repo = "love";
32 rev = version;
33 sha256 = "sha256-wZktNh4UB3QH2wAIIlnYUlNoXbjEDwUmPnT4vesZNm0=";
34 };
35
36 nativeBuildInputs = [
37 pkg-config
38 cmake
39 ];
40 buildInputs = [
41 SDL2
42 openal
43 (if stdenv.isDarwin then lua5_1 else luajit)
44 freetype
45 physfs
46 libmodplug
47 mpg123
48 libvorbis
49 libogg
50 libtheora
51 which
52 libtool
53 ]
54 ++ lib.optionals stdenv.isLinux [
55 libx11 # SDL2 optional depend, for SDL_syswm.h
56 libGLU
57 libGL
58 ];
59
60 # Use CMake instead of autotools on all platforms for uniformity
61 # On Darwin, autotools doesn't compile macOS-specific module (src/common/macosx.mm),
62 # leading to stubbed functions and segfaults
63 cmakeFlags = [
64 "-DCMAKE_POLICY_VERSION_MINIMUM=3.5" # Required by LÖVE's CMakeLists.txt
65 "-DCMAKE_SKIP_BUILD_RPATH=ON" # Don't include build directory in RPATH
66 "-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON" # Use install RPATH even during build
67 ];
68
69 env.NIX_CFLAGS_COMPILE = "-DluaL_reg=luaL_Reg"; # needed since luajit-2.1.0-beta3
70
71 # CMake doesn't define install target for LÖVE, so install manually
72 installPhase = ''
73 runHook preInstall
74
75 mkdir -p $out/bin $out/lib
76 cp love $out/bin/
77 cp libliblove.* $out/lib/
78
79 # Install man page (both Linux and Darwin)
80 mkdir -p $out/share/man/man1
81 cp $src/platform/unix/love.6 $out/share/man/man1/love.1
82 gzip -9n $out/share/man/man1/love.1
83 ''
84 + lib.optionalString stdenv.isLinux ''
85 # Install Linux-specific files (desktop, mime, icons)
86 mkdir -p $out/share/applications
87 mkdir -p $out/share/mime/packages
88 mkdir -p $out/share/pixmaps
89 mkdir -p $out/share/icons/hicolor/scalable/mimetypes
90
91 # Generate desktop file from template
92 substitute $src/platform/unix/love.desktop.in $out/share/applications/love.desktop \
93 --replace-fail '@bindir@' "$out/bin"
94
95 cp $src/platform/unix/love.xml $out/share/mime/packages/
96 cp $src/platform/unix/love.svg $out/share/pixmaps/
97 cp $src/platform/unix/application-x-love-game.svg $out/share/icons/hicolor/scalable/mimetypes/
98 ''
99 + ''
100 runHook postInstall
101 '';
102
103 postFixup = lib.optionalString stdenv.isDarwin ''
104 # Fix rpath so love binary can find libliblove.dylib
105 install_name_tool -change "@rpath/libliblove.dylib" "$out/lib/libliblove.dylib" "$out/bin/love"
106 '';
107
108 meta = {
109 homepage = "https://love2d.org";
110 description = "Lua-based 2D game engine/scripting language";
111 mainProgram = "love";
112 license = lib.licenses.zlib;
113 platforms = lib.platforms.linux ++ lib.platforms.darwin;
114 maintainers = [ lib.maintainers.raskin ];
115 };
116}