How to expose package contents on the path?

I’d like to compile some code that is looking for GL/gl.h, and of course can’t find it.

I know this file exists in the libGL package, but I haven’t figured out how to expose it’s contents onto the path in a shell or devshell. I’ve tried opening that package directly in nix shell and nix devshell, as well as writing a flake containing a devshell that requires it. In every case, I can’t find any indication of the package files being available, and the compiler can’t find it on the path.

What is the correct way of making these package contents available for the compiler to use?

For packaging, you would put libGL in the buildInputs of your derivation. Similar, if you are defining your development shell via Flakes.

For a one-off-compile, you can use nix-shell -p libGL.

I’ve tried both of those, but can’t find where it’s actually putting the files. /usr/include/ doesn’t exist, and the compiler still complains that GL/gl.h isn’t on the path.

This is the devshell I tried:

{
  description = "GameDev shell";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { nixpkgs, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; };
      in {
        devShells = {
          default = pkgs.mkShell {
            buildInputs = [
              pkgs.libGL    # also tried pkgs.libGL.dev
            ];
          };
        };
      }
    );
}

I’m happy to point the compiler to a specific location, if I know what that location is. I can see libGL in /nix/store/ but of course I can’t rely on any paths there.

You have the paths in NIX_CFLAGS_COMPILE and NIX_LDFLAGS. Just pass these along with your CFLAGS and LDFLAGS.

Ah! Thank you, I wasn’t aware of NIX_CFLAGS_COMPILE, I was looking for an actual path or symlink.

As an aside, how did you know about this flag? I assume it’s documented somewhere, but I’ve been searching for days on this problem and couldn’t find a reference to it.

env | grep libGL

Tbh, I cannot pinpoint when or how I came first came across this variables. I think it was when looking into build failures of OP-TEE that were specific to a nix-shell.

A short explanation of these variables can be found in the Wiki: C - NixOS Wiki

1 Like

Thanks, I appreciate the link!