RStudio can't install data.table

Yesterday I installed NixOS and currently am configuring the system. As I need RStudio I successfully installed that in my configuration.nix. However, I have not been able to install the R-packages data.table within RStudio. I receive the following output:

fwrite.c:10:10: fatal faultt: zlib.h: No such file or directory
   10 | #include <zlib.h>      // for compression to .gz
      |          ^~~~~~~~
compilation is terminated

As it asks for the package zlib I installed that in the nix-env. However, data.table still not succesfully install. I have no problem installing other R-packages such as Tidyverse, purrr, etc.
What am I doing wrong? Do I need to install those packages with rstudioWrapper based on the wiki

Did this get solved? I’m having a similar problem. When I try to build an empty Haskell project with aws among the build-depends in the project’s .cabal file, I get this error:

Configuring library for zlib-0.6.2.3..
cabal: Missing dependency on a foreign library:
* Missing (or bad) header file: zlib.h
* Missing (or bad) C library: z

My NixOS config includes all of these package:

haskellPackages.zlib
zlib
zlib.dev

@Viev The headers are probably not installed when using nix-env.

To both: R/RStudio and GHC are treated as compilers/interpreters, so zlib is not a dependency of these, but rather of your program that you build using these tools.
In the Nix world this boils down to:

  1. Create default.nix/shell.nix for your project.
  2. Define zlib in the buildInputs of your project.

See also https://github.com/NixOS/nixpkgs/pull/101423#pullrequestreview-515854728 where this was discussed for GHDL.

Thanks, @wamserma! That seems to have done the trick? But your answer generated two questions:

What’s special about zlib?

I use GHC all the time with lots of external dependencies. SuperCollider, for instance, is a giant program. Yet this is the first time I’ve had to write a default.nix file. Is that because zlib is a collection of C headers, and those are somehow treated differently than other stuff on my system?

Why does an empty default.nix file work?

The first default.nix configuration I found that let me open GHCI without errors or warnings was this:

with import <nixpkgs> { };
mkShell rec {
  buildInputs = [ zlib ];

  # Monkey-pasted from
  #   https://discourse.nixos.org/t/shared-libraries-error-with-cabal-repl-in-nix-shell/8921/9?u=jeffreybenjaminbrown
  LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
}

But now, if I change the default.nix file to be only the following:

with import <nixpkgs> { };
mkShell rec {
  buildInputs = [ ];
}

it still works! Or almost. It only gives me the following warning when I run cabal repl (to get to GHCI):

<no location info>: warning: [-Wmissed-extra-shared-lib]
    libz.so: cannot open shared object file: No such file or directory
    It's OK if you don't want to use symbols from it directly.
    (the package DLL is loaded by the system linker
     which manages dependencies by itself).

Moreover, I get the same behavior even if I don’t run nix-shell before cabal repl.

There is nothing special about zlib. It is a dependency of your code, not a dependency of any of the libs you use. As it is pulled in only when your code is compiled, nix required you to state this dependency explicitly.
For the cabal repl issues, maybe someone more familiar with the Haskell stuff can help?

That seems like the behavior changed because you changed something else? Perhaps removing zlib from your system config? The previous error complains that zlib.h is missing (i.e. it can find the library but can’t use it because the header is missing since nix doesn’t expose it when used in systemPackages), whereas the new one complains that the shared library is missing (i.e., the library isn’t installed at all).

It’s best to think of a shell.nix as equivalent to a file where you define all the things you want to install that you’d use *-dev packages for in ubuntu land. It’s nice, because those dependencies can be cleaned up easily with nix-collect-garbage.