Building binary package with alternate glibc

Hi, I’m relatively new to NixOS, and I am trying to do something I realize is a bit advanced. Nonetheless…

I have a proprietary binary in the form of a .deb package. As it turns out it was compiled for Ubuntu 18.04 and no longer works for any subsequent version of Ubuntu (nor Debian or NixOS for that matter). AFAICT, Ubuntu 18.04 has a patched version of glibc, in particular is has the pthread lib using a GLIBC_PRIVATE version.

So while I was able to create a derivation for this proprietary package, one of the executables will not run because of the above issue. I figured out how to build against a number of older glibc versions that are in nixpkgs, but none worked.

So, I downloaded Ubuntu’s package from 18.04 (libc6_2.27-3ubuntu1.6_amd64.deb), and I was also able to create a derivation for that – apparently I was even able to get it into my nix/store as nix/store/l742nx18wnpdrsps81jpzs396w1is3nx-glibc-2.27-3ubuntu1.6 by adding an overlay to my /etc/nixos/configuration.nix file.

But now I am stuck. I don’t know how to tell my derivation for the proprietary package to use the Ubuntu version of glibc.

Here is my derivation for libc2.27-3ubuntu1.6.deb:

{ stdenv
, lib
, dpkg
, gcc-unwrapped
, autoPatchelfHook 
}:

let
  version = "2.27-3ubuntu1.6";
  src = ./libc6_2.27-3ubuntu1.6_amd64.deb;

in stdenv.mkDerivation {
  pname  = "glibc";
  name   = "glibc-${version}";
  system = "x86_64-linux";

  inherit src;

  nativeBuildInputs = [
    autoPatchelfHook
    dpkg
  ];

  buildInputs = [
    gcc-unwrapped
  ];

unpackPhase = "true";

installPhase = ''
    mkdir -p $out
    dpkg -x $src $out
  '';

  meta = with lib; {
    description = "Ubuntu 18.04 patched Gnu Lib C";
    homepage = https://www.ubuntu.com;
    license = licenses.gpl3;
    platforms = [ "x86_64-linux" ];
  };

Here is my overlay from configuration.nix:

  nixpkgs.overlays = [
    (
      self: super:
      {
        glibcUbuntu = super.callPackage /home/common/glibc2.27-3ubuntu1.6 {};
      }
    )
  ];

And here is my derivation for the proprietary package:

{ stdenv
, qtbase
, wrapQtAppsHook
, dpkg
, glibc
, gcc-unwrapped
, autoPatchelfHook 
}:

let
  version = "3.10.1";
  src = ./foo-3.10-1.x86_64.deb;

  # This doesn't work.
  over-pkgs = import ( "/home/common/glibc2.27-3ubuntu1.6" ) {};
  old-glibc = over-pkgs.glibc;

  # Note: This is how I tried old versions of glibc in nixpkgs.
  #old-pkgs = import (builtins.fetchTarball {
  #  url = "https://github.com/NixOS/nixpkgs/archive/a9eb3eed170fa916e0a8364e5227ee661af76fde.tar.gz";
  #}) {}; 
  #old-glibc = old-pkgs.glibc;

in stdenv.mkDerivation {
  name = "foo-${version}";
  system = "x86_64-linux";

  inherit src;

  nativeBuildInputs = [
    autoPatchelfHook
    dpkg
    wrapQtAppsHook
  ];

  buildInputs = [
    old-glibc   # was `glibc`
    gcc-unwrapped
    qtbase
  ];
        
  unpackPhase = "true";

  installPhase = ''
    mkdir -p $out
    dpkg -x $src $out
  '';

  meta = with stdenv.lib; {
    description = "Foo Proprietary Package";
    homepage = https://www.foo.com;
    license = {
        fullName = "Foo's Proprietary License";
        url = "https://foo.com";
        free = false;
    };
    maintainers = with stdenv.lib.maintainers; [ ];
    platforms = [ "x86_64-linux" ];
  };

Finally my default.nix for it (only thing unique about this is b/c of Qt 5 dependency):

{ pkgs ? import <nixpkgs> {} } :

pkgs.libsForQt5.callPackage ./derivation.nix {}

I feel like I am very close to getting this all building right (remains an open question whether if it will all run right), but I can’t quite figure it out.

Any help is much appreciated.