Pkg-config not working when trying to use gtk-rs

I’m trying to develop an application with gtk-rs but I’m getting errors such as this when trying to run the default hello world with the gtk-rs package installed.
error

warning: `PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1" PKG_CONFIG_PATH="/nix/store/gh8a7n87wjm91bgicchvisykz25gippi-dbus-1.14.8-dev/lib/pkgconfig:/nix/store/c9dqnnhwdy64zqwpjkzk1s81zvz0infj-expat-2.5.0-dev/lib/pkgconfig" "pkg-config" "--libs" "--cflags" "gobject-2.0" "gobject-2.0 >= 2.66"` did not exit successfully: exit status: 1

error: failed to run custom build command for `gobject-sys v0.18.0`

Caused by:
  process didn't exit successfully: `/home/carl/Documents/Code/seashell/target/debug/build/gobject-sys-371cc603286ba0d8/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=GOBJECT_2.0_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:warning=`PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1" PKG_CONFIG_PATH="/nix/store/gh8a7n87wjm91bgicchvisykz25gippi-dbus-1.14.8-dev/lib/pkgconfig:/nix/store/c9dqnnhwdy64zqwpjkzk1s81zvz0infj-expat-2.5.0-dev/lib/pkgconfig" "pkg-config" "--libs" "--cflags" "gobject-2.0" "gobject-2.0 >= 2.66"` did not exit successfully: exit status: 1
  error: could not find system library 'gobject-2.0' required by the 'gobject-sys' crate

This is what my shell.nix looks like:

{ pkgs ? import <nixpkgs> {} }:
  pkgs.mkShell {
    buildInputs = with pkgs; [
        dbus
    ];

    nativeBuildInputs = with pkgs.buildPackages; [ 
	pkg-config
	dbus
    ];
}

when I run echo $PKG_CONFIG_PATH it echos nothing

The *-sys crates typically require system libraries to be available. In this case, gobject-2.0 is part of the glib package so you should add glib to buildInputs.

Thanks. That fixed most of the errors I had. I did that for all “*-sys” that caused errors but theres one I can’t seem to find the package for which is “gdk4-sys”.

This is the config now:

{ pkgs ? import <nixpkgs> {} }:
  pkgs.mkShell {
    buildInputs = with pkgs; [
        dbus
    ];
    # nativeBuildInputs is usually what you want -- tools you need to run
    nativeBuildInputs = with pkgs.buildPackages; [ 
	pkg-config
	dbus
	glib
	pango
	gdk-pixbuf
        graphene
    ];
    
}

Unlike with GTK 3, GDK 4 is part of gtk4 library. You can use nix-locate gtk4.pc from nix-index to find the package containing the relevant pkg-config file.

thank you so much for all the help. took a while to index but turns out i didnt need to. I just added gtk4 to the shell.nix.

The final working shell.nix is this:

{ pkgs ? import <nixpkgs> {} }:
  pkgs.mkShell {
    buildInputs = with pkgs; [
        dbus
    ];
    # nativeBuildInputs is usually what you want -- tools you need to run
    nativeBuildInputs = with pkgs.buildPackages; [ 
        pkg-config
        dbus
        glib
        pango
        gdk-pixbuf
        graphene
        gtk4
    ];
    
}