2 # ./nix-build.sh -A xonotic
4 # for it in $(./nix-build.sh -A dockerImage --no-out-link); do docker load -i $it; done
8 cmake ? pkgs.cmake_2_8,
14 # https://gitlab.com/xonotic/xonotic
15 srcs."xonotic" = localFilesMain ./.;
16 vers."xonotic" = "${VERSION}";
18 srcs."data/font-dejavu" = localFiles ./data/font-dejavu.pk3dir;
19 vers."data/font-dejavu" = "xonotic-${VERSION}";
21 srcs."data/font-nimbussansl" = localFiles ./data/font-nimbussansl.pk3dir;
22 vers."data/font-nimbussansl" = "xonotic-${VERSION}";
24 srcs."data/font-unifont" = localFiles ./data/font-unifont.pk3dir;
25 vers."data/font-unifont" = "xonotic-${VERSION}";
27 srcs."data/font-xolonium" = localFiles ./data/font-xolonium.pk3dir;
28 vers."data/font-xolonium" = "xonotic-${VERSION}";
31 # https://gitlab.com/xonotic/d0_blind_id
32 srcs."d0_blind_id" = localFiles ./d0_blind_id;
33 vers."d0_blind_id" = "xonotic-${VERSION}";
36 # https://gitlab.com/xonotic/darkplaces
37 srcs."darkplaces" = localFiles ./darkplaces;
38 vers."darkplaces" = "xonotic-${VERSION}";
41 # https://gitlab.com/xonotic/gmqcc
42 srcs."gmqcc" = localFiles ./gmqcc;
43 vers."gmqcc" = "xonotic-${VERSION}";
46 # https://gitlab.com/xonotic/netradiant
47 srcs."netradiant" = localFiles ./netradiant;
48 vers."netradiant" = "xonotic-${VERSION}";
51 # https://gitlab.com/xonotic/xonotic-data.pk3dir
52 srcs."data/xonotic-data" = localFilesCustom ./data/xonotic-data.pk3dir (name: type: type == "directory" || !(isCode name));
53 vers."data/xonotic-data" = builtins.getEnv "VERSION_data_xonotic_data_pk3dir";
55 srcs."data/xonotic-data/qcsrc" = localFilesCustom ./data/xonotic-data.pk3dir (name: type: type == "directory" || (isCode name));
56 vers."data/xonotic-data/qcsrc" = vers."data/xonotic-data";
59 # https://gitlab.com/xonotic/xonotic-maps.pk3dir
60 srcs."data/xonotic-maps" = localFiles ./data/xonotic-maps.pk3dir;
61 vers."data/xonotic-maps" = "${VERSION}";
63 # https://gitlab.com/xonotic/xonotic-music.pk3dir
64 srcs."data/xonotic-music" = localFiles ./data/xonotic-music.pk3dir;
65 vers."data/xonotic-music" = "${VERSION}";
67 # https://gitlab.com/xonotic/xonotic-nexcompat.pk3dir
68 srcs."data/xonotic-nexcompat" = localFiles ./data/xonotic-nexcompat.pk3dir;
69 vers."data/xonotic-nexcompat" = "${VERSION}";
71 inherit (x) srcs vers;
73 localFilesMain = src: let
74 project = toString ./.;
75 cleanSourceFilterMain = name: type: let
76 baseName = baseNameOf (toString name);
77 result = (cleanSourceFilter name type)
78 && !(name == "${project}/release")
79 && !(name == "${project}/d0_blind_id")
80 && !(name == "${project}/daemon")
81 && !(name == "${project}/darkplaces")
82 && !(name == "${project}/data")
83 && !(name == "${project}/gmqcc")
84 && !(name == "${project}/netradiant")
85 && !(name == "${project}/wiki" || name == "${project}/wiki.yes")
86 && !(name == "${project}/xonstat" || name == "${project}/xonstat.yes")
89 in builtins.filterSource cleanSourceFilterMain src;
92 baseName = baseNameOf (toString name);
94 || (lib.hasSuffix ".ase" baseName)
95 || (lib.hasSuffix ".dem" baseName)
96 || (lib.hasSuffix ".dpm" baseName)
97 || (lib.hasSuffix ".framegroups" baseName)
98 || (lib.hasSuffix ".iqm" baseName)
99 || (lib.hasSuffix ".jpg" baseName)
100 || (lib.hasSuffix ".lmp" baseName)
101 || (lib.hasSuffix ".md3" baseName)
102 || (lib.hasSuffix ".mdl" baseName)
103 || (lib.hasSuffix ".obj" baseName)
104 || (lib.hasSuffix ".ogg" baseName)
105 || (lib.hasSuffix ".png" baseName)
106 || (lib.hasSuffix ".shader" baseName)
107 || (lib.hasSuffix ".skin" baseName)
108 || (lib.hasSuffix ".sounds" baseName)
109 || (lib.hasSuffix ".sp2" baseName)
110 || (lib.hasSuffix ".spr" baseName)
111 || (lib.hasSuffix ".spr32" baseName)
112 || (lib.hasSuffix ".svg" baseName)
113 || (lib.hasSuffix ".tga" baseName)
114 || (lib.hasSuffix ".wav" baseName)
115 || (lib.hasSuffix ".width" baseName)
116 || (lib.hasSuffix ".zym" baseName)
120 pk3 = drv: mkDerivation {
121 name = "${drv.name}.pk3";
122 version = drv.version;
124 nativeBuildInputs = with pkgs; [
128 phases = [ "installPhase" ];
130 (cd ${drv} && zip -r ${drv.pk3args or ""} $out .)
135 font-dejavu = mkDerivation rec {
136 name = "font-dejavu-${version}";
137 version = vers."data/font-dejavu";
139 src = srcs."data/font-dejavu";
141 phases = [ "installPhase" ];
147 font-nimbussansl = mkDerivation rec {
148 name = "font-nimbussansl-${version}";
149 version = vers."data/font-nimbussansl";
151 src = srcs."data/font-nimbussansl";
153 phases = [ "installPhase" ];
159 font-unifont = mkDerivation rec {
160 name = "font-unifont-${version}";
161 version = vers."data/font-unifont";
163 src = srcs."data/font-unifont";
165 phases = [ "installPhase" ];
171 font-xolonium = mkDerivation rec {
172 name = "font-xolonium-${version}";
173 version = vers."data/font-xolonium";
175 src = srcs."data/font-xolonium";
177 phases = [ "installPhase" ];
183 d0_blind_id = mkDerivation rec {
184 name = "d0_blind_id-${version}";
185 version = vers."d0_blind_id";
187 src = srcs."d0_blind_id";
189 nativeBuildInputs = [
193 buildInputs = with pkgs; [
199 mkdir -p $out/include/d0_blind_id
201 cp libd0_blind_id.so $out/lib
202 (cd $src; cp d0.h d0_blind_id.h $out/include/d0_blind_id)
204 cp libd0_rijndael.so $out/lib
205 (cd $src; cp d0_rijndael.h $out/include/d0_blind_id)
210 unwrapped = mkDerivation rec {
211 name = "darkplaces-unwrapped-${version}";
212 version = vers."darkplaces";
214 src = srcs."darkplaces";
216 nativeBuildInputs = [
220 buildInputs = with pkgs; [
229 cp darkplaces-{dedicated,sdl} $out/bin
232 result = mkDerivation rec {
233 name = "darkplaces-${version}";
234 version = vers."darkplaces";
236 buildInputs = unwrapped.buildInputs ++ runtimeInputs;
237 runtimeInputs = with pkgs; [
253 phases = [ "installPhase" ];
257 cp -r ${unwrapped}/bin .
261 for exe in dedicated sdl; do
263 rpath=$(patchelf --print-rpath $f)
264 rpath=''${rpath:+$rpath:}${lib.makeLibraryPath runtimeInputs}
265 patchelf --set-rpath $rpath $f
266 cp $f $out/bin/xonotic-linux64-$exe
272 gmqcc = mkDerivation rec {
273 name = "gmqcc-${version}";
274 version = vers."gmqcc";
278 nativeBuildInputs = [
288 netradiant = mkDerivation rec {
289 name = "netradiant-${version}";
290 version = vers."netradiant";
292 src = srcs."netradiant";
294 nativeBuildInputs = with pkgs; [
299 buildInputs = with pkgs; [
324 xonotic-data = mkDerivation rec {
325 name = "xonotic-data-${version}";
326 version = vers."data/xonotic-data";
328 src = srcs."data/xonotic-data";
330 phases = [ "installPhase" ];
335 find $out -depth -type d -empty -exec rmdir {} \;
339 xonotic-data-code = mkDerivation rec {
340 name = "xonotic-data-code-${version}";
341 version = vers."data/xonotic-data/qcsrc";
343 src = srcs."data/xonotic-data/qcsrc";
346 QCC = "${gmqcc}/bin/gmqcc";
350 nativeBuildInputs = with pkgs; [
359 cp {menu,progs,csprogs}.{dat,lno} $out
360 cp csprogs-${version}.{dat,lno,txt} $out/.tmp
361 find $out -depth -type d -empty -exec rmdir {} \;
364 passthru.csprogs = pkgs.runCommand "xonotic-data-csprogs-${version}" { inherit version; pk3name = "csprogs-${version}"; } ''
366 cp ${xonotic-data-code}/.tmp/csprogs-${version}.{dat,lno,txt} $out
371 xonotic-maps = mkDerivation rec {
372 name = "xonotic-maps-${version}";
373 version = vers."data/xonotic-maps";
375 src = srcs."data/xonotic-maps";
377 phases = [ "installPhase" ];
383 passthru.dance = mkDerivation rec {
385 version = vers."data/xonotic-maps";
387 src = pkgs.fetchurl {
388 url = http://beta.xonotic.org/autobuild-bsp/dance-full-88c416b8c11bdcecfdb889af2a2b97b4c0e2b8de-319ee7234504199da56f07ce25185f6d6cb889cd.pk3;
389 sha256 = "1jgdg4mz56kbxcy3mwn4h5qlf3ahm1cmarp9l70fz9nfn6cnaknq";
392 phases = [ "installPhase" ];
397 ${pkgs.unzip}/bin/unzip $src
402 xonotic-music = mkDerivation rec {
403 name = "xonotic-music-${version}";
404 version = vers."data/xonotic-music";
406 src = srcs."data/xonotic-music";
408 phases = [ "installPhase" ];
414 passthru.pk3args = "-0";
417 xonotic-nexcompat = mkDerivation rec {
418 name = "xonotic-nexcompat-${version}";
419 version = vers."data/xonotic-nexcompat";
421 src = srcs."data/xonotic-nexcompat";
423 phases = [ "installPhase" ];
430 xonotic-keys = mkDerivation rec {
431 name = "xonotic-keys-${version}";
432 version = vers."xonotic";
434 src = srcs."xonotic";
436 phases = [ "installPhase" ];
444 xonotic = mkDerivation rec {
445 name = "xonotic-${version}";
446 version = vers."xonotic";
448 src = srcs."xonotic";
466 xonotic-data-csprogs = xonotic-data-code.passthru.csprogs;
467 inherit (xonotic-maps)
472 phases = [ "installPhase" ];
477 cp ${darkplaces}/bin/* $out
480 ${lib.concatStringsSep "\n" (lib.mapAttrsToList (k: v:
481 # "cp ${pk3 v} $out/data/${k}.pk3"
482 "ln -s ${v} $out/data/${k}.pk3dir"
485 mkdir -p $out/mapping
486 ln -s ${netradiant} $out/mapping/${netradiant.name}
491 main = pkgs.dockerTools.buildImage {
494 contents = mkDerivation {
495 name = "xonotic-init";
496 phases = [ "installPhase" ];
499 cat > $out/init <<EOF
501 ${pkgs.coreutils}/bin/ln -s ${xonotic-keys}/* /
503 ${pkgs.coreutils}/bin/ls -l /
504 ${pkgs.coreutils}/bin/ls -l /data
506 exec ${darkplaces}/bin/xonotic-linux64-dedicated "\''${@}"
511 config.Entrypoint = "/init";
513 unpackImage = { name, from, to }: pkgs.dockerTools.buildImage {
514 name = "xonotic_${name}";
516 contents = mkDerivation {
517 name = "xonotic-${name}-init";
518 phases = [ "installPhase" ];
521 cat > $out/init <<EOF
523 ${pkgs.coreutils}/bin/cp -r ${from} /data/${to}
528 config.Entrypoint = "/init";
529 fromImage = pkgs.dockerTools.buildImage {
530 name = "xonotic_deps";
531 contents = mkDerivation {
532 name = "xonotic_deps";
533 phases = [ "installPhase" ];
536 cat > $out/init <<EOF
545 // (lib.mapAttrs (k: v: unpackImage { name = k; from = pk3 v; to = "${v.pk3name or k}.pk3"; }) xonotic.paks)
549 cleanSourceFilter = name: type: let
550 baseName = baseNameOf (toString name);
551 result = (lib.cleanSourceFilter name type)
552 && !(lib.hasSuffix ".nix" baseName)
553 && !(type == "directory" && baseName == ".git")
554 && !(type == "directory" && baseName == ".idea")
555 && !(type == "directory" && (lib.hasPrefix "cmake-build-" baseName))
559 localFilesCustom = src: filter:
560 builtins.filterSource (name: type: (cleanSourceFilter name type) && (filter name type)) src
563 localFiles = src: localFilesCustom src (name: type: true);
565 stdenv = if (cc == null) then pkgs.stdenv
566 else pkgs.overrideCC pkgs.stdenv pkgs."${cc}";
568 mkDerivation = {env ? {}, shellHook ? "", runtimeInputs ? [], ...}@args: stdenv.mkDerivation ({}
569 // { enableParallelBuilding = true; }
570 // (removeAttrs args ["env" "shellHook" "runtimeInputs"])
575 ${lib.concatStringsSep "\n" (lib.mapAttrsToList (n: v: "export ${n}=${v}") env)}
576 export LD_LIBRARY_PATH=''${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${lib.makeLibraryPath runtimeInputs}
581 shell = let inputs = (lib.mapAttrsToList (k: v: v) targets); in stdenv.mkDerivation (rec {
582 name = "xonotic-shell";
583 nativeBuildInputs = builtins.map (it: it.nativeBuildInputs) (builtins.filter (it: it?nativeBuildInputs) inputs);
584 buildInputs = builtins.map (it: it.buildInputs) (builtins.filter (it: it?buildInputs) inputs);
585 shellHook = builtins.map (it: it.shellHook) (builtins.filter (it: it?shellHook) inputs);
587 in { inherit shell; } // targets