]> git.rm.cloudns.org Git - xonotic/xonotic.git/commitdiff
Update nix build
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 21 Apr 2018 05:12:41 +0000 (15:12 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 21 Apr 2018 05:13:20 +0000 (15:13 +1000)
CMakeLists.txt
default.nix
derivation.nix [new file with mode: 0644]
release.nix [new file with mode: 0644]

index e63f71f6654983d9ed0195700ec4070da685694f..23080598b53504e61e954830ad56295dc97b3c7f 100644 (file)
@@ -13,12 +13,12 @@ function(subproject id name)
     endif ()
 endfunction()
 
-subproject(DAEMON daemon)
 subproject(PKI d0_blind_id)
+subproject(DAEMON daemon)
 subproject(DP darkplaces)
-subproject(DATA data/xonotic-data.pk3dir)
 subproject(QCC gmqcc)
 subproject(RADIANT netradiant)
+subproject(DATA data/xonotic-data.pk3dir)
 
 if (DOWNLOAD_MAPS)
     add_custom_target(update-maps ALL
index 4ee0c65ae485af1edf9d9cb4b3429f231ea6d5d2..469c3f9b1dd3e5450ec716140110b6efd413957a 100644 (file)
@@ -1,155 +1,2 @@
-# nix-shell -A shell
-# --argstr cc clang
-{
-    nixpkgs ? <nixpkgs>,
-    pkgs ? (import nixpkgs) {},
-    cc ? null
-}:
-with pkgs;
-let
-    VERSION = "0.8.2";
-    cmake = pkgs.cmake_2_8;
-    targets = rec {
-        xonotic = mkDerivation { pki = true; dp = true; data = true; } rec {
-            name = "xonotic-${version}";
-            version = VERSION;
-
-            src = lib.sourceFilesBySuffices ./. [
-                ".txt" ".cmake" ".in"
-                ".c" ".cpp" ".h"
-                ".inc" ".def"
-                ".qc" ".qh"
-                ".sh"
-            ];
-
-            env = {
-                QCC = "${gmqcc}/bin/gmqcc";
-            };
-
-            nativeBuildInputs = [
-                cmake   # for building
-                git     # for versioning
-                # unzip # for downloading maps
-            ];
-
-            cmakeFlags = [
-                "-DDOWNLOAD_MAPS=0"
-            ];
-
-            buildInputs = [
-                openssl # for d0_blind_id
-                SDL2    # for darkplaces
-            ];
-
-            runtimeInputs = [
-                zlib
-                curl
-
-                libjpeg
-                libpng
-
-                freetype
-
-                libogg
-                libtheora
-                libvorbis
-            ];
-
-            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 = mkDerivation { qcc = true; } rec {
-            name = "gmqcc-${version}";
-            version = "xonotic-${VERSION}";
-
-            src = ./gmqcc;
-
-            installPhase = ''
-                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;
-    };
-    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
+{ pkgs ? import <nixpkgs> {} }:
+pkgs.callPackage ./derivation.nix {}
diff --git a/derivation.nix b/derivation.nix
new file mode 100644 (file)
index 0000000..945f39a
--- /dev/null
@@ -0,0 +1,381 @@
+# nix-shell -A shell
+# nix-build -A xonotic
+# --argstr cc clang
+{
+    pkgs, lib,
+    cc ? null,
+    cmake ? pkgs.cmake_2_8,
+}:
+let
+    VERSION = "0.8.2";
+
+    stdenv = if (cc == null) then pkgs.stdenv
+        else pkgs.overrideCC pkgs.stdenv pkgs."${cc}";
+
+    cleanSourceFilter = name: type: let
+        baseName = baseNameOf (toString name);
+        result = (lib.cleanSourceFilter name type)
+            && !(lib.hasSuffix ".nix" baseName)
+            && !(type == "directory" && baseName == ".git")
+            && !(type == "directory" && baseName == ".idea")
+            && !(type == "directory" && (lib.hasPrefix "cmake-build-" baseName))
+        ;
+    in result;
+
+    localFilesCustom = src: filter:
+        builtins.filterSource (name: type: (cleanSourceFilter name type) && (filter name type)) src
+    ;
+    localFiles = src: localFilesCustom src (name: type: true);
+
+    localFilesMain = src: let
+        project = toString ./.;
+        cleanSourceFilterMain = name: type: let
+            baseName = baseNameOf (toString name);
+            result = (cleanSourceFilter name type)
+                && !(name == "${project}/release")
+                && !(name == "${project}/d0_blind_id")
+                && !(name == "${project}/daemon")
+                && !(name == "${project}/darkplaces")
+                && !(name == "${project}/data")
+                && !(name == "${project}/gmqcc")
+                && !(name == "${project}/netradiant")
+                && !(name == "${project}/wiki" || name == "${project}/wiki.yes")
+                && !(name == "${project}/xonstat" || name == "${project}/xonstat.yes")
+            ;
+        in result;
+    in builtins.filterSource cleanSourceFilterMain src;
+
+    isCode = name: let
+        baseName = baseNameOf (toString name);
+        result = false
+            || (lib.hasSuffix ".txt" baseName)
+            || (lib.hasSuffix ".cmake" baseName)
+            || (lib.hasSuffix ".in" baseName)
+            || (lib.hasSuffix ".sh" baseName)
+
+            || (lib.hasSuffix ".qc" baseName)
+            || (lib.hasSuffix ".qh" baseName)
+            || (lib.hasSuffix ".inc" baseName)
+
+            || (lib.hasSuffix ".cfg" baseName)
+        ;
+    in result;
+
+    srcs = {
+        # https://gitlab.com/xonotic/xonotic
+        "xonotic" = localFilesMain ./.;
+        "data/font-dejavu" = localFiles ./data/font-dejavu.pk3dir;
+        "data/font-nimbussansl" = localFiles ./data/font-nimbussansl.pk3dir;
+        "data/font-unifont" = localFiles ./data/font-unifont.pk3dir;
+        "data/font-xolonium" = localFiles ./data/font-xolonium.pk3dir;
+
+        # https://gitlab.com/xonotic/d0_blind_id
+        "d0_blind_id" = localFiles ./d0_blind_id;
+
+        # https://gitlab.com/xonotic/darkplaces
+        "darkplaces" = localFiles ./darkplaces;
+
+        # https://gitlab.com/xonotic/gmqcc
+        "gmqcc" = localFiles ./gmqcc;
+
+        # https://gitlab.com/xonotic/netradiant
+        "netradiant" = localFiles ./netradiant;
+
+        # https://gitlab.com/xonotic/xonotic-data.pk3dir
+        "data/xonotic-data" = localFilesCustom ./data/xonotic-data.pk3dir (name: type: type == "directory" || !(isCode name));
+        "data/xonotic-data/qcsrc" = localFilesCustom ./data/xonotic-data.pk3dir (name: type: type == "directory" || (isCode name));
+
+        # https://gitlab.com/xonotic/xonotic-maps.pk3dir
+        "data/xonotic-maps" = localFiles ./data/xonotic-maps.pk3dir;
+
+        # https://gitlab.com/xonotic/xonotic-music.pk3dir
+        "data/xonotic-music" = localFiles ./data/xonotic-music.pk3dir;
+
+        # https://gitlab.com/xonotic/xonotic-nexcompat.pk3dir
+        "data/xonotic-nexcompat" = localFiles ./data/xonotic-nexcompat.pk3dir;
+    };
+
+    targets = rec {
+        font-dejavu = mkDerivation rec {
+            name = "font-dejavu-${version}";
+            version = VERSION;
+
+            src = srcs."data/font-dejavu";
+
+            phases = [ "installPhase" ];
+            installPhase = ''
+                cp -r $src $out
+            '';
+        };
+
+        font-nimbussansl = mkDerivation rec {
+            name = "font-nimbussansl-${version}";
+            version = VERSION;
+
+            src = srcs."data/font-nimbussansl";
+
+            phases = [ "installPhase" ];
+            installPhase = ''
+                cp -r $src $out
+            '';
+        };
+
+        font-unifont = mkDerivation rec {
+            name = "font-unifont-${version}";
+            version = VERSION;
+
+            src = srcs."data/font-unifont";
+
+            phases = [ "installPhase" ];
+            installPhase = ''
+                cp -r $src $out
+            '';
+        };
+
+        font-xolonium = mkDerivation rec {
+            name = "font-xolonium-${version}";
+            version = VERSION;
+
+            src = srcs."data/font-xolonium";
+
+            phases = [ "installPhase" ];
+            installPhase = ''
+                cp -r $src $out
+            '';
+        };
+
+        d0_blind_id = mkDerivation rec {
+            name = "d0_blind_id-${version}";
+            version = "xonotic-${VERSION}";
+
+            src = srcs."d0_blind_id";
+
+            nativeBuildInputs = [
+                cmake
+            ];
+
+            buildInputs = with pkgs; [
+                openssl
+            ];
+
+            installPhase = ''
+                mkdir -p $out/lib
+                cp libd0_blind_id.so $out/lib
+
+                mkdir -p $out/include/d0_blind_id
+                (cd $src; cp d0_blind_id.h d0.h $out/include/d0_blind_id)
+            '';
+        };
+
+        darkplaces = let
+            unwrapped = mkDerivation rec {
+                name = "darkplaces-unwrapped-${version}";
+                version = "xonotic-${VERSION}";
+
+                src = srcs."darkplaces";
+
+                nativeBuildInputs = [
+                    cmake
+                ];
+
+                buildInputs = with pkgs; [
+                    SDL2
+
+                    zlib
+                    libjpeg
+                ];
+
+                installPhase = ''
+                    mkdir -p $out/bin
+                    cp darkplaces-{dedicated,sdl} $out/bin
+                '';
+            };
+            result = mkDerivation rec {
+                name = "darkplaces-${version}";
+                version = "xonotic-${VERSION}";
+
+                buildInputs = unwrapped.buildInputs ++ runtimeInputs;
+                runtimeInputs = with pkgs; [
+                    d0_blind_id
+
+                    freetype
+
+                    curl
+                    zlib
+
+                    libjpeg
+                    libpng
+
+                    libogg
+                    libtheora
+                    libvorbis
+                ];
+
+                phases = [ "installPhase" ];
+                installPhase = ''
+                    mkdir -p $out/bin
+
+                    cp -r ${unwrapped}/bin .
+                    chmod +w bin/*
+                    cd bin
+
+                    for exe in darkplaces-sdl; do
+                        rpath=$(patchelf --print-rpath $exe)
+                        rpath=''${rpath:+$rpath:}${lib.makeLibraryPath runtimeInputs}
+                        patchelf --set-rpath $rpath $exe
+                    done
+
+                    for exe in dedicated sdl; do
+                        cp darkplaces-$exe $out/bin/xonotic-linux64-$exe
+                    done
+                '';
+            };
+        in result;
+
+        gmqcc = mkDerivation rec {
+            name = "gmqcc-${version}";
+            version = "xonotic-${VERSION}";
+
+            src = srcs."gmqcc";
+
+            nativeBuildInputs = [
+                cmake
+            ];
+
+            installPhase = ''
+                mkdir -p $out/bin
+                cp gmqcc $out/bin
+            '';
+        };
+
+        netradiant = mkDerivation rec {
+            name = "netradiant-${version}";
+            version = VERSION;
+
+            src = srcs."netradiant";
+
+            nativeBuildInputs = with pkgs; [
+                cmake
+                git
+            ];
+
+            buildInputs = with pkgs; [
+                pkgconfig
+                glib
+                pcre
+                libxml2
+                ncurses
+                libjpeg
+                libpng
+                minizip
+
+                mesa
+
+                xorg.libXt
+                xorg.libXmu
+                xorg.libSM
+                xorg.libICE
+                xorg.libpthreadstubs
+                xorg.libXdmcp
+
+                gnome2.gtk
+                gnome2.gtkglext
+                gnome3.gtk
+            ];
+        };
+
+        xonotic-data = mkDerivation rec {
+            name = "xonotic-data-${version}";
+            version = "xonotic-${VERSION}";
+
+            src = srcs."data/xonotic-data";
+
+            phases = [ "installPhase" ];
+            installPhase = ''
+                mkdir $out
+                cp -r $src/. $out
+                chmod -R +w $out
+                find $out -depth -type d -empty -exec rmdir {} \;
+            '';
+        };
+
+        xonotic-data-code = mkDerivation rec {
+            name = "xonotic-data-code-${version}";
+            version = "xonotic-${VERSION}";
+
+            src = srcs."data/xonotic-data/qcsrc";
+
+            env = {
+                QCC = "${gmqcc}/bin/gmqcc";
+            };
+
+            nativeBuildInputs = with pkgs; [
+                cmake
+                git
+            ];
+
+            installPhase = ''
+                mkdir $out
+                cp -r $src/. $out
+                chmod -R +w $out
+                cp {menu,progs,csprogs}.{dat,lno} $out
+                find $out -depth -type d -empty -exec rmdir {} \;
+            '';
+        };
+
+        xonotic = mkDerivation rec {
+            name = "xonotic-${version}";
+            version = VERSION;
+
+            src = srcs."xonotic";
+
+            env = {
+                XON_NO_DAEMON = "1";
+            };
+
+            phases = [ "installPhase" ];
+
+            # test: `ln -s`
+            # release: `cp -r`
+            installPhase = ''
+                mkdir $out
+                cp -r $src/. $out
+                cp ${darkplaces}/bin/* $out
+
+                mkdir -p $out/data
+                ln -s ${font-dejavu} $out/data/font-dejavu.pk3dir
+                ln -s ${font-nimbussansl} $out/data/font-nimbussansl.pk3dir
+                ln -s ${font-unifont} $out/data/font-unifont.pk3dir
+                ln -s ${font-xolonium} $out/data/font-xolonium.pk3dir
+
+                ln -s ${xonotic-data} $out/data/xonotic-data.pk3dir
+                ln -s ${xonotic-data-code} $out/data/xonotic-data-code.pk3dir
+                ln -s ${srcs."data/xonotic-maps"} $out/data/xonotic-maps.pk3dir # todo: build
+                ln -s ${srcs."data/xonotic-music"} $out/data/xonotic-music.pk3dir
+                ln -s ${srcs."data/xonotic-nexcompat"} $out/data/xonotic-nexcompat.pk3dir
+
+                mkdir -p $out/mapping
+                ln -s ${netradiant} $out/mapping/${netradiant.name}
+            '';
+        };
+    };
+
+    mkDerivation = {env ? {}, shellHook ? "", runtimeInputs ? [], ...}@args: stdenv.mkDerivation ({}
+        // { enableParallelBuilding = true; }
+        // (removeAttrs args ["env" "shellHook" "runtimeInputs"])
+        // 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 = "xonotic-shell";
+        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
diff --git a/release.nix b/release.nix
new file mode 100644 (file)
index 0000000..ae69b61
--- /dev/null
@@ -0,0 +1,11 @@
+{
+    nixpkgs ? <nixpkgs>,
+    systems ? [ "i686-linux" "x86_64-linux" ],
+}:
+{
+    xonotic = (import <nixpkgs/lib>).genAttrs systems (system:
+        import ./default.nix {
+            pkgs = import nixpkgs { inherit system; };
+        }
+    );
+}