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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
{ lib
, stdenv
, cmake
, pkg-config
, python3
, rake
, curl
, fetchFromGitHub
, libGL
, libGLU
, alsa-lib
, libX11
, libICE
, libXi
, libXScrnSaver
, libXcursor
, libXinerama
, libXext
, libXxf86vm
, libXrandr
, libxkbcommon
, wayland
, wayland-protocols
, wayland-scanner
, dbus
, udev
, libdecor
, pipewire
, libpulseaudio
# Whether to build TIC-80's "Pro" version, which is an incentive to support the project financially,
# that enables some additional features. It is, however, fully open source.
, withPro ? false
}:
let
major = "1";
minor = "1";
revision = "2837";
year = "2023";
in
stdenv.mkDerivation rec {
pname = "tic-80";
version = "${major}.${minor}.${revision}";
src = fetchFromGitHub {
owner = "nesbox";
repo = "TIC-80";
rev = "v" + version;
hash = "sha256-p7OyuD/4KxAzylQDlXW681TvEZwKYDD4zq2KDRkcv48=";
# TIC-80 vendors its dependencies as submodules, so to use its current build system,
# we need to fetch them. Managing the dependencies ourselves would require a lot of
# changes in the build system, which doesn't seem worth it right now. In future versions,
# TIC-80 is switching to more modular CMake files, at which point we can reconsider.
fetchSubmodules = true;
};
# TIC-80 tries to determine the revision part of the version using its Git history.
# Because using leaveDotGit tends be non-reproducible with submodules, we just
# hardcode it.
# To avoid the awkward copyright range of "2017-1980", which would be caused by the
# sandbox environment, hardcode the year of the release.
postPatch = ''
substituteInPlace CMakeLists.txt \
--replace-fail 'set(VERSION_REVISION 0)' 'set(VERSION_REVISION ${revision})' \
--replace-fail 'string(TIMESTAMP VERSION_YEAR "%Y")' 'set(VERSION_YEAR "${year}")'
'';
# Taken from pkgs/development/compilers/mruby; necessary so it uses `gcc` instead of `ld` for linking.
# https://github.com/mruby/mruby/blob/e502fd88b988b0a8d9f31b928eb322eae269c45a/tasks/toolchains/gcc.rake#L30
preBuild = ''
unset LD
'';
cmakeFlags = lib.optionals withPro [ "-DBUILD_PRO=On" ] ++ [ "-DBUILD_SDLGPU=On" ];
nativeBuildInputs = [
cmake
curl
pkg-config
python3
rake
];
buildInputs = [
alsa-lib
dbus
libdecor
libGL
libGLU
libICE
libpulseaudio
libX11
libXcursor
libXext
libXi
libXinerama
libxkbcommon
libXrandr
libXScrnSaver
libXxf86vm
pipewire
udev
wayland
wayland-protocols
wayland-scanner
];
# This package borrows heavily from pkgs/development/libraries/SDL2/default.nix
# because TIC-80 vendors SDL2, which means we need to take care and implement
# a similar environment in TIC-80's vendored copy of SDL2.
#
# SDL is weird in that instead of just dynamically linking with
# libraries when you `--enable-*` (or when `configure` finds) them
# it `dlopen`s them at runtime. In principle, this means it can
# ignore any missing optional dependencies like alsa, pulseaudio,
# some x11 libs, wayland, etc if they are missing on the system
# and/or work with wide array of versions of said libraries. In
# nixpkgs, however, we don't need any of that. Moreover, since we
# don't have a global ld-cache we have to stuff all the propagated
# libraries into rpath by hand or else some applications that use
# SDL API that requires said libraries will fail to start.
#
# You can grep SDL sources with `grep -rE 'SDL_(NAME|.*_SYM)'` to
# list the symbols used in this way.
postFixup =
let
rpath = lib.makeLibraryPath buildInputs;
in
''
patchelf --set-rpath "$(patchelf --print-rpath $out/bin/tic80):${rpath}" "$out/bin/tic80"
'';
meta = with lib; {
description =
"A free and open source fantasy computer for making, playing and sharing tiny games";
longDescription = ''
TIC-80 is a free and open source fantasy computer for making, playing and
sharing tiny games.
There are built-in tools for development: code, sprites, maps, sound
editors and the command line, which is enough to create a mini retro
game. At the exit you will get a cartridge file, which can be stored and
played on the website.
Also, the game can be packed into a player that works on all popular
platforms and distribute as you wish. To make a retro styled game the
whole process of creation takes place under some technical limitations:
240x136 pixels display, 16 color palette, 256 8x8 color sprites, 4
channel sound and etc.
'';
homepage = "https://github.com/nesbox/TIC-80";
license = licenses.mit;
platforms = platforms.linux;
mainProgram = "tic80";
maintainers = with maintainers; [ blinry ];
};
}
|