title: Error building PostgreSQL 12 with nix on Big Sur: “stdio.h not found”
body: <p>I'm trying to build postgresql 12 with timescaledb on macOS Big Sur (x86), but the build fails with “error: 'stdio.h' file not found”:</p>
  <pre><code>❯ nix-shell -p 'postgresql_12.withPackages (p: [ p.timescaledb ])'
  these derivations will be built:
    /nix/store/40ln5j15h3393rz6ib3agdjh44zbzq0l-timescaledb-2.1.0.drv
    /nix/store/nr2zamck44wmzfiv1qx069l60xmv3flf-postgresql-and-plugins-12.6.drv
  building '/nix/store/40ln5j15h3393rz6ib3agdjh44zbzq0l-timescaledb-2.1.0.drv'...
  unpacking sources
  unpacking source archive /nix/store/q59w20k2wvr2sr2nzzzs99ka82w3az6i-source
  source root is source
  patching sources
  configuring
  fixing cmake files...
  cmake flags: -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_SKIP_BUILD_RPATH=ON -DBUILD_TESTING=OFF -DCMAKE_INSTALL_LOCALEDIR=/nix/store/963231s8j5fp2zjx5dhnwy1g9yv8p4pp-timescaledb-2.1.0/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/nix/store/963231s8j5fp2zjx5dhnwy1g9yv8p4pp-timescaledb-2.1.0/libexec -DCMAKE_INSTALL_LIBDIR=/nix/store/963231s8j5fp2zjx5dhnwy1g9yv8p4pp-timescaledb-2.1.0/lib -DCMAKE_INSTALL_DOCDIR=/nix/store/963231s8j5fp2zjx5dhnwy1g9yv8p4pp-timescaledb-2.1.0/share/doc/timescaledb -DCMAKE_INSTALL_INFODIR=/nix/store/963231s8j5fp2zjx5dhnwy1g9yv8p4pp-timescaledb-2.1.0/share/info -DCMAKE_INSTALL_MANDIR=/nix/store/963231s8j5fp2zjx5dhnwy1g9yv8p4pp-timescaledb-2.1.0/share/man -DCMAKE_INSTALL_OLDINCLUDEDIR=/nix/store/963231s8j5fp2zjx5dhnwy1g9yv8p4pp-timescaledb-2.1.0/include -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/963231s8j5fp2zjx5dhnwy1g9yv8p4pp-timescaledb-2.1.0/include -DCMAKE_INSTALL_SBINDIR=/nix/store/963231s8j5fp2zjx5dhnwy1g9yv8p4pp-timescaledb-2.1.0/sbin -DCMAKE_INSTALL_BINDIR=/nix/store/963231s8j5fp2zjx5dhnwy1g9yv8p4pp-timescaledb-2.1.0/bin -DCMAKE_INSTALL_NAME_DIR=/nix/store/963231s8j5fp2zjx5dhnwy1g9yv8p4pp-timescaledb-2.1.0/lib -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_OSX_SYSROOT= -DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_STRIP=/nix/store/cay94li1m7s8qiigvp6h30l2gf89ys49-cctools-binutils-darwin-949.0.1/bin/strip -DCMAKE_RANLIB=/nix/store/cay94li1m7s8qiigvp6h30l2gf89ys49-cctools-binutils-darwin-949.0.1/bin/ranlib -DCMAKE_AR=/nix/store/cay94li1m7s8qiigvp6h30l2gf89ys49-cctools-binutils-darwin-949.0.1/bin/ar -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_INSTALL_PREFIX=/nix/store/963231s8j5fp2zjx5dhnwy1g9yv8p4pp-timescaledb-2.1.0 -DSEND_TELEMETRY_DEFAULT=OFF -DREGRESS_CHECKS=OFF -DWARNINGS_AS_ERRORS=OFF
  -- The C compiler identification is Clang 7.1.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /nix/store/8i0yaj3r82kqcdbr453wzzijnszxg4gx-clang-wrapper-7.1.0/bin/clang - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- TimescaleDB version 2.1.0. Can be updated from version 2.0.2
  -- Build type is Release
  -- Install method is 'source'
  -- CMAKE_BUILD_TYPE does not match Debug
  -- Performing Test CC_SUPPORTS_NO_FORMAT_TRUNCATION
  -- Performing Test CC_SUPPORTS_NO_FORMAT_TRUNCATION - Failed
  -- Compiler does not support -Wno-format-truncation
  -- Performing Test CC_STRINGOP_TRUNCATION
  -- Performing Test CC_STRINGOP_TRUNCATION - Failed
  -- Compiler does not support -Wno-stringop-truncation
  -- Performing Test CC_SUPPORTS_IMPLICIT_FALLTHROUGH
  -- Performing Test CC_SUPPORTS_IMPLICIT_FALLTHROUGH - Success
  -- Performing Test CC_SUPPORTS_VISIBILITY_HIDDEN
  -- Performing Test CC_SUPPORTS_VISIBILITY_HIDDEN - Success
  -- Using compiler Clang
  -- Could NOT find Git (missing: GIT_EXECUTABLE)
  -- Using pg_config /nix/store/2dbkk2kv3cb5gzxhyhhxair7c9f6rz9h-postgresql-12.6/bin/pg_config
  -- Compiling against PostgreSQL version 12.6
  -- Using local clang-format
  -- Linter support (clang-tidy) enabled
  -- Assertion checks are OFF
  -- Found OpenSSL: /nix/store/xxmdw2z5cm1rlcl8n9n91q7356542byw-openssl-1.1.1j/lib/libcrypto.dylib (found version &quot;1.1.1j&quot;)
  -- OPENSSL_LIBRARIES: /nix/store/xxmdw2z5cm1rlcl8n9n91q7356542byw-openssl-1.1.1j/lib/libssl.dylib;/nix/store/xxmdw2z5cm1rlcl8n9n91q7356542byw-openssl-1.1.1j/lib/libcrypto.dylib
  -- Using OpenSSL version 1.1.1j
  -- Using nm /nix/store/cay94li1m7s8qiigvp6h30l2gf89ys49-cctools-binutils-darwin-949.0.1/bin/nm
  -- Skipping isolation regress checks since program 'pg_regress' was not found
  -- Skipping isolation regress checks since program 'pg_isolation_regress' was not found
  -- Configuring done
  -- Generating done
  CMake Warning:
    Manually-specified variables were not used by the project:
  
      BUILD_TESTING
      CMAKE_CXX_COMPILER
      CMAKE_EXPORT_NO_PACKAGE_REGISTRY
      CMAKE_INSTALL_BINDIR
      CMAKE_INSTALL_DOCDIR
      CMAKE_INSTALL_INCLUDEDIR
      CMAKE_INSTALL_INFODIR
      CMAKE_INSTALL_LIBDIR
      CMAKE_INSTALL_LIBEXECDIR
      CMAKE_INSTALL_LOCALEDIR
      CMAKE_INSTALL_MANDIR
      CMAKE_INSTALL_OLDINCLUDEDIR
      CMAKE_INSTALL_SBINDIR
      CMAKE_POLICY_DEFAULT_CMP0025
  
  
  -- Build files have been written to: /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build
  cmake: enabled parallel building
  building
  build flags: -j1 -l1 SHELL=/nix/store/l25gl3siwmq6gws4lqlyd1040xignvqw-bash-4.4-p23/bin/bash
  Scanning dependencies of target sqlupdatescripts
  [  0%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/updates/post-update.sql.processed
  [  0%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--2.0.2--2.1.0.sql
  [  1%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--2.0.1--2.1.0.sql
  [  1%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--2.0.0--2.1.0.sql
  [  2%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--2.0.0-rc4--2.1.0.sql
  [  2%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--2.0.0-rc3--2.1.0.sql
  [  3%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--2.0.0-rc2--2.1.0.sql
  [  3%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--2.0.0-rc1--2.1.0.sql
  [  4%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.7.5--2.1.0.sql
  [  4%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.7.4--2.1.0.sql
  [  5%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.7.3--2.1.0.sql
  [  5%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.7.2--2.1.0.sql
  [  6%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.7.1--2.1.0.sql
  [  6%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.7.0--2.1.0.sql
  [  7%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.6.1--2.1.0.sql
  [  7%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.6.0--2.1.0.sql
  [  8%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.5.1--2.1.0.sql
  [  8%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.5.0--2.1.0.sql
  [  9%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.4.2--2.1.0.sql
  [  9%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.4.1--2.1.0.sql
  [ 10%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.4.0--2.1.0.sql
  [ 10%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.3.2--2.1.0.sql
  [ 11%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.3.1--2.1.0.sql
  [ 11%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.3.0--2.1.0.sql
  [ 12%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.2.2--2.1.0.sql
  [ 12%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.2.1--2.1.0.sql
  [ 13%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.2.0--2.1.0.sql
  [ 13%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.1.1--2.1.0.sql
  [ 14%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--1.1.0--2.1.0.sql
  [ 14%] Built target sqlupdatescripts
  Scanning dependencies of target sqlfile
  [ 14%] Generating /tmp/nix-build-timescaledb-2.1.0.drv-0/source/build/sql/timescaledb--2.1.0.sql
  [ 14%] Built target sqlfile
  Scanning dependencies of target timescaledb
  [ 15%] Building C object src/CMakeFiles/timescaledb.dir/agg_bookend.c.o
  /nix/store/2dbkk2kv3cb5gzxhyhhxair7c9f6rz9h-postgresql-12.6/include/server/c.h:59:10: error: 'stdio.h' file not found [clang-diagnostic-error]
  #include &lt;stdio.h&gt;
           ^
  1 error generated.
  Error while processing /tmp/nix-build-timescaledb-2.1.0.drv-0/source/src/agg_bookend.c.
  make[2]: *** [src/CMakeFiles/timescaledb.dir/build.make:82: src/CMakeFiles/timescaledb.dir/agg_bookend.c.o] Error 1
  make[1]: *** [CMakeFiles/Makefile2:950: src/CMakeFiles/timescaledb.dir/all] Error 2
  make: *** [Makefile:149: all] Error 2
  builder for '/nix/store/40ln5j15h3393rz6ib3agdjh44zbzq0l-timescaledb-2.1.0.drv' failed with exit code 2
  cannot build derivation '/nix/store/nr2zamck44wmzfiv1qx069l60xmv3flf-postgresql-and-plugins-12.6.drv': 1 dependencies couldn't be built
  error: build of '/nix/store/nr2zamck44wmzfiv1qx069l60xmv3flf-postgresql-and-plugins-12.6.drv' failed
  </code></pre>
  <p>It looks like cmake is called, but is not able to find <code>stdio.h</code>. How can I debug/fix this?</p>
  <p>(What I <em>actually</em> want to build is <code>'postgresql_12.withPackages (p: [ (p.timescaledb.overrideDerivation (old: { cmakeFlags = [ &quot;-DSEND_TELEMETRY_DEFAULT=OFF&quot; &quot;-DREGRESS_CHECKS=OFF&quot; &quot;-DAPACHE_ONLY=true&quot; ]; })) ])'</code>.)</p>