# nix-shell -A shell
# nix-build -A xonotic
# --argstr cc clang
+# for it in $(nix-build -A dockerImage --no-out-link); do docker load -i $it; done
{
pkgs, lib,
cc ? null,
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/xonotic-nexcompat" = localFiles ./data/xonotic-nexcompat.pk3dir;
};
+ 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 ".ase" baseName)
+ || (lib.hasSuffix ".dem" baseName)
+ || (lib.hasSuffix ".dpm" baseName)
+ || (lib.hasSuffix ".framegroups" baseName)
+ || (lib.hasSuffix ".iqm" baseName)
+ || (lib.hasSuffix ".jpg" baseName)
+ || (lib.hasSuffix ".lmp" baseName)
+ || (lib.hasSuffix ".md3" baseName)
+ || (lib.hasSuffix ".mdl" baseName)
+ || (lib.hasSuffix ".obj" baseName)
+ || (lib.hasSuffix ".ogg" baseName)
+ || (lib.hasSuffix ".png" baseName)
+ || (lib.hasSuffix ".shader" baseName)
+ || (lib.hasSuffix ".skin" baseName)
+ || (lib.hasSuffix ".sounds" baseName)
+ || (lib.hasSuffix ".sp2" baseName)
+ || (lib.hasSuffix ".spr" baseName)
+ || (lib.hasSuffix ".spr32" baseName)
+ || (lib.hasSuffix ".svg" baseName)
+ || (lib.hasSuffix ".tga" baseName)
+ || (lib.hasSuffix ".wav" baseName)
+ || (lib.hasSuffix ".width" baseName)
+ || (lib.hasSuffix ".zym" baseName)
+ );
+ in result;
+
+ pk3 = drv: mkDerivation {
+ name = "${drv.name}.pk3";
+ version = drv.version;
+
+ nativeBuildInputs = with pkgs; [
+ zip
+ ];
+
+ phases = [ "installPhase" ];
+ installPhase = ''
+ (cd ${drv} && zip -r ${drv.pk3args or ""} $out .)
+ '';
+ };
+
targets = rec {
font-dejavu = mkDerivation rec {
name = "font-dejavu-${version}";
installPhase = ''
mkdir -p $out/lib
+ mkdir -p $out/include/d0_blind_id
+
cp libd0_blind_id.so $out/lib
+ (cd $src; cp d0.h d0_blind_id.h $out/include/d0_blind_id)
- mkdir -p $out/include/d0_blind_id
- (cd $src; cp d0_blind_id.h d0.h $out/include/d0_blind_id)
+ cp libd0_rijndael.so $out/lib
+ (cd $src; cp d0_rijndael.h $out/include/d0_blind_id)
'';
};
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
+ f=darkplaces-$exe
+ rpath=$(patchelf --print-rpath $f)
+ rpath=''${rpath:+$rpath:}${lib.makeLibraryPath runtimeInputs}
+ patchelf --set-rpath $rpath $f
+ cp $f $out/bin/xonotic-linux64-$exe
done
'';
};
'';
};
+ # todo: build
+ xonotic-maps = mkDerivation rec {
+ name = "xonotic-maps-${version}";
+ version = "xonotic-${VERSION}";
+
+ src = srcs."data/xonotic-maps";
+
+ phases = [ "installPhase" ];
+ installPhase = ''
+ mkdir $out
+ cp -r $src/. $out
+ '';
+
+ passthru.dance = mkDerivation rec {
+ name = "dance";
+ version = "xonotic-${VERSION}";
+
+ src = pkgs.fetchurl {
+ url = http://beta.xonotic.org/autobuild-bsp/dance-full-88c416b8c11bdcecfdb889af2a2b97b4c0e2b8de-319ee7234504199da56f07ce25185f6d6cb889cd.pk3;
+ sha256 = "1jgdg4mz56kbxcy3mwn4h5qlf3ahm1cmarp9l70fz9nfn6cnaknq";
+ };
+
+ phases = [ "installPhase" ];
+
+ installPhase = ''
+ mkdir -p $out
+ cd $out
+ ${pkgs.unzip}/bin/unzip $src
+ '';
+ };
+ };
+
+ xonotic-music = mkDerivation rec {
+ name = "xonotic-music-${version}";
+ version = "xonotic-${VERSION}";
+
+ src = srcs."data/xonotic-music";
+
+ phases = [ "installPhase" ];
+ installPhase = ''
+ mkdir $out
+ cp -r $src/. $out
+ '';
+
+ passthru.pk3args = "-0";
+ };
+
+ xonotic-nexcompat = mkDerivation rec {
+ name = "xonotic-nexcompat-${version}";
+ version = "xonotic-${VERSION}";
+
+ src = srcs."data/xonotic-nexcompat";
+
+ phases = [ "installPhase" ];
+ installPhase = ''
+ mkdir $out
+ cp -r $src/. $out
+ '';
+ };
+
+ xonotic-keys = mkDerivation rec {
+ name = "xonotic-keys-${version}";
+ version = VERSION;
+
+ src = srcs."xonotic";
+
+ phases = [ "installPhase" ];
+
+ installPhase = ''
+ mkdir $out
+ cp $src/*.d0pk $out
+ '';
+ };
+
xonotic = mkDerivation rec {
name = "xonotic-${version}";
version = VERSION;
XON_NO_DAEMON = "1";
};
+ passthru.paks = {
+ inherit
+ font-dejavu
+ font-nimbussansl
+ font-unifont
+ font-xolonium
+ xonotic-data
+ xonotic-data-code
+ xonotic-maps
+ xonotic-music
+ xonotic-nexcompat
+ ;
+ inherit (xonotic-maps)
+ dance
+ ;
+ };
+
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
+ ${lib.concatStringsSep "\n" (lib.mapAttrsToList (k: v:
+ # "cp ${pk3 v} $out/data/${k}.pk3"
+ "ln -s ${v} $out/data/${k}.pk3dir"
+ ) passthru.paks)}
mkdir -p $out/mapping
ln -s ${netradiant} $out/mapping/${netradiant.name}
'';
};
+
+ dockerImage = let
+ main = pkgs.dockerTools.buildImage {
+ name = "xonotic";
+ tag = VERSION;
+ contents = mkDerivation {
+ name = "xonotic-init";
+ phases = [ "installPhase" ];
+ installPhase = ''
+ mkdir -p $out
+ cat > $out/init <<EOF
+ #!${stdenv.shell}
+ ${pkgs.coreutils}/bin/ln -s ${xonotic-keys}/* /
+
+ ${pkgs.coreutils}/bin/ls -l /
+ ${pkgs.coreutils}/bin/ls -l /data
+
+ exec ${darkplaces}/bin/xonotic-linux64-dedicated "\''${@}"
+ EOF
+ chmod +x $out/init
+ '';
+ };
+ config.Entrypoint = "/init";
+ };
+ unpackImage = { name, from, to }: pkgs.dockerTools.buildImage {
+ name = "xonotic_${name}";
+ tag = VERSION;
+ contents = mkDerivation {
+ name = "xonotic-${name}-init";
+ phases = [ "installPhase" ];
+ installPhase = ''
+ mkdir -p $out
+ cat > $out/init <<EOF
+ #!${stdenv.shell}
+ ${pkgs.coreutils}/bin/cp -r ${from} /data/${to}
+ EOF
+ chmod +x $out/init
+ '';
+ };
+ config.Entrypoint = "/init";
+ };
+ in { main = main; }
+ // (lib.mapAttrs (k: v: unpackImage { name = k; from = pk3 v; to = "${k}.pk3"; }) xonotic.paks)
+ ;
};
+ 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);
+
+ stdenv = if (cc == null) then pkgs.stdenv
+ else pkgs.overrideCC pkgs.stdenv pkgs."${cc}";
+
mkDerivation = {env ? {}, shellHook ? "", runtimeInputs ? [], ...}@args: stdenv.mkDerivation ({}
// { enableParallelBuilding = true; }
// (removeAttrs args ["env" "shellHook" "runtimeInputs"])
'';
}
);
- shell = let inputs = (lib.mapAttrsToList (n: v: v) targets); in stdenv.mkDerivation (rec {
+
+ shell = let inputs = (lib.mapAttrsToList (k: v: v) targets); in stdenv.mkDerivation (rec {
name = "xonotic-shell";
- nativeBuildInputs = builtins.map (it: it.nativeBuildInputs) inputs;
- buildInputs = builtins.map (it: it.buildInputs) inputs;
+ nativeBuildInputs = builtins.map (it: it.nativeBuildInputs) (builtins.filter (it: it?nativeBuildInputs) inputs);
+ buildInputs = builtins.map (it: it.buildInputs) (builtins.filter (it: it?buildInputs) inputs);
shellHook = builtins.map (it: it.shellHook) (builtins.filter (it: it?shellHook) inputs);
});
in { inherit shell; } // targets