From ed5146dcfc4795d56fd5101c39d7de9789baab26 Mon Sep 17 00:00:00 2001 From: TimePath Date: Wed, 2 Aug 2017 21:29:06 +1000 Subject: [PATCH] nix: create a composed shell derivation --- CMakeLists.txt | 19 +++++++----- default.nix | 82 ++++++++++++++++++++++++++++---------------------- 2 files changed, 57 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 704c5439..4116f5cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,17 +4,20 @@ project(xonotic) 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) diff --git a/default.nix b/default.nix index 418fb88d..69485127 100644 --- a/default.nix +++ b/default.nix @@ -1,25 +1,18 @@ -# nix-shell -A xonotic +# nix-shell -A shell # --argstr cc clang { 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" @@ -28,11 +21,9 @@ let ".sh" ]; - enableParallelBuilding = true; - - cmakeFlags = [ - "-DDOWNLOAD_MAPS=0" - ]; + env = { + QCC = "${gmqcc}/gmqcc"; + }; nativeBuildInputs = [ cmake # for building @@ -40,6 +31,10 @@ let # unzip # for downloading maps ]; + cmakeFlags = [ + "-DDOWNLOAD_MAPS=0" + ]; + buildInputs = [ openssl # for d0_blind_id SDL2 # for darkplaces @@ -59,10 +54,6 @@ let libvorbis ]; - shellHook = '' - export LD_LIBRARY_PATH=''${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${lib.makeLibraryPath runtimeInputs} - ''; - installPhase = '' mkdir $out @@ -79,43 +70,33 @@ let 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 @@ -141,4 +122,33 @@ let ]; }; }; -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 -- 2.39.2