Nix is a lie, and that’s ok

Nix is a lie, and that’s ok

Engineering·2 min read·via LobstersOriginal source →

Takeaways

  • Nix was designed to avoid the Filesystem Hierarchy Standard (FHS) for reproducibility, but practical needs have led to a compromise.
  • The introduction of a global path for graphics drivers in NixOS highlights the tension between purity and usability.
  • Workarounds exist for users on non-NixOS distributions, but they come with their own set of challenges.

Nix is a Lie, and That’s OK: The Paradox of Purity in Package Management

The Purity Principle

When Eelco Dolstra, the architect of Nix, first introduced this package management system, he had a vision: a world free from the constraints of the Filesystem Hierarchy Standard (FHS). This standard, which dictates where libraries and files should reside, was seen as a hindrance to reproducibility. Nix aimed to provide a clean slate, allowing developers to build and run applications in isolated environments without the baggage of conventional file paths. But what happens when the ideal meets the reality of hardware dependencies?

The Graphics Driver Dilemma

The crux of the issue lies in graphics drivers, which form a crucial boundary between user-space and kernel-space. For instance, the user-space library libGL.so must align perfectly with the host OS’s kernel module and the physical GPU. In a typical Nix environment, most derivations do not bundle libGL.so because they cannot predict the hardware or host kernel on which they will run. This creates a significant barrier for users trying to leverage Nix on non-NixOS distributions.

A Necessary Compromise

Enter NixOS and Home Manager, which have introduced a global path at /run/opengl-driver/lib where derivations expect to find libGL.so. This move, while practical, essentially reintroduces the very convention that Nix sought to eliminate. It’s a bittersweet realization: to maintain usability, the community has opted for a compromise that feels like a betrayal of Nix's original purity. Users on other Linux distributions are left grappling with error messages reminiscent of the very problems Nix was designed to solve, such as “error while loading shared libraries: libGL.so.1: cannot open shared object file: No such file or directory.”

Workarounds and the Price of Purity

For those determined to uphold the sanctity of Nix, a few workarounds have emerged. Solutions like nixGL, which injects the library via $LD_LIBRARY_PATH, or manually adjusting $LD_LIBRARY_PATH, offer some respite. Alternatively, users can create their own /run/opengl-driver and symlink it with the drivers from /usr/lib/x86_64-linux-gnu. However, these fixes come with their own complexities and can feel like a betrayal of the Nix ethos.

In the end, the lesson is clear: while the quest for purity is noble, practical needs often dictate a different path. As the Nix community navigates this paradox, it raises an essential question for practitioners: how do we balance the ideals of our tools with the realities of the environments in which we deploy them?

More Stories