MS Sql tools, buildFHSUserEnv, and /opt folder

I use NixOS version 20.09.

The short story is that I am making a buildFHSUserEnv and the chroot jail do not link from /opt to my package. I do not understand why, as bin, sbin, usr, … are linked to my package.

How do I get a link from /opt to my …-fhs package?

The longer version follows below.

I am trying to install MS SQL tools .deb package on my NixOS machine.

The deb installs, among others, these files under /opt/mssql-tools/share/resources/en_US/:

  • BatchParserGrammar.dfa
  • BatchParserGrammar.llr
  • bcp.rll
  • SQLCMD.rll

Furthermore, the executables expect to find these files using a hard-coded string to /opt/mssql-tools/share/resources/en_US/… (I used less to look in the executable). Thus I thought only a change root jail would do the trick.

I created a

source $stdenv/setup
dpkg -x $src unpacked
mkdir -p $out
cp -r unpacked/* $out/

and a mssql-tools.nix:

let nixpkgs = import <nixpkgs> {};
    stdenv = nixpkgs.stdenv;
in rec {
  pkg = stdenv.mkDerivation {
    name = "dumb-mssql-tools";
    builder = ./;
    dpkg = nixpkgs.dpkg;
    src = nixpkgs.fetchurl {
      url = "";
      sha256 = "0mc12sg4b362lldgg2ilxb7j4ym50g7qlnvs2mk44hja067wsyll";
  mssql-tools = nixpkgs.buildFHSUserEnv {
    name = "mssql-tools";
    targetPkgs = pkgs: [ pkg pkgs.unixODBC pkgs.libuuid ];
    multiPkgs = pkgs: [ pkgs.dpkg ];
    #extraOutputsToInstall = [ "opt" "opt/mssql-tools" ];
    extraBuildCommands = ''
      #cp -r ${pkg.outPath}/usr $out
      cp -r ${pkg.outPath}/opt $out
      find $out | grep opt
      mkdir -p $out/usr/bin
      #ln -s $out/opt/mssql-tools/bin/sqlcmd* $out/usr/bin/sqlcmd
    #runScript = "${pkg}/opt/mssql-tools/bin/sqlcmd-";
    runScript = "bash";

I compile it with:

nix-build -A mssql-tools mssql-tools.nix

and run:


I get:

Unable to load SQLCMD resource file(s)

why? because there is no /opt/mssql-tools folder:

ls /opt/mssql-tools
ls: cannot access '/opt/mssql-tools': No such file or directory

If I do:

ls -l /

I can see that bin, lib, lib32, lib64, sbin and usr are soft-links to mssql-tools-fhs package, but not the opt folder.

So how do I get opt to also be part of the changeroot environment?

Best regards,

Mads Lindstrøm

Found this thread because I had the same problem.

Make sure you don’t have any /opt directory on your host. If you do it will be used instead of the /opt you define in extraBuildCommands