How to expose header files for development?

Sorry for the noob question, but I’ve tried searching and only found suggestions like “just use nix-shell”, which still leaves me lost.

I need to use a very specific set of versioned python packages for my work that I install in a venv with pip install requirements.txt. Most packages work fine, but I’m having trouble with ones that require header files from installed system packages, e.g.:

      ./psycopg/psycopg.h:36:10: fatal error: libpq-fe.h: No such file or directory
         36 | #include <libpq-fe.h>

Could any one point me in the right direction?

Development headers are not exposed by default, but they’re bundled with a different output of every package that has them.

To make them available, you need to install the package in question in a nix shell, as the nix shell will set your environment up correctly so gcc can find the headers.

Something like this should do the trick in this case:

# shell.nix
{ pkgs, ... }: pkgs.mkShell {
  packages = with pkgs; [

Then you just enter the shell by running nix-shell et voilá, you have a perfectly working development environment with a clearly traceable version of libpqxx. And if you ever need to give someone else installation instructions, you can just look in this shell.nix and tell them all the dependencies, since NixOS guarantees that the list is exhaustive (except maybe for kernel and graphics stuff, because that’s messy).

YMMV with python stuff however, their build systems tend to be a bit broken.

1 Like

Thanks! I was able to get it to build with this:

{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
  packages = [ pkgs.libpqxx ];
  inputsFrom = [ pkgs.libpqxx ];
1 Like