Declarative Wrappers: Another Idea

So there are many issues we’re having regarding wrappers:

Today I came up with an idea for a builder that could wrap programs with the appropriate environment without using wrap{GApps,Qt}hook at all. This needs more thinking, but I’d be glad to hear comments.

What if we’ll start by writing down all we know about environmental variables needed at runtime. Maybe something like this:

wrappingEncyclopedia = {
  QT_PLUGIN_PATH = {
    provided_by = [
      qt5.qtbase
    ];
    subpath = "/lib/qt-${qt5.qtbase.version}/plugins";
  };
  QML2_PLUGIN_PATH = {
    provided_by = [
      qt5.qtbase
    ];
    subpath = "/lib/qt-${qt5.qtbase.version}/qml";
  };
  XDG_DATA_DIRS = {
    provided_by = [
        gsettings-desktop-schemas
    ];
    subpath = "/share";
  };
  GST_PLUGIN_SYSTEM_PATH_1_0 = {
    ...
  }
  ...
};

With this, I imagine the builder recursively searching through the dependency tree of the package-to-wrap for dependencies that need an environmental variable, according to the encyclopedia. Then, with either symlinkJoin or buildEnv, we can add all of these dependencies to paths and wrapProgram would not even need to concatenate paths with :, but he’ll be able to use (e.g):

--prefix XDG_DATA_DIRS : $out/share

(This would also prevent issues like what #84679 fixed)

In order to use this new wrapping method, a contributor would use:

  wrappedPackage = neoWrap (callPackage ../applications/myPackage { });
2 Likes

How does the builder determine, from the encyclopedia, which dependencies need to be included? From your example, it’s not clear to me how this would happen. In my experience designing wrappers, answering that question is the hardest part.

I can imagine and that’s why I need help from experienced wrapper writers :slight_smile: if I’ll implement this. Here’s what I was thinking: Given an argument of a package to wrap, the builder would recursively search for dependencies in the package argument that are also listed in the encyclopedia, and if it finds such a dependency, it’ll add the appropriate environmental variable to wrapProgram's args.

There are already open threads here on Discourse about this.

I know @FRidh and I already encountered your post and PR. I’m currently trying to tackle this with passthrus instead of an “encyclopedia”. I’m fighting with Nix itself in order to implement the recursive search for dependencies with an environment attribute - most notably, I’m realizing now that “for loop” workflows are just not applicable in Nix.

PR: https://github.com/NixOS/nixpkgs/pull/85103

2 Likes

RFC live at https://github.com/NixOS/rfcs/pull/75 .