How do you set the PKG_CONFIG_PATH environment variable to reference the directory containing wayland-client.pc?

How do you set the PKG_CONFIG_PATH environment variable to reference the directory containing wayland-client.pc?

Context

My NixOS installation is running a desktop environment using Wayland. It also has a configuration.nix file with the following pertinent contents:

{ config, pkgs, … }: {

hardware.graphics = {
enable = true;
enable32Bit = true;
};

environment.sessionVariables = rec {
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (with pkgs; [
wayland
pkg-config
]);
PKG_CONFIG_PATH = pkgs.lib.makeLibraryPath (with pkgs; [
wayland
pkg-config
]);
};

}

On this installation, there is a silly little cargo.toml file with the following contents:

[package]
name = “rust-game”
version = “0.1.0”
edition = “2024”

[dependencies]
bevy = “0.18”

When we run the console command cargo run the thread panics:

The system library wayland-client required by crate wayland-sys was not found.
The file wayland-client.pc needs to be installed and the PKG_CONFIG_PATH environment variable must contain its
parent directory.
The PKG_CONFIG_PATH environment variable is not set.

Running the console command find / -name “wayland-client.pc” I get something like:
/nix/store/sj5qy7qbczvdpz8kbgfyqfn3kj5zppyq-wayland-1.24.0-dev/lib/pkgconfig/wayland-client.pc

PKG_CONFIG_PATH should point to the pkgconfig directory, not lib, which makeLibraryPath points it to

{ 
  PKG_CONFIG_PATH = "${lib.getDev wayland}/lib/pkgconfig";
}

A common practice is to set up a per-project shell with something like mkShell,
and let pkg-config’s setup hook handle the environment variables.

mkShell {
  packages = [
    pkg-config
  ];

  buildInputs = [
    wayland
  ];
}