Add nix-shell environment
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 16 Jul 2017 04:54:54 +0000 (14:54 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 16 Jul 2017 04:54:54 +0000 (14:54 +1000)
.gitignore
CMakeLists.txt
default.nix [new file with mode: 0644]

index 0a76101..ab43afb 100644 (file)
@@ -15,3 +15,4 @@
 /wiki
 
 .idea/
+/result*
index e5f53a2..704c543 100644 (file)
@@ -4,18 +4,18 @@ project(xonotic)
 option(DOWNLOAD_MAPS "Download new maps from the build server" ON)
 option(BUILD_RELEASE "Package a release" OFF)
 
-macro(subproject name)
-    if (EXISTS "${PROJECT_SOURCE_DIR}/${name}/CMakeLists.txt")
+macro(subproject id name)
+    if (EXISTS "${PROJECT_SOURCE_DIR}/${name}/CMakeLists.txt" AND NOT DEFINED ENV{XON_NO_${id}})
         add_subdirectory(${name} ${ARGN})
     endif ()
 endmacro()
 
-subproject(daemon)
-subproject(d0_blind_id)
-subproject(darkplaces)
-subproject(data/xonotic-data.pk3dir)
-subproject(gmqcc)
-subproject(netradiant)
+subproject(DAEMON  daemon)
+subproject(PKI     d0_blind_id)
+subproject(DP      darkplaces)
+subproject(DATA    data/xonotic-data.pk3dir)
+subproject(QCC     gmqcc)
+subproject(RADIANT netradiant)
 
 if (DOWNLOAD_MAPS)
     add_custom_target(update-maps ALL
diff --git a/default.nix b/default.nix
new file mode 100644 (file)
index 0000000..d4d1021
--- /dev/null
@@ -0,0 +1,96 @@
+# nix-shell -A xonotic
+{
+    nixpkgs ? <nixpkgs>,
+    pkgs ? (import nixpkgs) {}
+}:
+with pkgs;
+let
+    VERSION = "0.8.2";
+    targets = rec {
+        xonotic = stdenv.mkDerivation rec {
+
+            XON_NO_DAEMON = true;
+            XON_NO_RADIANT = true;
+
+            XON_NO_QCC = true;
+            QCC = "${gmqcc}/gmqcc";
+
+            version = VERSION;
+
+            name = "xonotic-${version}";
+
+            src = lib.sourceFilesBySuffices ./. [
+                ".txt" ".cmake" ".in"
+                ".c" ".cpp" ".h"
+                ".inc" ".def"
+                ".qc" ".qh"
+                ".sh"
+            ];
+
+            enableParallelBuilding = true;
+
+            cmakeFlags = [
+                "-DDOWNLOAD_MAPS=0"
+            ];
+
+            nativeBuildInputs = [
+                cmake   # for building
+                git     # for versioning
+                # unzip # for downloading maps
+            ];
+
+            buildInputs = [
+                openssl # for d0_blind_id
+                SDL2    # for darkplaces
+            ];
+
+            runtimeInputs = [
+                zlib
+                curl
+
+                libjpeg
+                libpng
+
+                freetype
+
+                libogg
+                libtheora
+                libvorbis
+            ];
+
+            shellHook = ''
+                export LD_LIBRARY_PATH=''${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${lib.makeLibraryPath runtimeInputs}
+            '';
+
+            installPhase = ''
+                mkdir $out
+
+                exe=darkplaces/darkplaces
+                rpath=$(patchelf --print-rpath $exe)
+                rpath_firstparty=$out/d0_blind_id
+                rpath_thirdparty=${lib.makeLibraryPath runtimeInputs}
+                rpath=''${rpath:+$rpath:}$rpath_firstparty:$rpath_thirdparty
+                patchelf --set-rpath $rpath $exe
+
+                cp -r . $out
+            '';
+
+            dontPatchELF = true;
+        };
+
+        gmqcc = stdenv.mkDerivation rec {
+            version = "xonotic-${VERSION}";
+
+            name = "gmqcc-${version}";
+
+            src = ./gmqcc;
+
+            enableParallelBuilding = true;
+
+            installPhase = ''
+                mkdir $out
+                cp -r . $out
+            '';
+        };
+    };
+in targets