Could NOT find X11 (missing: X11_X11_INCLUDE_PATH X11_X11_LIB) when building Rust crate

Hello!

I have been trying to set up my Rust development environment and when trying to build the glfw package I got that dependency error Could NOT find X11 (missing: X11_X11_INCLUDE_PATH X11_X11_LIB) with the whole trace being:

  --- stderr
  CMake Error at /nix/store/b893ksdqbdpzrdcmms59aq4fgqmh083w-cmake-3.29.2/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
    Could NOT find X11 (missing: X11_X11_INCLUDE_PATH X11_X11_LIB)
  Call Stack (most recent call first):
    /nix/store/b893ksdqbdpzrdcmms59aq4fgqmh083w-cmake-3.29.2/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
    /nix/store/b893ksdqbdpzrdcmms59aq4fgqmh083w-cmake-3.29.2/share/cmake-3.29/Modules/FindX11.cmake:676 (find_package_handle_standard_args)
    CMakeLists.txt:211 (find_package)


  thread 'main' panicked at /home/jtv/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cmake-0.1.51/src/lib.rs:1100:5:

  command did not execute successfully, got: exit status: 1

  build script failed, must exit now

Now I have already tried configuring my shell with the proper dependencies like this:

{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
  buildInputs = [
    pkg-config
    xorg.libX11
    xorg.libXrandr
    xorg.libXinerama
    xorg.libXcursor
    xorg.libXi
    opengl
  ];
}

but that didn’t seem to do the job and I can’t seem to find any useful information relating to this problem online so help would be greatly appreciated and thanks in advance!

Use packages not buildInputs, and you are missing pkgs. in front of each. You may also need pkgs.rustPlatform.bindgenHook. And where are you getting rust from?

It’s possible that you didn’t activate the shell, as you didn’t get a warning that pkgs was missing in the build inputs when you should have.

This was enough for me to successfully build the package:

# shell.nix
{
  pkgs ? import <nixpkgs> { },
}:
pkgs.mkShell {
  buildInputs = with pkgs; [
    pkg-config
    xorg.libX11
    xorg.libXrandr
    xorg.libXinerama
    xorg.libXcursor
    xorg.libXi
    cmake
  ];
}

Just put it in shell.nix and run nix-shell before you build.

Okay thank you so much for the response, turns out when I started nix shell with .envrc I just did nix-shell instead of use nix which caused some weird behavior. With your config it also built successfully so I appreciate the help!

Also probably noteworthy I did basically have your config as the original but removed the .pkg prefix as it didn’t work as an attempt to maybe fix the issue, which was probably partially caused by the misconfigured .envrc

1 Like