option(DOWNLOAD_MAPS "Download new maps from the build server" ON)
option(BUILD_RELEASE "Package a release" OFF)
-macro(subproject id name)
- if (EXISTS "${PROJECT_SOURCE_DIR}/${name}/CMakeLists.txt" AND NOT DEFINED ENV{XON_NO_${id}})
+function(subproject id name)
+ if ($ENV{XON_NO_${id}})
+ return()
+ endif ()
+ if (EXISTS "${PROJECT_SOURCE_DIR}/${name}/CMakeLists.txt")
add_subdirectory(${name} ${ARGN})
endif ()
-endmacro()
+endfunction()
-subproject(DAEMON daemon)
-subproject(PKI d0_blind_id)
-subproject(DP darkplaces)
-subproject(DATA data/xonotic-data.pk3dir)
-subproject(QCC gmqcc)
+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)
-# nix-shell -A xonotic
+# nix-shell -A shell
# --argstr cc clang
{
nixpkgs ? <nixpkgs>,
pkgs ? (import nixpkgs) {},
- cc ? null,
+ cc ? null
}:
with pkgs;
let
VERSION = "0.8.2";
- stdenv = if (cc != null) then overrideCC pkgs.stdenv pkgs."${cc}" else pkgs.stdenv;
targets = rec {
- xonotic = stdenv.mkDerivation rec {
+ xonotic = mkDerivation { pki = true; dp = true; data = true; } rec {
name = "xonotic-${version}";
version = VERSION;
- XON_NO_DAEMON = true;
- XON_NO_RADIANT = true;
-
- XON_NO_QCC = true;
- QCC = "${gmqcc}/gmqcc";
-
src = lib.sourceFilesBySuffices ./. [
".txt" ".cmake" ".in"
".c" ".cpp" ".h"
".sh"
];
- enableParallelBuilding = true;
-
- cmakeFlags = [
- "-DDOWNLOAD_MAPS=0"
- ];
+ env = {
+ QCC = "${gmqcc}/gmqcc";
+ };
nativeBuildInputs = [
cmake # for building
# unzip # for downloading maps
];
+ cmakeFlags = [
+ "-DDOWNLOAD_MAPS=0"
+ ];
+
buildInputs = [
openssl # for d0_blind_id
SDL2 # for darkplaces
libvorbis
];
- shellHook = ''
- export LD_LIBRARY_PATH=''${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${lib.makeLibraryPath runtimeInputs}
- '';
-
installPhase = ''
mkdir $out
dontPatchELF = true;
};
- gmqcc = stdenv.mkDerivation rec {
+ gmqcc = mkDerivation { qcc = true; } rec {
name = "gmqcc-${version}";
version = "xonotic-${VERSION}";
src = ./gmqcc;
- enableParallelBuilding = true;
-
installPhase = ''
mkdir $out
cp -r . $out
'';
};
- netradiant = stdenv.mkDerivation rec {
+ netradiant = mkDerivation { radiant = true; } rec {
name = "netradiant-${version}";
version = VERSION;
- XON_NO_DAEMON = true;
- XON_NO_DP = true;
- XON_NO_PKI = true;
- XON_NO_QCC = true;
- XON_NO_DATA = true;
-
src = ./netradiant;
- enableParallelBuilding = true;
-
- cmakeFlags = [
- "-DDOWNLOAD_MAPS=0"
- ];
-
nativeBuildInputs = [
cmake # for building
git # for versioning
];
+ cmakeFlags = [
+ "-DDOWNLOAD_MAPS=0"
+ ];
+
buildInputs = [
pkgconfig
glib
];
};
};
-in targets
+ 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;
+ };
+ 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