by PaulDavisThe1st · 6y ago · 0 comments
We build and distribute Ardour (a cross-platform open source DAW) in a single package that runs on every Linux distribution that has libc, libstdc++, and some version of Xlib.
Every Linux distribution that is, except NixOS. They decided to patch the runtime linker so that the approach usable on every other Linux distro breaks there.
This says something about NixOS, and presumably Nix too, though I'm not sure what.
For anyone curious, this wiki page describes how to package and run some precompiled binaries on NixOS, particularly the section "The Dynamic Loader": https://nixos.wiki/wiki/Packaging/Binaries
NixOS tries to insist that programs reference only other paths within the nix store (e.g. /nix/store/9rabxvqbv0vgjmydiv59wkz768b5fmbc-glibc-2.30/lib64/ld-linux-x86-64.so.2 which is a specific version built by a specific compiler, rather than /lib64/ld-linux-x86-64.so.2). This is the source of the per-program isolation that enables all the nifty features of NixOS.
NixOS _does_ make exceptions to that though, for example providing both /bin/sh and /usr/bin/env at those paths.
Note that the way we do things is not unique - Firefox has been packaged this way by the Mozilla Foundation for years. We consider ourselves closer to a "traditional ISV" than merely the provider of source code to the open source community (though obviously, we play the latter roll too).
We don't have the resources to spend on a nixOS-specific package, nor the desire. Fortunately, of course, nixOS users can create suitable packages for nixOS, and I think they are.
It just says something that out of the myriad flavors of Linux, nixOS is the only one that has broken this rather old concept for packaging software from ISVs.
But please, carry on! Seems interesting enough.
They do eliminate any ability to automatically find libraries, and the dynamic loader does not exist at the path where it exists on most other distros, which means binaries linked elsewhere will not run unmodified on nixos.
The binary's .interp section indicates which dynamic linker must be used. On a regular Linux distribution, you will find that this is a global path:
$ readelf -p .interp $(which cp)
String dump of section '.interp':
[ 0] /lib64/ld-linux-x86-64.so.2
No global library paths such as /lib or /lib64 exists on NixOS. This is one of the reasons why binaries compiled on other Linux distributions, such as Ubuntu, do not work out of the box. And you have to use patchelf to change the dynamic loader's path.Instead, the dynamic loader of the glibc version that a program was built against is used:
$ readelf -p .interp $(which cp)
String dump of section '.interp':
[ 0] /nix/store/jx19wa4xlh9n4324xdl9rjnykd19mmq3-glibc-2.30/lib/ld-linux-x86-64.so.2Edit: I assume you can't do it very well system-wide because individual packages might need conflicting versions. Okay. Has something like runtime injection been considered? What are the trade-offs here? (I think it's fairly obvious that I'm not very familiar with the whole matter yet).