How to provide `alsa.pc` to environment?

That’s the error log of my cargo clippy inside a rust project:

    Checking bevy_render v0.14.2
    Checking matchers v0.1.0
   Compiling alsa-sys v0.3.1
   Compiling nix v0.29.0
error: failed to run custom build command for `alsa-sys v0.3.1`

Caused by:
  process didn't exit successfully: `/home/azrael/projects/rust/bevy_app/target/debug/build/alsa-sys-174f5531b95e51b6/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=ALSA_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=ALSA_STATIC
  cargo:rerun-if-env-changed=ALSA_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  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

  --- stderr
  thread 'main' panicked at /home/azrael/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alsa-sys-0.3.1/build.rs:13:18:

  pkg-config exited with status code 1
  > PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --libs --cflags alsa

  The system library `alsa` required by crate `alsa-sys` was not found.
  The file `alsa.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.

  HINT: if you have installed the library, try setting PKG_CONFIG_PATH to the directory containing `alsa.pc`.

  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

That’s my cargo.toml:

[package]
name = "bevy_stuff"
version = "0.1.0"
edition = "2021"
authors = ["GueLaKais <koroyeldiores@gmail.com>"]
description = "My personal Bevy project"
readme = "README.md"
repository = "https://gitlab.com/rust_projects3505446/bevy_app"
license-file="LICENSE"
keywords = ["bevy", "game", "game engine", "gamedev","graphics"]
categories = ["game-development", "graphics", "gamedev"]
exclude = ["/target","/images",".*"]

[workspace]
resolver = "2"
members = [ "egui_stuff","physics_2d", "physics_3d", "urdf_loader"]

[workspace.dependencies]
bevy = {version="0.14.2", features=["dynamic_linking"]}
rand = "0.8.5"

[dependencies]
bevy = {workspace=true, features=["dynamic_linking"]}
rand = {workspace=true}
[profile.dev]
opt-level = 1

[profile.dev.package."*"]
opt-level = 3

[[bin]]
name = "movable_circle"
path = "src/movable_circle.rs"

[[bin]]
name="mouse_red_dot_draw"
path="src/mouse_red_dot_draw.rs"

[[bin]]
name = "movable_with_pos"
path = "src/movable_with_pos.rs"

[[bin]]
name = "movable_with_entitys"
path = "src/movable_with_entitys.rs"

[[bin]]
name = "movable_window"
path = "src/movable_with_window_size.rs"

[[bin]]
name = "position_component"
path = "src/fixed_position_component.rs"

[[bin]]
name = "nodebundle_fixed"
path = "src/nodebundle_fixed.rs"

[[bin]]
name = "ui1"
path= "src/ui1.rs"

Please share any nix code you used as well

Of course:
my config.nix:

{ config, pkgs, ... }:
let
  nixvim = import (builtins.fetchGit { url = "https://github.com/nix-community/nixvim"; });
in
let
  rosDocker = import (
    builtins.fetchGit { url = "https://gitlab.com/docker5348/ros2_main_dev_container"; }
  );
in
{
  imports = [
    /etc/nixos/hardware-configuration.nix
  ];
  nix = {
    gc = {
      automatic = true;
      dates = "daily";
    };
    settings = {
      auto-optimise-store = true;
      experimental-features = [
        "nix-command"
        "flakes"
      ];
    };
  };

  # paste your boot config here...
  boot.loader = {
    systemd-boot.enable = true;
    efi.canTouchEfiVariables = true;
  };

  virtualisation.docker.enable = true;
  networking = {
    firewall = {
      enable = true;
      allowedTCPPorts = [ ];
      allowedUDPPorts = [ ];
    };
    hostName = "Azrael";
    networkmanager.enable = true;
  };

  # edit as per your location and timezone
  time.timeZone = "Europe/Berlin";

  i18n = {
    defaultLocale = "en_GB.UTF-8";
    extraLocaleSettings = {
      LC_ADDRESS = "de_DE.UTF-8";
      LC_IDENTIFICATION = "de_DE.UTF-8";
      LC_MEASUREMENT = "de_DE.UTF-8";
      LC_MONETARY = "de_DE.UTF-8";
      LC_NAME = "de_DE.UTF-8";
      LC_NUMERIC = "de_DE.UTF-8";
      LC_PAPER = "de_DE.UTF-8";
      LC_TELEPHONE = "de_DE.UTF-8";
      LC_TIME = "de_DE.UTF-8";
      LC_CTYPE = "en_US.utf8"; # required by dmenu don't change this
    };
  };

  services = {
    libinput.enable = true;
    printing.enable = true;
    signald = {
      enable = true;
      user = "azrael";
    };
    xserver = {
      enable = true;
      displayManager = {
        sessionCommands = "xhost si:localuser:root";
      };
    }; # xserver
    gvfs.enable = true;
    gnome.gnome-keyring.enable = true;
    blueman.enable = true;
    pipewire = {
      enable = true;
      alsa = {
        enable = true;
        support32Bit = true;
      };
      pulse.enable = true;
    };
  };
  nixpkgs = {
    config = {
      allowUnfree = true;
      pulseaudio = true;
      permittedInsecurePackages = [
        "freeimage-unstable-2021-11-01"
      ];
    };
  };

  users = {
    defaultUserShell = pkgs.nushell;
    users.azrael = {
      isNormalUser = true;
      description = "azrael";
      extraGroups = [
        "networkmanager"
        "wheel"
        "docker"
      ];
    };
  }; # users

  environment = {
    localBinInPath = true;
    variables = {
      SRC_ENDPOINT = "https://sourcegraph.example.com";
      SRC_SRC_ACCESS_TOKEN = "'cat ${config.users.users.azrael.home}/sourcegraphToken'";
    };
    shellAliases = {
      sudo = "sudo ";
      nixos_list_generations = "sudo nix-env --list-generations --profile /nix/var/nix/profiles/system";
      nixosRebuild = "sudo nixos-rebuild switch";
      dockerRmContainters = "docker ps -a | awk '{print $NF}' | while read -r container_name; do docker rm $container_name; done";
      dockerRmImages = "docker image ls --quiet --no-trunc | while read -r image_id; do docker image rm $image_id; done";
    };
    systemPackages = with pkgs; [
      alsa-lib
      grim # screenshot functionality
      slurp # screenshot functionality
      wl-clipboard # wl-copy and wl-paste for copy/paste from stdin / stdout
      mako # notification system developed by swaywm maintainer
      alacritty
      alacritty-theme
      bat
      bluez
      bluez-tools
      cargo
      catimg
      clang
      curl
      cmake
      cytoscape
      docker
      fd
      firefox
      fuse
      gcc
      glab
      glibc
      git
      gimp
      gnome.gnome-keyring
      gr-framework
      htop
      inkscape
      jabref
      jql
      julia
      just
      kate
      lazygit
      libclang
      lld_18
      mc
      networkmanagerapplet
      neovim
      nixfmt-rfc-style
      nodejs_22
      pasystray
      obsidian
      openjdk
      openscad-unstable
      pkg-config
      polkit_gnome
      pulseaudioFull
      python312
      python313
      python312Packages.polars
      python312Packages.numpy
      python312Packages.scipy
      python312Packages.pip
      python312Packages.ortools
      ravedude
      ripgrep
      roboto
      rustc
      rustup
      steam
      signald
      signal-desktop-beta
      tectonic
      tree
      tree-sitter
      thunderbird
      typst
      typstfmt
      typst-lsp
      ucs-fonts
      unetbootin
      unrar
      unzip
      uv
      vcstool
      vim
      vscode
      wget
      xclip
      xorg.xhost
      xorg.libX11
      x11docker
      zip
      (vscode-with-extensions.override {
        vscodeExtensions =
          with vscode-extensions;
          [
            bbenoist.nix
            ms-azuretools.vscode-docker
            ms-python.python
            ms-toolsai.jupyter
            ms-toolsai.jupyter-keymap
            ms-toolsai.jupyter-renderers
            ms-toolsai.vscode-jupyter-slideshow
            ms-toolsai.vscode-jupyter-cell-tags
            ms-vscode-remote.remote-ssh
            serayuzgur.crates
            tamasfe.even-better-toml
          ]
          ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [
            {
              name = "remote-ssh-edit";
              publisher = "ms-vscode-remote";
              version = "0.47.2";
              sha256 = "1hp6gjh4xp2m1xlm1jsdzxw9d8frkiidhph6nvl24d0h8z34w49g";
            }
          ];
      })
    ];
  }; # environment

  programs = {
    dconf.enable = true;
    firefox = {
      enable = true;

    };
    git.enable = true;
    neovim = {
      enable = true;
      defaultEditor = true;
    };
    ssh.startAgent = true;
    steam = {
      enable = true;
      remotePlay.openFirewall = true;
      dedicatedServer.openFirewall = true;
    };
    thunar.enable = true;
    sway = {
      enable = true;
      wrapperFeatures.gtk = true;
    };
  }; # programs

  security = {
    polkit.enable = true;
    rtkit.enable = true;
  };

  systemd = {
    user.services.polkit-gnome-authentication-agent-1 = {
      description = "polkit-gnome-authentication-agent-1";
      wantedBy = [ "graphical-session.target" ];
      wants = [ "graphical-session.target" ];
      after = [ "graphical-session.target" ];
      serviceConfig = {
        Type = "simple";
        ExecStart = "${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1";
        Restart = "on-failure";
        RestartSec = 1;
        TimeoutStopSec = 10;
      };
    };
  }; # systemd

  hardware.bluetooth.enable = true;

  # Don't touch this
  system = {
    activationScripts = {
      script.text = ''
        mkdir -p ${config.users.users.azrael.home}/{ros2_ws,microros_ws,ros2_debug}/src
      '';
    };
    stateVersion = "unstable";
  };
}

See my other answer, you really want a shell.nix, and remove all the compilers/libs from your config

It might be too late for the original asker, but since this is likely to come up via search here are a few thoughts.

First for the alsa.pc (pkg-config) you want to use pkgs.alsa-lib.dev.

Second to get a working shell I prefer to define a flake with all the dependencies including LD_LIBRARY_PATH and use nix develop. For a simple ‘hello world’ bevy program that uses DefaultPlugins (and thus requires working GPU drivers among other libraries) the following flake has worked for me:

{
  description = "Bevy-based hello world";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    oxalica.url = "github:oxalica/rust-overlay";
  };

  outputs = { self, nixpkgs, flake-utils, oxalica }:
    with flake-utils.lib;
    eachSystem allSystems (system:
      let
        pkgs = nixpkgs.legacyPackages.${system}.extend oxalica.overlays.default;
      in rec {

        packages = {
          bevy-program = let
            rustPlatform = pkgs.makeRustPlatform {
              cargo = pkgs.rust-bin.stable.latest.minimal;
              rustc = pkgs.rust-bin.stable.latest.minimal;
            };
          in rustPlatform.buildRustPackage rec {
            name = "bevy-hello-world";
            src = self;
            nativeBuildInputs = with pkgs; [ pkg-config ];
            buildInputs = with pkgs; [
                            alsa-lib.dev
                            udev.dev 
                            xorg.libX11
                            xorg.libXrandr
                            xorg.libXcursor
                            xorg.libxcb
                            xorg.libXi
                            wayland
                            libxkbcommon
                            libxkbcommon.dev
                            vulkan-loader
                            vulkan-tools
                            glfw
                            xorg.xf86videoamdgpu  # notice this line might not match your needs or desires
            ];
            cargoLock = { lockFile = ./Cargo.lock; };
            LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;
          };
        };
        defaultPackage = packages.bevy-program;
        formatter = pkgs.nixfmt;
      });
}

The nix build . of the flake is slow as molasses even for rebuilds, but for development purposes we can work faster by using nix develop:

Projects/bevy-hello-world% nix develop
warning: Git tree '/home/tommd/Projects/bevy-hello-world' is dirty

[~/Projects/bevy-hello-world]$ cargo run 
...