mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-05-27 04:02:59 +00:00
Also wrote and by wrote I mean stole from other projects helper functions for bypassing the nodownload restriction of the nix sandbox. This uses the wrap files in the repo ecxept for the download part which has to be an input for reproducibility sake. The Nix Code is ugly and I am gonna vomit.
171 lines
4.4 KiB
Nix
171 lines
4.4 KiB
Nix
{
|
|
description = "4jcraft nix-package and dev-shell";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
shiggy = {
|
|
url = "github:4jcraft/shiggy/main";
|
|
flake = false;
|
|
};
|
|
|
|
"4jlibs" = {
|
|
url = "github:4jcraft/4jlibs/main";
|
|
flake = false;
|
|
};
|
|
|
|
miniaudio = {
|
|
url = "https://github.com/mackron/miniaudio/archive/refs/tags/0.11.22.tar.gz";
|
|
flake = false;
|
|
};
|
|
|
|
# patches only get applied if they follow <subproject_to_patch>-patch naming
|
|
miniaudio-patch = {
|
|
url = "https://wrapdb.mesonbuild.com/v2/miniaudio_0.11.22-2/get_patch";
|
|
flake = false;
|
|
};
|
|
|
|
stb = {
|
|
url = "github:nothings/stb/master";
|
|
flake = false;
|
|
};
|
|
|
|
simdutf = {
|
|
url = "github:simdutf/simdutf";
|
|
flake = false;
|
|
};
|
|
};
|
|
|
|
outputs =
|
|
{ self, nixpkgs, flake-utils, ... }@inputs:
|
|
flake-utils.lib.eachDefaultSystem (
|
|
system:
|
|
let
|
|
pkgs = import nixpkgs { inherit system; };
|
|
lib = pkgs.lib;
|
|
|
|
subprojectNames = [
|
|
"shiggy"
|
|
"4jlibs"
|
|
"stb"
|
|
"simdutf"
|
|
"miniaudio"
|
|
];
|
|
|
|
# helper: copy all subproject sources
|
|
copySubprojects = ''
|
|
mkdir -p $sourceRoot/subprojects
|
|
${lib.concatMapStringsSep "\n" (name: "cp -r ${inputs.${name}} $sourceRoot/subprojects/${name}") subprojectNames}
|
|
chmod -R u+w $sourceRoot/subprojects
|
|
'';
|
|
|
|
# helper: copy packagefiles
|
|
copyPackagefiles = ''
|
|
for proj in ${builtins.toString subprojectNames}; do
|
|
if [ -d "subprojects/packagefiles/$proj" ]; then
|
|
cp -r subprojects/packagefiles/$proj/* subprojects/$proj/
|
|
fi
|
|
done
|
|
'';
|
|
|
|
# helper: apply patches from '-patch' inputs
|
|
applyPatches = lib.concatMapStringsSep "\n" (name: ''
|
|
patch_input="${inputs.${name + "-patch"} or ""}"
|
|
if [ -n "$patch_input" ]; then
|
|
unzip "$patch_input" -d ${name}-patch-tmp
|
|
if [ $(ls -1 ${name}-patch-tmp | wc -l) -eq 1 ] && [ -d ${name}-patch-tmp/* ]; then
|
|
cp -r ${name}-patch-tmp/*/* subprojects/${name}/
|
|
else
|
|
cp -r ${name}-patch-tmp/* subprojects/${name}/
|
|
fi
|
|
rm -rf ${name}-patch-tmp
|
|
fi
|
|
'') subprojectNames;
|
|
|
|
in
|
|
{
|
|
packages.default = pkgs.clangStdenv.mkDerivation {
|
|
pname = "4jcraft";
|
|
version = "0.1.0";
|
|
src = ./.;
|
|
|
|
dontFixup = true;
|
|
dontUseCmakeConfigure = true;
|
|
|
|
# Disable fortify to prevent buffer overflow detection
|
|
hardeningDisable = [ "fortify3" "fortify" ];
|
|
|
|
postUnpack = ''
|
|
${copySubprojects}
|
|
'';
|
|
|
|
postPatch = ''
|
|
# Remove wrap files so Meson doesn't try to download them
|
|
for proj in ${builtins.toString subprojectNames}; do
|
|
rm -f subprojects/$proj.wrap
|
|
done
|
|
|
|
${copyPackagefiles}
|
|
${applyPatches}
|
|
'';
|
|
|
|
nativeBuildInputs = with pkgs; [
|
|
lld
|
|
makeWrapper
|
|
meson
|
|
ninja
|
|
pkg-config
|
|
python3
|
|
unzip
|
|
];
|
|
|
|
buildInputs = with pkgs; [
|
|
openssl.dev
|
|
libGL
|
|
libGLU
|
|
glm
|
|
SDL2
|
|
zlib
|
|
];
|
|
|
|
installPhase = ''
|
|
mkdir -p $out/share/4jcraft
|
|
cp -r Minecraft.Client/. $out/share/4jcraft/
|
|
|
|
mkdir -p $out/bin
|
|
makeWrapper $out/share/4jcraft/Minecraft.Client $out/bin/4jcraft \
|
|
--run "cd $out/share/4jcraft"
|
|
'';
|
|
|
|
meta = {
|
|
description = "4JCraft";
|
|
platforms = lib.platforms.unix;
|
|
};
|
|
};
|
|
|
|
devShells.default =
|
|
pkgs.mkShell.override
|
|
{
|
|
stdenv = pkgs.clangStdenv;
|
|
}
|
|
{
|
|
inputsFrom = [ self.packages.${system}.default ];
|
|
|
|
packages = with pkgs; [
|
|
clang-tools
|
|
lldb
|
|
valgrind
|
|
include-what-you-use
|
|
ccache
|
|
];
|
|
|
|
shellHook = ''
|
|
export CC="ccache clang"
|
|
export CXX="ccache clang++"
|
|
'';
|
|
};
|
|
}
|
|
);
|
|
}
|