]> git.xonotic.org Git - xonotic/xonotic.git/blobdiff - default.nix
rename all the configs
[xonotic/xonotic.git] / default.nix
index d4d10211e692af99ee9ab3f2a010a9c85302ae62..4ee0c65ae485af1edf9d9cb4b3429f231ea6d5d2 100644 (file)
@@ -1,23 +1,18 @@
-# nix-shell -A xonotic
+# nix-shell -A shell
+# --argstr cc clang
 {
     nixpkgs ? <nixpkgs>,
-    pkgs ? (import nixpkgs) {}
+    pkgs ? (import nixpkgs) {},
+    cc ? null
 }:
 with pkgs;
 let
     VERSION = "0.8.2";
+    cmake = pkgs.cmake_2_8;
     targets = rec {
-        xonotic = stdenv.mkDerivation rec {
-
-            XON_NO_DAEMON = true;
-            XON_NO_RADIANT = true;
-
-            XON_NO_QCC = true;
-            QCC = "${gmqcc}/gmqcc";
-
-            version = VERSION;
-
+        xonotic = mkDerivation { pki = true; dp = true; data = true; } rec {
             name = "xonotic-${version}";
+            version = VERSION;
 
             src = lib.sourceFilesBySuffices ./. [
                 ".txt" ".cmake" ".in"
@@ -27,11 +22,9 @@ let
                 ".sh"
             ];
 
-            enableParallelBuilding = true;
-
-            cmakeFlags = [
-                "-DDOWNLOAD_MAPS=0"
-            ];
+            env = {
+                QCC = "${gmqcc}/bin/gmqcc";
+            };
 
             nativeBuildInputs = [
                 cmake   # for building
@@ -39,6 +32,10 @@ let
                 # unzip # for downloading maps
             ];
 
+            cmakeFlags = [
+                "-DDOWNLOAD_MAPS=0"
+            ];
+
             buildInputs = [
                 openssl # for d0_blind_id
                 SDL2    # for darkplaces
@@ -58,10 +55,6 @@ let
                 libvorbis
             ];
 
-            shellHook = ''
-                export LD_LIBRARY_PATH=''${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${lib.makeLibraryPath runtimeInputs}
-            '';
-
             installPhase = ''
                 mkdir $out
 
@@ -78,19 +71,85 @@ let
             dontPatchELF = true;
         };
 
-        gmqcc = stdenv.mkDerivation rec {
-            version = "xonotic-${VERSION}";
-
+        gmqcc = mkDerivation { qcc = true; } rec {
             name = "gmqcc-${version}";
+            version = "xonotic-${VERSION}";
 
             src = ./gmqcc;
 
-            enableParallelBuilding = true;
-
             installPhase = ''
-                mkdir $out
-                cp -r . $out
+                mkdir -p $out/bin
+                cp gmqcc $out/bin
             '';
         };
+
+        netradiant = mkDerivation { radiant = true; } rec {
+            name = "netradiant-${version}";
+            version = VERSION;
+
+            src = ./netradiant;
+
+            nativeBuildInputs = [
+                cmake   # for building
+                git     # for versioning
+            ];
+
+            cmakeFlags = [
+                "-DDOWNLOAD_MAPS=0"
+            ];
+
+            buildInputs = [
+                pkgconfig
+                glib
+                pcre
+                libxml2
+                ncurses
+                libjpeg
+                libpng
+                minizip
+
+                mesa
+
+                xorg.libXt
+                xorg.libXmu
+                xorg.libSM
+                xorg.libICE
+                xorg.libpthreadstubs
+                xorg.libXdmcp
+
+                gnome3.gtk
+                gnome2.gtk
+                gnome2.gtkglext
+            ];
+        };
+    };
+    stdenv = if (cc != null) then overrideCC pkgs.stdenv pkgs."${cc}" else pkgs.stdenv;
+    mkEnableTargets = args: {
+        XON_NO_PKI = !args?pki;
+        XON_NO_DP = !args?dp;
+        XON_NO_DATA = !args?data;
+        XON_NO_QCC = !args?qcc;
+        XON_NO_RADIANT = !args?radiant;
     };
-in targets
+    mkDerivation = targets: {env ? {}, shellHook ? "", runtimeInputs ? [], ...}@args:
+        stdenv.mkDerivation (
+            (mkEnableTargets targets)
+            // { enableParallelBuilding = true; }
+            // (removeAttrs args ["env" "shellHook" "runtimeInputs"])  # passthru
+            // env
+            // {
+                shellHook = ''
+                    ${shellHook}
+                    ${lib.concatStringsSep "\n" (lib.mapAttrsToList (n: v: "export ${n}=${v}") env)}
+                    export LD_LIBRARY_PATH=''${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${lib.makeLibraryPath runtimeInputs}
+                '';
+            }
+        );
+    shell = let inputs = (lib.mapAttrsToList (n: v: v) targets); in stdenv.mkDerivation (rec {
+        name = "xon-shell";
+        XON_NO_DAEMON = true;
+        nativeBuildInputs = builtins.map (it: it.nativeBuildInputs) inputs;
+        buildInputs = builtins.map (it: it.buildInputs) inputs;
+        shellHook = builtins.map (it: it.shellHook) (builtins.filter (it: it?shellHook) inputs);
+    });
+in { inherit shell; } // targets