scallyw4g / bonsai

A voxel engine in a pot
Do What The F*ck You Want To Public License
170 stars 10 forks source link

Let's make a nix port #68

Open Sigmanificient opened 3 weeks ago

Sigmanificient commented 3 weeks ago

Hi! I was recently recommended your project by GitHub and found it quite astonishing!

I wanted to try it for myself, as I noticed the presence of a default.nix file. However it seems to be quite out of date (last updated about 5 years ago) and only provides a few dependencies. With my curiosity picked, I tried to assemble a very basic derivation that would build the core items of the engine (the game loader, and demo files). Currently, the setup is a bit hacky (for instance i have to cd within the result dir), but here the derivation i made as a proof of concept:

{ stdenv, fetchFromGitHub, clang, which, libGL, xorg }:

stdenv.mkDerivation (finalAttrs: {
  pname = "bonsai-engine";
  version = "1.5.1";

  src = fetchFromGitHub {
    owner = "scallyw4g";
    repo = "bonsai";
    rev = "refs/tags/v${finalAttrs.version}";
    hash = "sha256-hzKmrrYNwBVnkwN/AyoYJMI+2xYZGJ7pl5dYpFfitQA=";
    fetchSubmodules = true;
  };

  nativeBuildInputs = [ clang which xorg.libX11 libGL ];

  prePatch = ''
    patchShebangs .

    substituteInPlace external/bonsai_stdlib/src/initialize.cpp \
      --replace-fail "./bin/lib_debug_system_loadable" "$out/lib/lib_debug_system_loadable"
  '';

  buildPhase = "./make.sh";

  installPhase = ''
    install -Dm 755 ./bin/game_loader $out/bin/game_loader
    install -Dm 755 ./bin/lib_debug_system_loadable.so $out/lib/lib_debug_system_loadable.so

    for lib in \
      blank_project_loadable \
      project_and_level_picker_loadable \
      terrain_gen_loadable \
      the_wanderer_loadable \
      transparency_loadable \
      turn_based_loadable \
      voxel_synthesis_rule_baker_loadable; \
    do
      install -Dm 755 ./bin/game_libs/$lib.so $out/lib/$lib.so
    done

    cp -r shaders $out/shaders
    cp -r assets $out/assets

    cp -r settings.init $out/settings.init

    cp texture_atlas_0.bmp $out/texture_atlas_0.bmp
    cp texture_atlas_1.bmp $out/texture_atlas_1.bmp

    touch $out/.root_marker
  '';
})

Here is a screenshot of the generator, that has been built using from the prototype derivation:

image

It was wondering if you were interested to improve the nix support (which would take me quite some time to do properly). I could setup a flake.nix for this repository to provide things like the devShelll, package to build the demo declaratively and more. This could also be the opportunity to port the engine to nixpkgs repository.

scallyw4g commented 3 weeks ago

Hi @Sigmanificient! Thanks for your kind words and enthusiasm :)

I personally have no particular interest in improving the nix support because I don't use nix. That nixfile was written by a buddy of mine who obviously didn't continue to contribute. Since I'm the only person who contributes to the project regularly, and there are very few dependencies, the cost of using nix is significantly (imo) outweighed by the benefit.

That said, if you'd like to do it as a fun project because you like nix, or because you might want to contribute to bonsai in the future and nix makes you happy, go nuts :)