Setup monogame content editor

A small disclaimer that I started using Nixos for around one month - so I’m fairly new to the ecosystem.

I’ve been trying to setup MonoGame.
I’ve made a nix-shell

with import <nixpkgs> {};
stdenv.mkDerivation {
  name = "env";
  buildInputs = [
    pkgs.dotnet-sdk
    pkgs.freetype
    pkgs.libGL
    pkgs.pulseaudio
    pkgs.xorg.libX11
    pkgs.xorg.libXrandr
    pkgs.gtk3
    pkgs.gtk3-x11
    pkgs.git
  ];
  LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
    pkgs.freetype
    pkgs.libGL
    pkgs.pulseaudio
    pkgs.xorg.libX11
    pkgs.xorg.libXrandr
    pkgs.dotnet-sdk
    pkgs.gtk3
    pkgs.gtk3-x11
  ];
}

and later a flake

{
  description = "dotnet monogame flake";

  inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; };

  outputs = { self, nixpkgs }:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs { 
        inherit system; 
      };
    in {
      environment.sessionVariables = { DOTNET_ROOT = "${pkgs.dotnet-sdk}"; };
      devShells.${system}.default = pkgs.mkShell {
        buildInputs = with pkgs; [ dotnet-sdk ];
        LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
          pkgs.freetype
          pkgs.libGL
          pkgs.pulseaudio
          pkgs.xorg.libX11
          pkgs.xorg.libXrandr
          pkgs.dotnet-sdk
          pkgs.gtk3
          pkgs.gtk3-x11
        ];
      };
    };
}

which allowed me to by bypass issues with the LD_LIBRARY_PATH.
After installing mgcb-editor dotnet tool I tried running it inside the shell.

Which leads to multiple errors

(mgcb-editor-linux:438615): GdkPixbuf-CRITICAL **: 16:27:46.954: gdk_pixbuf_calculate_rowstride: assertion 'bits_per_sample == 8' failed

(mgcb-editor-linux:438615): GdkPixbuf-CRITICAL **: 16:27:46.955: gdk_pixbuf_calculate_rowstride: assertion 'bits_per_sample == 8' failed

(mgcb-editor-linux:438615): Gtk-CRITICAL **: 16:27:46.984: gtk_icon_set_new_from_pixbuf: assertion 'pixbuf != NULL' failed

(mgcb-editor-linux:438615): Gtk-CRITICAL **: 16:27:46.987: gtk_icon_set_new_from_pixbuf: assertion 'pixbuf != NULL' failed

(mgcb-editor-linux:438615): Gtk-CRITICAL **: 16:27:46.988: gtk_icon_set_new_from_pixbuf: assertion 'pixbuf != NULL' failed

(mgcb-editor-linux:438615): Gtk-WARNING **: 16:27:47.136: GtkHeaderBar does not have a child property called expand

and a crash

(mgcb-editor-linux:438615): GLib-GIO-ERROR **: 16:28:28.815: Settings schema 'org.gtk.Settings.FileChooser' is not installed

I read Which package includes org.gtk.gtk4.Settings.FileChooser?
that they can only be used with derivations.

I’ve had my shot with the derivation but I cannot wrap my head around the workaround the user mentions.
Has anyone had any similar issue in dotnet?

I would recommend actually packaging the program.
See https://nixos.org/manual/nixpkgs/stable/#dotnet.
There are many examples in nixpkgs as well.

I tried packaging it with various different methods.
In the docs they specify buildDotnetGlobalTool.
I tried creating a package.nix

{ pkgs ? import <nixpkgs> {} }:

pkgs.buildDotnetGlobalTool {
  pname = "dotnet-mgcb-editor";
  version = "3.8.2.1105";

  nugetHash = "sha256-8xfQiZ3utEpmdgKZtKsTWBPzEZdaPIW/XFi5sJWTTd8="; # Replace with the correct hash

  meta = {
    description = "MonoGame Content Builder Editor as a .NET global tool";
    homepage = "https://www.nuget.org/packages/dotnet-mgcb-editor/";
    license = pkgs.lib.licenses.mit;
    platforms = pkgs.lib.platforms.all;
  };
}

but nix build produces

You can invoke the tool using the following command: mgcb-editor
Tool 'dotnet-mgcb-editor' (version '3.8.2.1105') was successfully installed.
Running phase: dotnetFixupHook
@nix { "action": "setPhase", "phase": "dotnetFixupHook" }
Specified binary "dotnet-mgcb-editor" is either not an executable or does not exist!
Looked in /nix/store/wc9vd3ij0f8vwi3ifdgpzfikcamkmbhm-dotnet-mgcb-editor-3.8.2.1105>```

Managed to package the app using the following

{ pkgs ? import <nixpkgs> {} }:

pkgs.buildDotnetGlobalTool {
  pname = "dotnet-mgcb-editor";
  version = "3.8.2.1105";
  nativeBuildInputs = [ 
    pkgs.gtk3
    pkgs.glib
    pkgs.gsettings-desktop-schemas
    pkgs.adwaita-icon-theme
    pkgs.hicolor-icon-theme

  ];  # Ensure gtk3 is available at build time

  nugetHash = "sha256-8xfQiZ3utEpmdgKZtKsTWBPzEZdaPIW/XFi5sJWTTd8="; # Replace with the correct hash

  dotnetFixupHook = ''
    echo '<============ DEBUG START ==============>'
    # Create a new wrapper script that sets the GTK library paths.
    mkdir -p $out/bin
    cat > $out/bin/mgcb-editor <<'EOF'
    #! /usr/bin/env bash
    # Ensure GTK libraries can be found.
    export LD_LIBRARY_PATH=${pkgs.gtk3}/lib:\$LD_LIBRARY_PATH
    # Set the directory for GSettings schemas from both glib and gsettings-desktop-schemas.
    export GSETTINGS_SCHEMA_DIR=${pkgs.glib}/share/glib-2.0/schemas:${pkgs.gsettings-desktop-schemas}/share/glib-2.0/schemas
    # Set XDG_DATA_DIRS so that icon themes and desktop files are available.
    export XDG_DATA_DIRS=${pkgs.hicolor-icon-theme}/share:${pkgs.adwaita-icon-theme}/share:${pkgs.gtk3}/share:\$XDG_DATA_DIRS

    exec dotnet mgcb-editor "$@"
EOF
    chmod +x $out/bin/mgcb-editor

    echo gdk-pixbuf-query-loaders
    echo '<============ DEBUG END ==============>'
  '';

  meta = {
    description = "MonoGame Content Builder Editor as a .NET global tool";
    homepage = "https://www.nuget.org/packages/dotnet-mgcb-editor/";
    license = pkgs.lib.licenses.mit;
    platforms = pkgs.lib.platforms.all;
  };
}

The only issue that persists is the

(mgcb-editor-linux:1491221): GLib-GIO-ERROR **: 19:05:06.328: Settings schema 'org.gtk.Settings.FileChooser' is not installed

Tried different options to fix it with no luck/progress

You need XDG_DATA_DIRS at runtime pointing to the data directories. This is typically achieved through a wrapper. See GNOME section of the Nixpkgs manual for more details.

Also note that we use /share/gsettings-schemas/${name}/glib-2.0/schemas rather than /share/glib-2.0/schemas – that is, /share/gsettings-schemas/${name} is the datadir. We also have a helper for getting the datadir: glib.getSchemaDataDirPath gtk3.