I am trying to install cartopy in a poetry virtual environment with system packages provided via nix. Here is my shell.nix file:
{
pkgs ? import <nixpkgs> {}
}:
pkgs.stdenv.mkDerivation rec {
name = "poetry-hvplot";
buildInputs = [
pkgs.glibc
pkgs.libcxx
pkgs.gcc
# pkgs.qt5.full
pkgs.poetry
pkgs.geos
pkgs.snappy
pkgs.graphviz
pkgs.pkgconf
pkgs.geckodriver
pkgs.firefox
];
shellHook = ''
export ENVNAME="${name}";
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${pkgs.graphviz}/lib/pkgconfig
# gcc, snappy, graphviz
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${pkgs.stdenv.cc.cc.lib}/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${pkgs.snappy}/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${pkgs.graphviz}/lib
#export CPATH=$CPATH:${pkgs.stdenv.cc.cc}/include/c++/9.3.0:${pkgs.glibc.dev}/include
#export C_INCLUDE_PATH=$C_INCLUDE_PATH:${pkgs.stdenv.cc.cc}/include/c++/9.3.0:${pkgs.glibc.dev}/include
#export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:${pkgs.stdenv.cc.cc}/include/c++/9.3.0:${pkgs.glibc.dev}/include
#export CFLAGS="-I${pkgs.stdenv.cc.cc}/include/c++/9.3.0 -I${pkgs.glibc.dev}/include"
#export CPPFLAGS="-I${pkgs.stdenv.cc.cc}/include/c++/9.3.0 -I${pkgs.glibc.dev}/include"
'';
}
Once I enter the nix-shell and try to run “poetry add cartopy” which tries to install the package in a virtual environment but finds that gcc is not able to find stdlib.h. As you may have noticed in the shell.nix above I have tried to provide the include paths in multiple ways but of them work and I get the following build error. Any reason this may be happening:
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DACCEPT_USE_OF_DEPRECATED_PROJ_API_H=1 -I/nix/store/bs03sg8b0gq2zr4v252hh9psp780qj5q-python3-3
.8.5/include -I./lib/cartopy -I/home/rowhit/.cache/pypoetry/virtualenvs/hvplot-test-5ZyshoS1-py3.8/lib/python3.8/site-packages/numpy/core/include -I/nix/store/kqq4b77277zjy7
jrdqz9c7cxik32maq7-geos-3.8.1/include -I/home/rowhit/.cache/pypoetry/virtualenvs/hvplot-test-5ZyshoS1-py3.8/include -I/nix/store/bs03sg8b0gq2zr4v252hh9psp780qj5q-python3-3.8
.5/include/python3.8 -c lib/cartopy/trace.cpp -o build/temp.linux-x86_64-3.8/lib/cartopy/trace.o
In file included from /nix/store/rclksjxdjgp6y6qkxyl9m4dx4b9d45zk-gcc-9.3.0/include/c++/9.3.0/ext/string_conversions.h:41,
from /nix/store/rclksjxdjgp6y6qkxyl9m4dx4b9d45zk-gcc-9.3.0/include/c++/9.3.0/bits/basic_string.h:6493,
from /nix/store/rclksjxdjgp6y6qkxyl9m4dx4b9d45zk-gcc-9.3.0/include/c++/9.3.0/string:55,
from /nix/store/rclksjxdjgp6y6qkxyl9m4dx4b9d45zk-gcc-9.3.0/include/c++/9.3.0/bits/locale_classes.h:40,
from /nix/store/rclksjxdjgp6y6qkxyl9m4dx4b9d45zk-gcc-9.3.0/include/c++/9.3.0/bits/ios_base.h:41,
from /nix/store/rclksjxdjgp6y6qkxyl9m4dx4b9d45zk-gcc-9.3.0/include/c++/9.3.0/ios:42,
from lib/cartopy/trace.cpp:659:
/nix/store/rclksjxdjgp6y6qkxyl9m4dx4b9d45zk-gcc-9.3.0/include/c++/9.3.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
75 | #include_next <stdlib.h>
| ^~~~~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------