1 { lib, stdenv, fetchurl, pkg-config, unzip, zlib, libpng, bzip2, SDL, SDL_mixer
2 , buildEnv, config, runtimeShell
6 # Choose your "paksets" of objects, images, text, music, etc.
7 paksets = config.simutrans.paksets or "pak64 pak64.japan pak128 pak128.britain pak128.german";
9 result = with lib; withPaks (
10 if paksets == "*" then attrValues pakSpec # taking all
11 else map (name: pakSpec.${name}) (splitString " " paksets)
17 version = "${ver1}.${ver2}${lib.optionalString (ver3 != "") ".${ver3}"}";
18 ver_dash = "${ver1}-${ver2}${lib.optionalString (ver3 != "") "-${ver3}"}";
20 binary_src = fetchurl {
21 url = "mirror://sourceforge/simutrans/simutrans/${ver_dash}/simutrans-src-${ver_dash}.zip";
22 sha256 = "1f463r6kr5ig0zd3mncc74k93xbjywsq3d06j5r17831jyc9bzb9";
26 # As of 2021/07, many of these paksets have not been updated for years, so are on old versions.
27 pakSpec = lib.mapAttrs
28 (pakName: attrs: mkPak (attrs // {inherit pakName;}))
31 srcPath = "${ver_dash}/simupak64-${ver_dash}";
32 sha256 = "1k335kh8dhm1hdn5iwn3sdgnrlpk0rqxmmgqgqcwsi09cmw45m5c";
35 # No release for 121.0 yet!
36 srcPath = "120-0/simupak64.japan-120-0-1";
37 sha256 = "14swy3h4ij74bgaw7scyvmivfb5fmp21nixmhlpk3mav3wr3167i";
41 srcPath = "pak128%20for%20ST%20120.4.1%20%282.8.1%2C%20priority%20signals%20%2B%20bugfix%29/pak128";
42 sha256 = "0z01y7r0rz7q79vr17bbnkgcbjjrimphy1dwb1pgbiv4klz7j5xw";
45 srcPath = "pak128.Britain%20for%20120-1/pak128.Britain.1.18-120-3";
46 sha256 = "1kyb0s54kysvdr0zdln9106yx75d71j4lbw3v87k3i440cj3r1d3";
48 "pak128.cs" = { # note: it needs pak128 to work
49 url = "mirror://sourceforge/simutrans/Pak128.CS/pak128.cz_v.0.2.1.zip";
50 sha256 = "008d8x1s0vxsq78rkczlnf57pv1n5hi1v5nbd1l5w3yls7lk11sc";
53 url = "mirror://sourceforge/simutrans/PAK128.german/"
54 + "pak128.german_1.2_for_ST_121.0/PAK128.german_1.2_for_ST_121-0.zip";
55 sha256 = "1cv1rzl1a3i5dvk476zq094wawk9hhdh2f0y4xrdny5gn17mb2xi";
58 /* This release contains accented filenames that prevent unzipping.
60 srcPath = "pak192comic%20for%20${ver2_dash}/pak192comic-0.4-${ver2_dash}up";
68 sha256, pakName, srcPath ? null
69 , url ? "mirror://sourceforge/simutrans/${pakName}/${srcPath}.zip"
72 name = "simutrans-${pakName}";
74 preferLocalBuild = true;
75 installPhase = let src = fetchurl { inherit url sha256; };
77 mkdir -p "$out/share/simutrans/${pakName}"
78 cd "$out/share/simutrans/${pakName}"
79 "${unzip}/bin/unzip" "${src}"
80 chmod -R +w . # some zipfiles need that
82 set +o pipefail # no idea why it's needed
83 toStrip=`find . -iname '*.pak' | head -n 1 | sed 's|\./\(.*\)/[^/]*$|\1|'`
84 echo "Detected path '$toStrip' to strip"
86 rm -f "$toStrip/.directory" #pak128.german had this
91 /* The binaries need all data in one directory; the default is directory
92 of the executable, and another option is the current directory :-/ */
93 withPaks = paks: buildEnv {
94 inherit (binaries) name;
95 paths = [binaries] ++ paks;
97 rm "$out/bin" && mkdir "$out/bin"
98 cat > "$out/bin/simutrans" <<EOF
100 cd "$out"/share/simutrans
101 exec "${binaries}/bin/simutrans" -use_workdir "\$@"
103 chmod +x "$out/bin/simutrans"
106 passthru.meta = binaries.meta // { hydraPlatforms = []; };
107 passthru.binaries = binaries;
110 binaries = stdenv.mkDerivation {
118 nativeBuildInputs = [ pkg-config unzip ];
119 buildInputs = [ zlib libpng bzip2 SDL SDL_mixer ];
122 # Configuration as per the readme.txt and config.template
124 if stdenv.isLinux then "linux" else
125 if stdenv.isDarwin then "mac" else throw "add your platform";
132 #TODO: MULTI_THREAD = 1 is "highly recommended",
133 # but it's roughly doubling CPU usage for me
135 echo "${config}" > config.default
137 # Use ~/.simutrans instead of ~/simutrans
138 substituteInPlace simsys.cc --replace '%s/simutrans' '%s/.simutrans'
140 # use -O2 optimization (defaults are -O or -O3)
141 sed -i -e '/CFLAGS += -O/d' Makefile
145 enableParallelBuilding = true;
149 mv simutrans $out/share/
152 mv build/default/sim $out/bin/simutrans
156 description = "A simulation game in which the player strives to run a successful transport system";
158 Simutrans is a cross-platform simulation game in which the
159 player strives to run a successful transport system by
160 transporting goods, passengers, and mail between
161 places. Simutrans is an open source remake of Transport Tycoon.
164 homepage = "http://www.simutrans.com/";
165 license = with licenses; [ artistic1 gpl1Plus ];
166 maintainers = with maintainers; [ ];
167 platforms = with platforms; linux; # TODO: ++ darwin;