27 , dedicatedServer ? false
31 latestVersionMajor = "0.2.9";
32 unstableVersionMajor = "0.4";
36 fetchArmagetron = rev: hash:
38 owner = "armagetronad";
39 repo = "armagetronad";
44 # https://gitlab.com/armagetronad/armagetronad/-/tags
45 ${latestVersionMajor} =
47 version = "${latestVersionMajor}.2.3";
49 hash = "sha256-lfYJ3luGK9hB0aiiBiJIqq5ddANqGaVtKXckbo4fl2g=";
52 src = fetchArmagetron rev hash;
53 extraBuildInputs = lib.optionals (!dedicatedServer) [ libpng SDL SDL_image SDL_mixer ];
56 # https://gitlab.com/armagetronad/armagetronad/-/commits/trunk/?ref_type=heads
57 ${unstableVersionMajor} =
59 rev = "391a74625c1222dd180f069f1b61c3e069a3ba8c";
60 hash = "sha256-fUY0dBj85k0QhnAoDzyBmmKmRh9oCYC6r6X4ukt7/L0=";
62 version = "${unstableVersionMajor}-${builtins.substring 0 8 rev}";
63 src = fetchArmagetron rev hash;
64 extraBuildInputs = [ protobuf boost ]
65 ++ lib.optionals (!dedicatedServer) [ glew ftgl freetype SDL2 SDL2_image SDL2_mixer ];
66 extraNativeBuildInputs = [ bison ];
69 # https://gitlab.com/armagetronad/armagetronad/-/commits/hack-0.2.8-sty+ct+ap/?ref_type=heads
70 "${latestVersionMajor}-sty+ct+ap" =
72 rev = "5a17cc9fb6e1e27a358711afbd745ae54d4a8c60";
73 hash = "sha256-111C1j/hSaASGcvYy3//TyHs4Z+3fuiOvCmtcWLdFd4=";
75 version = "${latestVersionMajor}-sty+ct+ap-${builtins.substring 0 8 rev}";
76 src = fetchArmagetron rev hash;
77 extraBuildInputs = lib.optionals (!dedicatedServer) [ libpng SDL SDL_image SDL_mixer ];
81 # Creates an Armagetron build. Takes a function returning build inputs for a particular value of dedicatedServer.
82 mkArmagetron = fn: dedicatedServer:
84 # Compute the build params.
85 resolvedParams = fn dedicatedServer;
87 # Figure out the binary name depending on whether this is a dedicated server.
88 mainProgram = if dedicatedServer then "armagetronad-dedicated" else "armagetronad";
90 # Split the version into the major and minor parts
91 versionParts = lib.splitString "-" resolvedParams.version;
92 splitVersion = lib.splitVersion (builtins.elemAt versionParts 0);
93 majorVersion = builtins.concatStringsSep "." (lib.lists.take 2 splitVersion);
95 minorVersionPart = parts: sep: expectedSize:
96 if builtins.length parts > expectedSize then
97 sep + (builtins.concatStringsSep sep (lib.lists.drop expectedSize parts))
101 minorVersion = (minorVersionPart splitVersion "." 2) + (minorVersionPart versionParts "-" 1) + "-nixpkgs";
103 stdenv.mkDerivation {
105 inherit (resolvedParams) version src;
107 # Build works fine; install has a race.
108 enableParallelBuilding = true;
109 enableParallelInstalling = false;
114 # Create the version.
115 echo "${majorVersion}" > major_version
116 echo "${minorVersion}" > minor_version
118 echo "Bootstrapping version: $(<major_version)$(<minor_version)" >&2
123 "--enable-automakedefaults"
124 "--enable-authentication"
125 "--disable-memmanager"
127 "--disable-initscripts"
129 "--disable-uninstall"
130 "--disable-sysinstall"
131 ] ++ lib.optional dedicatedServer "--enable-dedicated"
132 ++ lib.optional (!dedicatedServer) "--enable-music";
134 buildInputs = lib.singleton (libxml2.override { enableHttp = true; })
135 ++ (resolvedParams.extraBuildInputs or []);
137 nativeBuildInputs = [ autoconf automake gnum4 pkg-config which python3 ]
138 ++ (resolvedParams.extraNativeBuildInputs or []);
140 nativeInstallCheckInputs = [ gnugrep ]
141 ++ lib.optional (!dedicatedServer) xvfb-run
142 ++ (resolvedParams.extraNativeInstallCheckInputs or []);
144 postInstall = lib.optionalString (!dedicatedServer) ''
145 mkdir -p $out/share/{applications,icons/hicolor}
146 ln -s $out/share/games/armagetronad/desktop/armagetronad*.desktop $out/share/applications/
147 ln -s $out/share/games/armagetronad/desktop/icons $out/share/icons/hicolor
150 doInstallCheck = true;
152 installCheckPhase = ''
153 export XDG_RUNTIME_DIR=/tmp
154 bin="$out/bin/${mainProgram}"
155 if command -v xvfb-run &>/dev/null; then
160 echo "Checking game info:" >&2
161 version="$($run --version || true)"
162 echo " - Version: $version" >&2
163 prefix="$($run --prefix || true)"
164 echo " - Prefix: $prefix" >&2
165 rubber="$(($run --doc || true) | grep -m1 CYCLE_RUBBER)"
166 echo " - Docstring: $rubber" >&2
168 if [[ "$version" != *"${resolvedParams.version}"* ]] || \
169 [ "$prefix" != "$out" ] || \
170 [[ ! "$rubber" =~ ^CYCLE_RUBBER[[:space:]]+Niceness[[:space:]]factor ]]; then
171 echo "Something didn't match. :-(" >&2
174 echo "Everything is ok." >&2
179 if (dedicatedServer) then {
180 # No passthru, end of the line.
181 # https://www.youtube.com/watch?v=NOMa56y_Was
183 else if (resolvedParams.version != (srcs.${latestVersionMajor} dedicatedServer).version) then {
184 # Allow a "dedicated" passthru for versions other than the default.
185 dedicated = mkArmagetron fn true;
189 lib.mapAttrs (name: value: mkArmagetron value dedicatedServer)
190 (lib.filterAttrs (name: value: (value dedicatedServer).version != (srcs.${latestVersionMajor} dedicatedServer).version) srcs)
193 # Allow both a "dedicated" passthru and a passthru for all the options other than the latest version, which this is.
194 dedicated = mkArmagetron fn true;
195 tests.armagetronad = nixosTests.armagetronad;
200 homepage = "https://www.armagetronad.org";
201 description = "Multiplayer networked arcade racing game in 3D similar to Tron";
202 maintainers = with maintainers; [ numinit ];
203 license = licenses.gpl2Plus;
204 platforms = platforms.linux;
208 mkArmagetron srcs.${latestVersionMajor} dedicatedServer