Using rix/nix on Debian Bookworm

Clocks From Pexels Castorly Stock

I decided it was time to start using nix as a configuration manager. I’m planning on using it on top of a Debian OS. In the first instance, I just want to control my analysis environment, that is R and it’s associated packages. But there is one subtlety, I am using the RPostgres package which implies that I need some control of some PostgreSQL header files in order to install and load the package. However, I don’t think I want to run the server in this environment - the server could ideally be on a completely different machine. Nevertheless, nix should let me control the postgres version so I can make sure the packages are compiled against the correct header files. At least, that’s what I want to happen.

First, rix suggests you use a specific nix installation from Determinate Systems

curl --proto '=https' --tlsv1.2 -sSf \
    -L https://install.determinate.systems/nix | \
     sh -s -- install

Now, this is the instruction I’m not sure about; you install the cachix client in order to install binary versions of many R packages:

nix-env -iA cachix -f https://cachix.org/api/v1/install

Then you just “use” the cache:

cachix use rstats-on-nix

This wouldn’t run and helpfully told me to run

echo "trusted-users = root phewson" | sudo tee -a /etc/nix/nix.conf && sudo pkill nix-daemon

Useful notes:

  • ǹix-collect-garbage does a bit of tidying up
  • nix-shell --show-trace does what it says
  • I need to find more out about nix-flakes, at the moment I have a folder specific default.nix which is activated by nix-shell
  • There is a horribly circular first step where you need some R in your nix environment in order to run rix. But once that’s done it is very helpful about writing config files.

I wasted a lot of time trying to install the RPostgreSQL library, I should have just installed the RPostgres library. I was hunting for a PQfmod symbol in libpq.so which was all a waste of time. I need to check which library I use through all my analytic scripts, and indeed check whether I need rpostgis as I think sf has all I need to read spatial data given a connecton from RPostgreSQL.