On NixOS, I'm using a FHS environment to supply libraries (unixODBC and sqlite-odbc) to libreoffice.

{ pkgs ? import <nixpkgs> {} }:
( pkgs.buildFHSUserEnv {
  name = "odbc-sqlite-libreoffice";
  targetPkgs = pkgs: with pkgs; [libreoffice unixODBC unixODBCDrivers.sqlite];

However, this works in conjunction with the configuration file /etc/odbcinst.ini, which is generated from the environment.unixODBCDrivers option, but I can't figure out how to pass it to the chroot's filesystem.

I tried using the extraBuildCommands option:

extraBuildCommands = "ln -s /host/etc/odbcinst.ini /etc/odbcinst.ini";

but it doesn't seem to be the right way, and it results in an error: ln: failed to create symbolic link '/etc/odbcinst.ini': Permission denied

How would I go about placing the config file? I imagine there should be a way to create an environment based on a particular system configuration/generation.

If there are other ways to configure ODBC and SQLite on NixOS, they are also very welcome.

  • Why do you need to use buildFHSUserEnv? Did installing libreoffice and unixODBC normally and then using the environment.unixODBCDrivers option, not work? – Emmanuel Rosa May 23 at 12:08
  • @EmmanuelRosa No, it doesn't work when they're just installed side by side, nor does it when they're included side by side in an stdenv.mkDerivation environment. I imagine why libreoffice can find the libraries in a buildFHSUserEnv is because it looks for the libraries in a standard, hardcoded, FHS-compliant location. – user142852 May 24 at 3:05

So I decided to look into the source, since the documentation is pretty terrible.

Apparently, if you add to buildTargets a derivation outputting files in /etc or /var folders, buildFHSUserEnv will automatically copy them to their respective places in the FHS environment.

For my situation, I wrote a simple derivation to place a config file to $out/etc/odbcinst.ini, and added it to buildTargets:

odbcinst = pkgs.stdenv.mkDerivation {
  name = "odbcinst";
  buildCommand = ''
    mkdir -p $out/etc
    cp $odbcinst $out/etc/odbcinst.ini
  odbcinst = pkgs.writeTextFile {
    name = "odbcinst-ini";
    text = ''
      Description = ODBC driver for SQLite
      Driver = /lib/libsqlite3odbc.so

And lo and behold:

[...]$ nix-shell odbc.nix 
odbc-chrootenv:[...]$ ls /etc
asound.conf  hosts   mtab       pam.d      resolv.conf  sudoers
default      localtime   nsswitch.conf  passwd     shadow   sudoers.d
fonts        login.defs  odbcinst.ini   profile    ssl      zoneinfo
group        machine-id  os-release profile.d  static

Libreoffice recognized the file, but then it gave me some inscrutable error about not being able to read the sqlite library. So, I'm giving up and running it in an Ubuntu VM.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.