mkDerivation godot mono version (C# support) not working

Hey,
i’m on nixos 20.09 and try to build godot-3.2.3-stable with support for C#.

I’m following the instruction on the godot docs, which states that one first has to enable the mono module and then generate the mono-glue. I tried to adapt the default.nix of the NixOS/nixpkgs repository to my needs but failed.

What i tried to do :

with import<nixpkgs>{};

stdenv.mkDerivation rec {
  pname = "godot_cs";
  version = "3.2.3";

  src = fetchFromGitHub {
    owner  = "godotengine";
    repo   = "godot";
    rev    = "${version}-stable";
    sha256 = "19vrp5lhyvxbm6wjxzn28sn3i0s8j08ca7nani8l1nrhvlc8wi0v";
  };

  nativeBuildInputs = with pkgs; [ pkg-config ];
  buildInputs = with pkgs; [
    mono6 msbuild dotnetPackages.Nuget 
    scons xorg.libX11 xorg.libXcursor xorg.libXinerama xorg.libXrandr xorg.libXrender
    xorg.libXi xorg.libXext xorg.libXfixes freetype openssl alsaLib libpulseaudio
    libGLU zlib yasm
  ];

  patches = [
    ./pkg_config_additions.patch
    ./dont_clobber_environment.patch
  ];

  enableParallelBuilding = true;

  buildPhase = ''
    scons p=x11 tools=yes module_mono_enabled=yes mono_glue=no pulseaudio=true
    ./bin/godot.x11.tools.64.mono --generate-mono-glue modules/mono/glue
    scons p=x11 target=release_debug tools=yes module_mono_enabled=yes
  '';

  outputs = [ "out" "dev" ];

  installPhase = ''
    mkdir -p "$out/bin"
    cp bin/godot.* $out/bin/godot
    mkdir "$dev"
    cp -r modules/gdnative/include $dev
    mkdir -p "$out"/share/{applications,icons/hicolor/scalable/apps}
    cp misc/dist/linux/org.godotengine.Godot.desktop "$out/share/applications/"
    cp icon.svg "$out/share/icons/hicolor/scalable/apps/godot.svg"
    cp icon.png "$out/share/icons/godot.png"
    substituteInPlace "$out/share/applications/org.godotengine.Godot.desktop" \
      --replace "Exec=godot" "Exec=$out/bin/godot"
  '';
}

But if i try to build the derivation with nix-build i get an error:

Mono root directory not found. Using pkg-config instead
/nix/store/vnyfysaya7sblgdyvqjkrjbrb0cy11jf-bash-4.4-p23/bin/sh: pkg-config: command not found
OSError: 'pkg-config monosgen-2 --libs-only-L' exited 127:
  File "/build/source/SConstruct", line 617:
    SConscript("modules/SCsub")
...
...
builder for '/nix/store/gpf5rchkbmwc1kqirn2bydxlrlnny2pn-godot_cs-3.2.3.drv' failed with exit code 2
error: build of '/nix/store/gpf5rchkbmwc1kqirn2bydxlrlnny2pn-godot_cs-3.2.3.drv' failed

I am sorry but this is the first derivation i am trying to build and i am totally lost here. I have already searched the nixpkg manual but couldn’t find a solution there. If someone could help me and point me in the right direction i would be very grateful.

In the original derivation for goday you can see this.

{ stdenv, lib, fetchFromGitHub, scons, pkgconfig, libX11, libXcursor
, libXinerama, libXrandr, libXrender, libpulseaudio ? null
, libXi ? null, libXext, libXfixes, freetype, openssl
, alsaLib, libGLU, zlib, yasm ? null }:

let
  options = {
    touch = libXi != null;
    pulseaudio = false;
  };
in stdenv.mkDerivation rec {
  pname = "godot";
  version = "3.2.3";

  src = fetchFromGitHub {
    owner  = "godotengine";
    repo   = "godot";
    rev    = "${version}-stable";
    sha256 = "19vrp5lhyvxbm6wjxzn28sn3i0s8j08ca7nani8l1nrhvlc8wi0v";
  };

  nativeBuildInputs = [ pkgconfig ];
  buildInputs = [
    scons libX11 libXcursor libXinerama libXrandr libXrender
    libXi libXext libXfixes freetype openssl alsaLib libpulseaudio
    libGLU zlib yasm
  ];

  patches = [
    ./pkg_config_additions.patch
    ./dont_clobber_environment.patch
  ];

  enableParallelBuilding = true;

  sconsFlags = "target=release_debug platform=x11";
  preConfigure = ''
    sconsFlags+=" ${lib.concatStringsSep " " (lib.mapAttrsToList (k: v: "${k}=${builtins.toJSON v}") options)}"
  '';

  outputs = [ "out" "dev" "man" ];

  installPhase = ''
    mkdir -p "$out/bin"
    cp bin/godot.* $out/bin/godot
    mkdir "$dev"
    cp -r modules/gdnative/include $dev
    mkdir -p "$man/share/man/man6"
    cp misc/dist/linux/godot.6 "$man/share/man/man6/"
    mkdir -p "$out"/share/{applications,icons/hicolor/scalable/apps}
    cp misc/dist/linux/org.godotengine.Godot.desktop "$out/share/applications/"
    cp icon.svg "$out/share/icons/hicolor/scalable/apps/godot.svg"
    cp icon.png "$out/share/icons/godot.png"
    substituteInPlace "$out/share/applications/org.godotengine.Godot.desktop" \
      --replace "Exec=godot" "Exec=$out/bin/godot"
  '';

  meta = {
    homepage    = "https://godotengine.org";
    description = "Free and Open Source 2D and 3D game engine";
    license     = stdenv.lib.licenses.mit;
    platforms   = [ "i686-linux" "x86_64-linux" ];
    maintainers = [ stdenv.lib.maintainers.twey ];
  };
}

you’ll see

sconsFlags = "target=release_debug platform=x11";

as you seems to be using different scons flags, you maybe able to put them here.

However you changed the devivation, it’s having trouble find pkg-config now.

If that doesn’t work it maybe time to debug the Build with a nix-shell. I’ll post how do that if you like.

Thanks a lot for your suggestion and your offer for further help :slight_smile: I found a solution in the meantime on GitHub - sgillespie/nixos-godot-bin: An overlay for Godot which i could tweak to my needs.