Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 262 lines 6.9 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchurl, 5 fetchzip, 6 makeWrapper, 7 runCommand, 8 makeDesktopItem, 9 xonotic-data, 10 copyDesktopItems, 11 # required for both 12 unzip, 13 libjpeg, 14 zlib, 15 libvorbis, 16 curl, 17 freetype, 18 libpng, 19 libtheora, 20 libX11, 21 # glx 22 libGLU, 23 libGL, 24 libXpm, 25 libXext, 26 libXxf86vm, 27 alsa-lib, 28 # sdl 29 SDL2, 30 # blind 31 gmp, 32 33 withSDL ? true, 34 withGLX ? false, 35 withDedicated ? true, 36}: 37 38let 39 pname = "xonotic"; 40 version = "0.8.6"; 41 name = "${pname}-${version}"; 42 variant = 43 if withSDL && withGLX then 44 "" 45 else if withSDL then 46 "-sdl" 47 else if withGLX then 48 "-glx" 49 else if withDedicated then 50 "-dedicated" 51 else 52 "-what-even-am-i"; 53 54 meta = { 55 description = "Free fast-paced first-person shooter"; 56 longDescription = '' 57 Xonotic is a free, fast-paced first-person shooter that works on 58 Windows, macOS and Linux. The project is geared towards providing 59 addictive arena shooter gameplay which is all spawned and driven 60 by the community itself. Xonotic is a direct successor of the 61 Nexuiz project with years of development between them, and it 62 aims to become the best possible open-source FPS of its kind. 63 ''; 64 homepage = "https://www.xonotic.org/"; 65 license = lib.licenses.gpl2Plus; 66 maintainers = with lib.maintainers; [ 67 zalakain 68 ]; 69 platforms = lib.platforms.linux; 70 }; 71 72 desktopItem = makeDesktopItem { 73 name = "xonotic"; 74 exec = "xonotic"; 75 comment = meta.description; 76 desktopName = "Xonotic"; 77 categories = [ 78 "Game" 79 "Shooter" 80 ]; 81 icon = "xonotic"; 82 startupNotify = false; 83 }; 84 85 xonotic-unwrapped = stdenv.mkDerivation rec { 86 pname = "xonotic${variant}-unwrapped"; 87 inherit version; 88 89 src = fetchurl { 90 url = "https://dl.xonotic.org/xonotic-${version}-source.zip"; 91 hash = "sha256-i5KseBz/SuicEhoj6s197AWiqr7azMI6GdGglYtAEqg="; 92 }; 93 94 nativeBuildInputs = [ unzip ]; 95 buildInputs = [ 96 libjpeg 97 zlib 98 libvorbis 99 curl 100 gmp 101 libX11 102 ] 103 ++ lib.optionals withGLX [ 104 libGLU 105 libGL 106 libXpm 107 libXext 108 libXxf86vm 109 alsa-lib 110 ] 111 ++ lib.optionals withSDL [ SDL2 ]; 112 113 sourceRoot = "Xonotic/source/darkplaces"; 114 115 # "debug", "release", "profile" 116 target = "release"; 117 118 dontStrip = target != "release"; 119 120 postConfigure = '' 121 pushd ../d0_blind_id 122 ./configure $configureFlags 123 popd 124 ''; 125 126 buildPhase = 127 ( 128 lib.optionalString withDedicated '' 129 make -j $NIX_BUILD_CORES sv-${target} 130 '' 131 + lib.optionalString withGLX '' 132 make -j $NIX_BUILD_CORES cl-${target} 133 '' 134 + lib.optionalString withSDL '' 135 make -j $NIX_BUILD_CORES sdl-${target} 136 '' 137 ) 138 + '' 139 pushd ../d0_blind_id 140 make -j $NIX_BUILD_CORES 141 popd 142 ''; 143 144 enableParallelBuilding = true; 145 146 installPhase = 147 ( 148 '' 149 install -Dm644 ../../misc/logos/xonotic_icon.svg \ 150 $out/share/icons/hicolor/scalable/apps/xonotic.svg 151 pushd ../../misc/logos/icons_png 152 for img in *.png; do 153 size=''${img#xonotic_} 154 size=''${size%.png} 155 dimensions="''${size}x''${size}" 156 install -Dm644 $img \ 157 $out/share/icons/hicolor/$dimensions/apps/xonotic.png 158 done 159 popd 160 '' 161 + lib.optionalString withDedicated '' 162 install -Dm755 darkplaces-dedicated "$out/bin/xonotic-dedicated" 163 '' 164 + lib.optionalString withGLX '' 165 install -Dm755 darkplaces-glx "$out/bin/xonotic-glx" 166 '' 167 + lib.optionalString withSDL '' 168 install -Dm755 darkplaces-sdl "$out/bin/xonotic-sdl" 169 '' 170 ) 171 + '' 172 pushd ../d0_blind_id 173 make install 174 popd 175 ''; 176 177 # Xonotic needs to find libcurl.so at runtime for map downloads 178 dontPatchELF = true; 179 postFixup = 180 lib.optionalString withDedicated '' 181 patchelf --add-needed ${curl.out}/lib/libcurl.so $out/bin/xonotic-dedicated 182 '' 183 + lib.optionalString withGLX '' 184 patchelf \ 185 --add-needed ${curl.out}/lib/libcurl.so \ 186 --add-needed ${libvorbis}/lib/libvorbisfile.so \ 187 --add-needed ${libvorbis}/lib/libvorbisenc.so \ 188 --add-needed ${libvorbis}/lib/libvorbis.so \ 189 --add-needed ${libGL.out}/lib/libGL.so \ 190 --add-needed ${freetype}/lib/libfreetype.so \ 191 --add-needed ${libpng}/lib/libpng.so \ 192 --add-needed ${libtheora}/lib/libtheora.so \ 193 $out/bin/xonotic-glx 194 '' 195 + lib.optionalString withSDL '' 196 patchelf \ 197 --add-needed ${curl.out}/lib/libcurl.so \ 198 --add-needed ${libvorbis}/lib/libvorbisfile.so \ 199 --add-needed ${libvorbis}/lib/libvorbisenc.so \ 200 --add-needed ${libvorbis}/lib/libvorbis.so \ 201 --add-needed ${freetype}/lib/libfreetype.so \ 202 --add-needed ${libpng}/lib/libpng.so \ 203 --add-needed ${libtheora}/lib/libtheora.so \ 204 $out/bin/xonotic-sdl 205 ''; 206 }; 207 208in 209rec { 210 xonotic-data = fetchzip { 211 name = "xonotic-data"; 212 url = "https://dl.xonotic.org/xonotic-${version}.zip"; 213 hash = "sha256-Lhjpyk7idmfQAVn4YUb7diGyyKZQBfwNXxk2zMOqiZQ="; 214 postFetch = '' 215 cd $out 216 rm -rf $(ls | grep -v "^data$" | grep -v "^key_0.d0pk$") 217 ''; 218 meta.hydraPlatforms = [ ]; 219 inherit version pname; 220 }; 221 222 xonotic = 223 runCommand "xonotic${variant}-${version}" 224 { 225 inherit xonotic-unwrapped version; 226 pname = "${pname}${variant}"; 227 nativeBuildInputs = [ 228 makeWrapper 229 copyDesktopItems 230 ]; 231 desktopItems = [ desktopItem ]; 232 meta = meta // { 233 hydraPlatforms = [ ]; 234 }; 235 } 236 ( 237 '' 238 mkdir -p $out/bin 239 '' 240 + lib.optionalString withDedicated '' 241 ln -s ${xonotic-unwrapped}/bin/xonotic-dedicated $out/bin/ 242 '' 243 + lib.optionalString withGLX '' 244 ln -s ${xonotic-unwrapped}/bin/xonotic-glx $out/bin/xonotic-glx 245 ln -s $out/bin/xonotic-glx $out/bin/xonotic 246 '' 247 + lib.optionalString withSDL '' 248 ln -s ${xonotic-unwrapped}/bin/xonotic-sdl $out/bin/xonotic-sdl 249 ln -sf $out/bin/xonotic-sdl $out/bin/xonotic 250 '' 251 + lib.optionalString (withSDL || withGLX) '' 252 mkdir -p $out/share 253 ln -s ${xonotic-unwrapped}/share/icons $out/share/icons 254 copyDesktopItems 255 '' 256 + '' 257 for binary in $out/bin/xonotic-*; do 258 wrapProgram $binary --add-flags "-basedir ${xonotic-data}" --prefix LD_LIBRARY_PATH : "${xonotic-unwrapped}/lib" 259 done 260 '' 261 ); 262}