Bundling Libraries
onelf bundle-libs walks the ELF files in an AppDir, resolves their dependencies, and copies the shared libraries into lib/.
The rules this page encodes:
- ✅ Run
bundle-libson every AppDir before packing. It is idempotent; run it again whenever the tree changes. - ❌ Never put a host directory on the library search path. Not with
LD_LIBRARY_PATH, not with anRPATHpointing outside the tree. The resolver decides host access one library at a time; you cannot do better by hand. - ✅ Reach for
--scan-dlopenor--trace-runwhen the app loads plugins.DT_NEEDEDalone does not see adlopen. - ❌ Do not bundle Mesa "to be safe". The driver that works is the user's; the host's driver stack is taken at launch unless you say otherwise.
Basic usage
onelf bundle-libs ./myappWith no flags, this:
- Scans every ELF file under
./myapp/forDT_NEEDEDentries. - Resolves each soname via ldconfig (or the NixOS store, when detected).
- Copies the resolved
.sofiles into./myapp/lib/. With glibc come its charset converters, intolib/gconv/: the Unicode, Windows, ISO Latin, and common East Asian ones with the configuration that names them.iconvloads those by name from beside its own libc, and on a host with another glibc none would load, so a bundled app could not convert text at all. The runtime pointsGCONV_PATHat them. TheC.UTF-8locale comes too, intolib/locale/, when the source system has it. It is not built into glibc, and a bundled glibc reads the host's locale archive, which a musl host or a minimal container does not have. A library resolved from a plugin directory of its own kind keeps that directory: the ALSA plugins a recipe force-includes land inlib/alsa-lib/, GStreamer's inlib/gstreamer-1.0/, PipeWire's inlib/pipewire-0.3/andlib/spa-0.2/, GIO's inlib/gio/modules/, and libheif's, babl's and GEGL's likewise. That is where their loaders look for them; a copy written flat would be dead weight, since nothing loads it from there. With the library comes the data it reads from a path compiled into it: libasound bringsshare/alsa, libxkbcommonshare/X11/xkb, libX11share/X11/locale, and libmagic its compiled databasemagic.mgc, each copied from beside the resolved library. When that library is already in the AppDir, put there by the Wayland copier or shipped by the publisher, the data is looked for beside the host copy it came from or that its soname resolves to, after the AppDir's own. A sysroot build never looks on the host. The carry is automatic and adds bulk on every matching bundle: a GUI toolkit's libxkbcommon brings roughly 3 MB of keymap data, libasound about 150 KB. A tree bundled by an older onelf is repaired on the next run: the missing data is carried then, and a plugin left flat inlib/moves into its subdirectory. Because of that repair work a re-run re-resolves every library instead of stopping at the first "all present" answer, which costs a few seconds more on a large tree and copies nothing when everything is current. On a host without the owning package, ALSA withoutshare/alsahas noalsa.confand cannot open any device at all, bundled plugins included. The carriedalsa.confalso gets a hook entry inserted, loading the carriedalsa.conf.d/right after the host's own snippet directories: the host's distro snippets then cannot steal the default output from the pulse default the package carries, while a deliberate/etc/asound.confor~/.asoundrcstill wins. - Rewrites
RPATH/RUNPATHon every bundled ELF to the one$ORIGINentry that reacheslib/from where the file sits:$ORIGIN/../libforbin/app,$ORIGIN/../../../libforopt/tool/bin/app. No entry ever resolves outside the tree, so the bundled binaries find their libs relative to their own location withoutLD_LIBRARY_PATHand without a host directory ever being searched. ARUNPATHis retagged asRPATH, which the loader passes down the dependency chain. For an executable without an existing slot,bundle-libsfalls back topatchelf --set-rpath(when patchelf is inPATH, or named byONELF_PATCHELF) to add a fresh entry. - Injects an AT_EXECFN bootstrap into each bundled executable. At runtime, the bootstrap reads
AT_EXECFN, computes the bundled interpreter path relative to the binary's own location, and jumps into it. This keeps/proc/self/exepointing at the real binary, which is important for Python's stdlib detection, Electron's ASAR locator, and Qt's plugin loader. - Scrubs
/usr/,/etc/,/nix/,/lib/, and/lib64/strings inside the bundled glibc loader to/XXX/, so it won't pick up the host'sld.so.preload,ld.so.cache, or hardcoded fallback library dirs. A bundled musl loader has its default library path scrubbed the same way.
Two ways to decide what goes in
✅ Host scan (this page) for a quick bundle of the app on your machine. ✅ A pinned sysroot when the result must not depend on your machine.
The walk above takes its universe from the machine you pack on: the ldconfig cache, the Nix store, and the search paths you add. It cannot see a dlopen by computed name, a plugin directory or a data file, and what it finds is what your distribution installs. A pinned sysroot with a package database is the other source: the bundle becomes the closure of your application's package, pruned by what you declare, with nothing taken from your machine. See Bundling from a Sysroot.
Both sources end in the same verifier. Every DT_NEEDED of every bundled ELF must resolve inside the bundle or name something the host provides. How a finding is treated depends on where the tree came from:
- ✅ From a sysroot an unresolved soname is an error, since the universe was complete and the omission is a policy or platform-line mistake you can fix.
- ✅ From a host scan,
onelf buildandonelf run --bundlefail on an unresolved required dependency too, before anything is published or run. A need the host platform supplies (the libc family and the GPU driver stacks) is reported and never fails the build. A need that[bundle] excluderemoves fails it: the runtime takes nothing but those host-platform libraries from the host, so an excluded library something retained needs would be missing at launch. An auto-collected plugin whose dependency the scan cannot find is omitted and reported instead, and what the build requires (an entrypoint, an explicit include, a file you placed, a required helper or data group) is never omitted. - ⚠️ The low-level
onelf bundle-libskeeps the old behavior: from a host scan an unresolved soname stays a warning and nothing is omitted. - ⚠️ A recipe with
[bundle] skipruns no walk and no audit at all: the tree is packed unchecked, exactly as it stands. See Unchecked trees.
Libraries that come from the host
The problem: some libraries must come from the host, most of the bundle must not, and both land in the same process.
- ❌
LD_LIBRARY_PATHwith host directories. It is inherited by every process the app spawns, so host libraries get loaded next to the bundled libc and break in ways that are miserable to trace. Never. - ❌ Host directories before the bundle's on any search path. The host's libstdc++ loads beside a bundled glibc built against a different one.
- ❌ Host directories after the bundle's. The bundled copies win everywhere, and a host driver that must match the user's hardware fails to bind.
- ✅ Per-library resolution by the runtime's launch resolver. It compares versions and picks the superset, per soname.
A library the bundle does not provide is not a hard error at runtime, but what the host may supply is decided one library at a time, at launch, by the runtime's resolver. No host directory is ever placed on the search path.
The problem the resolver exists for is a host GPU driver. Mesa and the vendor drivers are dlopen'd by name and have to match the user's hardware, so they come from the host, and they bring their own dependencies with them: the host's libstdc++, libdrm, LLVM and, at the bottom, the host's glibc. Whether those can share a process with the bundled copies depends on which side is newer, and that differs per library. Neither blanket order above is right for every library, which is why comparing per soname is the design.
For each soname present both in the bundle and on the host, the runtime reads the versions each copy defines and picks the superset. Under symbol versioning a newer build only ever adds versions, so the winner can stand in for the loser. Equal sets keep the bundled copy. Two copies that each define a version the other lacks cannot be ordered; the bundled one is kept and the soname is reported on stderr:
onelf-rt: resolver: cannot order libfoo.so.1; keeping the bundled copyThe loader and libc are compared first, as a pair, because a libc only runs under the loader it shipped with. When the host's glibc is newer than the bundled one, the whole glibc family comes from the host and the entrypoint runs under the host loader. Every bundled library still loads from the bundle, since a newer libc satisfies whatever the older one did.
The host loader never runs as installed, because it would still search its compiled-in default directories and find any host library there. The runtime runs a copy with those directories removed. The copy is kept once per uid and loader under the cache root's loaders/, which is /var/cache/onelf/loaders/ for root, and is checked against its BLAKE3 digest and its private ownership before a launch uses it. Copies are not collected by the cache's garbage collection. Each is the size of the host's loader, about a megabyte, and a new one appears only when the host's loader changes. Removing loaders/ while no package runs is safe, as the next launch writes the copy it needs again.
The host libc opens the name service modules /etc/nsswitch.conf (or /usr/etc/nsswitch.conf) names and libgcc_s by name, so those come from the host with the pair when the bundle lacks them. A bundled libgcc_s is compared against the host's like any other library. When no copy can be made, because the loader's directories cannot be found in its image, the cache root is not a directory the uid can write, or the cache sits on a noexec mount, the bundled loader and libc run instead and --onelf-doctor says why.
Host winners are placed over their bundled copies with a bind mount inside the private mount namespace, or a symlink in a tree that belongs to this launch alone, so every process the app starts sees the same choice, including one that clears its environment and re-execs. A mode that has neither, the cache and a fusermount3 mount, keeps the bundled glibc, since the bundled executables would still find their own libc under the host loader. Host libraries the bundle does not carry at all, the driver itself for one, are shown as symlinks in the bundle's library directory, where the run path bundle-libs wrote finds them. No LD_LIBRARY_PATH is set, so the programs the app runs never see them (see Environment). A soname that is neither bundled nor chosen fails by name:
error while loading shared libraries: libm.so.6: cannot open shared object filerather than loading whatever the host has and crashing later, somewhere else, on a machine you do not have.
The decision is recorded under the private runtime directory, keyed by the package and a fingerprint of the host's loader cache and driver directories, so a second launch on an unchanged host reuses it. Set ONELF_NO_RESOLVER=1 to launch with nothing from the host, which is the quickest way to tell whether a failure is the resolver's doing.
What the resolver may consider
| Verdict | Mode | Meaning |
|---|---|---|
| default when the bundle references a driver stack | auto | The driver stack's host closure: the driver families, what the host's Vulkan and EGL vendor files name, the host's GLX vendor libraries, what the DRI and VA-API drivers in its dri directories need, and everything they need |
| default otherwise | never | Nothing from the host |
| ✅ for apps that load a host library under a name they never mention | always | Every bundled soname is compared as well |
onelf pack app -o app.onelf --command bin/app --host-libs alwaysor as host-libs under [package] in a recipe.
Detection is deliberately generous, because a wrong "never" breaks an app that works while a wrong "auto" only costs a comparison. It matches driver sonames anywhere in the bundle's binaries, not just in DT_NEEDED, since drivers are reached through dlopen. Reach for always if your app loads a host library under a name it does not mention, such as one built at runtime from parts.
bundle-libs reports what it did not bundle:
warning: 1 librar(ies) are not in the bundle:
- libm.so.6 (needed by myapp)How to read that warning:
- ✅ GL, DRI, Vulkan and NSS entries are expected. They are meant to come from the host, because they have to match the user's drivers and system configuration.
- ❌ Anything else means the library exists on your machine but did not make the bundle, and the app will rely on the host for it. Fix it by pointing
--search-pathat a directory holding the library and repacking.
A library reached only through dlopen will not appear in DT_NEEDED at all, so --scan-dlopen is what finds those.
Plugin and data paths compiled into a library
The problem: GStreamer, PipeWire, ALSA, libheif, Tcl, libX11 and libmagic load plugins or read data from a directory built into them, such as /usr/lib/gstreamer-1.0 or /usr/share/alsa. The bundled library carries that host path inside it, and something must make the path find the bundle's own copy at launch.
onelf collects those directories for you. The build reads the absolute paths compiled into every bundled object and, when a compiled-in path is a plugin or data directory that exists on the pack host, carries the directory and redirects the path. A library the catalog has no descriptor for gets its plugin and data directories bundled anyway, and its compiled-in paths answer from the bundle.
What is collected: a candidate must be a normalized absolute path below the prefix's lib family (including each multiarch directory) or share directory, and must name an existing directory. Shared roots and shared trees are never collected: share/locale, share/icons, share/fonts, share/doc, lib/gcc, lib/modules, lib/firmware and the rest hold many packages' files or the host's own. libc's own paths stay with the libc handling, driver stacks keep their own policy, and host configuration and system state (/etc, /proc, /var) are not candidates. Whatever a descriptor declares is the descriptor's, and those directories never appear as inferred findings; the descriptor's own finding covers them. Every built-in descriptor holds that claim whether enabled or not, so disabling a built-in keeps inference out of its directories, and every enabled project-local rule holds it too.
A candidate that holds ELF objects is a plugin group, carried whole with its layout preserved, because frameworks keep scripts, manifests and caches beside their modules. Every ELF object inside passes the same architecture and ELF-class checks as a bundled library, with its dependencies judged like a library's, so one module built for another architecture is skipped with its reason while the rest of the directory still ships. Any other candidate is a data directory, copied under the prefix it compiles to. Each directory is collected once under its canonical path: a link and its target are one directory, and one copy answers for every spelling of it.
Each collected directory is redirected by exactly one of three mechanisms, chosen when the package is built, in this order:
- A descriptor's environment mapping (the variables in Environment): the library's bytes are left alone and the variable names the bundled copy. Only a lookup that reaches the library through the variable is covered.
- An anchor: every string in the bundled copies that is the compiled-in path, or starts with it followed by
/, has its first 11 bytes overwritten with/dev/fd/77/. The rest of the string is kept, so/usr/share/alsabecomes/dev/fd/77/alsaand/usr/share/alsa/alsa.confbecomes/dev/fd/77/alsa/alsa.conf. The string keeps its length, a file named below the directory is covered too, and a shorter string the linker stored inside the original keeps its bytes. A path below the directory that another carried directory or a recipe[paths]pair sends somewhere else keeps its bytes instead, for that answer. A recipe pair that sends the compiled-in path itself to another bundle directory owns it: an inferred directory whose every compiled-in path a recipe pair sends elsewhere is not carried, and its finding names the pair. A tree rebuilt in place keeps the bytes and the anchors its earlier build made, so a recipe pair added later over an anchored path applies only to a fresh tree, and the build says so. The key is the kept tail (alsahere). At launch the runtime holds descriptor 77 open on a private per-launch directory whose keys link to the bundled copies, so the path resolves only inside the launch that holds it and for the processes it starts. No mount namespace is needed, and nothing is created anywhere another user could write. A package that uses anchors needs a runtime advertisinganchorssupport, which the packer checks. Strip runs before the rewrite, so the rewritten bytes are the ones packed. A bundled program started with every inherited descriptor closed, as Python'ssubprocess, GLib's spawn functions and Chromium's launcher do, reopens descriptor 77 fromONELF_ANCHOR_DIRbefore its own code runs. A host program started that way, or one started with a cleared environment, finds nothing at an anchored path. - A path pair for a namespace overlay, recorded in the package's
.onelf/paths, for every compiled-in path of a directory that cannot take an anchor: one of its paths has 11 bytes or fewer, which leaves no key, another directory already takes one of its keys, a recipe pair sends one of its paths elsewhere, or the anchor record is full. A tree built once keeps the keys its record names while a carried directory or a tree object still uses them, and a path a rebuild newly finds for an anchored directory takes a pair of its own when it cannot take a key. A key whose directory the tree lost is held back for the build that loses it. An anchored path the tree's objects still carry that the record no longer explains is reported in the build that finds it, with what it now resolves to or that nothing serves it, and a fresh tree clears it. A launch with a private mount namespace binds the bundled copy over the path; a[paths]pair from the recipe keeps precedence over an inferred one. A spelling that cannot enter the pair record leaves the path unredirected, and the findings say so. Runningbundle-libsandpackas separate steps keeps the inferred pairs: the build leaves them in the tree's.onelf/inferred-paths, which the pack merges into.onelf/pathsand does not ship.
The completeness findings name every carried inferred directory with the object that compiled it in, its classification, its size and how it is redirected. A build that carries a framework no descriptor describes, and ncurses beside it, reads
- lib/widgetry-0.2: selected: plugin directory, 43 object(s) and 0 other file(s), 3.9 MB, redirected through /dev/fd/77/dgetry-0.2; inferred from /usr/lib/widgetry-0.2 below the prefix /usr, compiled in by libwidgetry.so.0 as /usr/lib/widgetry-0.2
- share/terminfo: selected: data directory, 209.9 KB, carried, redirected through /dev/fd/77/terminfo; inferred from /usr/share/terminfo below the prefix /usr, compiled in by libncursesw.so.6 as /usr/share/terminfoThe build then prints a summary of the mechanism it chose for each carried directory (Redirected inferred directories:, one line per directory naming environment mapping, anchor /dev/fd/77/<key> or path pair), and --onelf-doctor reports what a launch would do with them on the host you ask about: the anchor record, which pairs become overlays, and which pairs would stay unredirected, with the reason (see Runtime flags).
A compiled-in path of a component the catalog knows, which neither its descriptor nor inference answered, stays an unchecked completeness finding naming what the bundle would have to carry:
- lib/libasound.so.2: unchecked: reads /usr/share/alsa from the host unless the bundle carries share/alsa and the runtime sets ALSA_CONFIG_DIRInference cannot see a path that no bundled object spells out whole: GLib, GTK, gdk-pixbuf and gobject-introspection join theirs at run time, and a compiler may build a short path from pieces, so no finding is no proof. For those, give the walk a search-paths entry and an include for the plugin by soname, or set the library's own variable from the recipe (see Environment).
Host plugin modules
A plugin directory the bundle carries also sees the host's own modules. A configuration written by the user or the app can name one by absolute host path; an .asoundrc with pcm_type.pulse { lib "/usr/lib/..." } is the common case. The launch admits the named module when every object in its dependency closure passes the admission checks; among them the object must be built for the package's architecture and ELF class, be of no foreign libc family, demand only symbol versions the copy that would load defines, and need only sonames something supplies. The module and its directory, with links resolved, and every directory above them must also be owned by root or the user running the package and be writable by no one else, a sticky directory excepted, so another user cannot plant a module the launch would admit. The module's dependencies come through the loader cache, as host driver libraries do. On a host without a loader cache, a musl one say, the default library directories stand in for the ones a cache would name. The host's counterpart directories count as the same plugin directory, which is what makes a multiarch host's /usr/lib/x86_64-linux-gnu/alsa-lib answer for a bundle that carries /usr/lib/alsa-lib.
An admitted module is never loaded beside the bundled ones. The launch presents the directory as a merged view: bundled members first, then every admitted host member whose name the package does not carry, and the compiled-in path resolves to that view. --onelf-doctor reports refused modules with the first object that failed and why. A musl-family module is always refused, so on a musl host the bundle plays through what it carries.
host-libs = "never" (and ONELF_NO_RESOLVER=1) admit no host module. A module the launch reaches through a redirected directory, by name or through a [paths] pair bound over its path, then fails to load, and the application falls back to what it carries. A configuration that names a module's absolute host path is not affected: where the directory is redirected by an environment mapping or an anchor, that path is not covered, and the host's file is opened whatever the policy says, with whatever its own run path reaches. No admission check applies to it. Neither setting stops the bundle from carrying its own inferred directories.
Trimming inferred directories
Inferred directories are carried whole, and a framework's plugin tree can be large. A recipe whose build carries a trace, from trace-run or a [sysroot] trace, can add trim-inferred = true under [bundle]: a plugin group then keeps only the members the trace loaded, their dependencies, matches of the recipe's keep patterns and the targets of kept relative links, and a data directory keeps only the files the trace opened, keep-pattern matches and the targets of its kept relative links. A traced run of a glibc target records only the objects the loader maps, so there only plugin objects are trimmed and data is carried whole; a traced run of a musl target and a sysroot trace record every file opened. Without the key nothing is trimmed, including in recipes that trace only to add libraries, and the key without a trace that applies fails the build. A [sysroot] build trims by its recorded trace, even in a dry run, and refuses trace-run outside one, since the run would be against this machine; a dry run of a traced host scan trims nothing because it never runs the target. Trimmed directories are reported as trace-limited rather than complete.
Self-extracting binaries (Bun, etc.)
- ⚠️ Binaries that embed a payload break under naive post-processing. The common case is Bun-compiled apps. Before 1.3.12 Bun looks for the trailer
\n---- Bun! ----\nat the end of the file. From 1.3.12 it keeps the payload in a.bunELF section that it finds by parsing its own program headers, so a rewritten layout makes it crash.
bundle-libs detects both kinds automatically and:
- Skips bootstrap injection. The bootstrap appends bytes and repurposes a program header, which would clobber the trailer or the section lookup.
- Skips
patchelf --set-rpathfor binaries lacking a RUNPATH slot, and leaves them out of--strip. Both rewrite the file.
At runtime, onelf-rt has the kernel resolve the PT_INTERP of a binary with the end-of-file trailer directly. Inside a private mount namespace it bind-mounts the bundled linker over the binary's existing PT_INTERP path. Without one, as in cache mode, it creates a short symlink in the private runtime directory and patches the binary's PT_INTERP in place to point at it. Either way, /proc/self/exe resolves to the binary itself and Bun finds its embedded JS bundle.
☑️ bundle-libs warns about each such executable that is left without an $ORIGIN entry. It finds its libraries only through the LD_LIBRARY_PATH the runtime sets, which an app that clears its environment and re-execs itself loses.
Starting from a bare binary
onelf bundle-libs ./myapp --from-binary /usr/bin/myappCopies /usr/bin/myapp into ./myapp/bin/myapp, then runs the normal flow.
Detecting dlopen'd libs
Some libraries are loaded at runtime via dlopen and don't appear in DT_NEEDED.
- ✅
--scan-dlopenwhen the app loads known plugins. It searches the binary for common candidates (Wayland, X11 and its extensions, audio, DBus, fonts) and bundles any matches, including names a Rust binary merges into its string data without a NUL between them. The GPU stack is not a candidate: as on detection, the host's driver is the one that works.
onelf bundle-libs ./myapp --scan-dlopen✅ Extend the allow-list with a vendor soname the scan cannot know:
onelf bundle-libs ./myapp --scan-dlopen --dlopen libmyvendor.so.1✅ When even the scan is not enough, run the application and let the loader say what it loaded:
onelf bundle-libs ./myapp --target bin/myapp --trace-run --trace-seconds 5 --trace-arg --versionThe target runs for up to the given time, from this machine's libraries, and every shared object it loaded from outside the tree joins the bundle, subject to the same exclusions as everything else. glibc's loader reports this on its own through LD_DEBUG, per process, so helpers the app spawns count too; a musl target is watched with strace, which has to be installed. Only the tree's own programs count: a host program the app starts, a shell or xdg-open, does not. The run gets a scratch HOME and XDG directories, runs in its own process group, and the whole group is stopped at the end; it keeps the display and the D-Bus session. The GPU stack it maps (Mesa, libLLVM, vendor GL and Vulkan drivers) is left to the host as on detection. A run that fails on its own is reported with the end of its stderr. ⚠️ A GUI app needs a display for the run; an app that reads its arguments needs --trace-arg to make it exercise the path you care about. ❌ A trace does not apply to a sysroot build, which records a trace with ONELF_TRACE instead.
Framework auto-detection
bundle-libs scans the binaries for the frameworks they use, by DT_NEEDED and by literal soname strings in their bytes, so a library that is only dlopen'd at runtime (Blender loading libwayland-cursor.so after checking $XDG_SESSION_TYPE, for example) is found without a DT_NEEDED entry.
✅ Detection only flags a framework when it finds a properly versioned soname such as libEGL.so.1 or libwayland-client.so.0. This keeps Rust binaries honest. Their string tables merge literals together without NUL separators, so a real dlopen soname shows up glued to its neighbours like ...eglWaitSynclibEGL.so.1libEGL.so.... The version suffix is what tells a genuine soname apart from prose like "Library libwayland-client.so could not be loaded.".
The verdict per framework:
- ✅ Wayland, GTK: bundled. Client-side, they must match the bundle.
- ✅ GL, DRI, Vulkan: not bundled. The driver that works is the host's.
packsees the driver references under its default--host-libs autoand the launch resolver takes the stack from the host. The scan reports which it found:
Frameworks: gl, vulkan detected; the host's drivers are used at launch.
Pass --gl, --dri or --vulkan to bundle Mesa instead.- ❌ Bundling Mesa "to be safe": for a host that has its own GL this means two copies of the driver stack, and the resolver then takes the host's wherever it is newer. ✅ Bundle Mesa only when the package must run where the host has no GL at all.
You can still force any of these explicitly:
onelf bundle-libs ./myapp --gl --vulkan --wayland --gtk✅ Opt out of a framework that detection or an explicit flag would otherwise pull in. This matters for a binary built with optional GUI support that you only ship as a TUI. amdgpu_top, for example, links the wgpu and wayland stacks even though its default mode is a terminal UI:
onelf bundle-libs ./amdgpu_top --no-gl --no-waylandThe --no-* opt-out always wins over both auto-detection and the matching --* flag. Auto-enabled and suppressed frameworks are both printed so you know what was decided.
Framework rules
Behind the detection sits a built-in rule catalog. Each supported component (ALSA, GStreamer, PipeWire, GTK, Qt, xkb, fontconfig, gdk-pixbuf, Tcl/Tk and the rest) has a rule naming the sonames that activate it and the plugin directories, helper executables and data directories the component needs. When the walk sees an activating soname, the rule's groups are collected from the selected source, so a component's plugins and data arrive with it instead of being chased one --include and one hand-placed share/ at a time. Each activated rule is reported, with the soname that triggered it and how many groups it queued:
Rules: 1 activated by soname prefix: xkb (libxkbcommon.so.0); 1 group(s) queued- ✅ A required group the selected source cannot supply stops the build naming the rule, the group and the locations it looked in:
error: rule alsa group configuration requires directory data at share/alsa, but none of its declared locations exist in the selected source; ./myapp: absentThe trailing list is the audit's evidence: each examined location and why it held nothing (absent, left to the host package, pruned from the package), a few at most, so the fix is visible without rerunning. A required helper executable is treated the same way and names the rule and the helper it missed. The host's copy is never pulled in to fill the gap.
- ⚠️ An optional group the source happens not to have is an optional omission in the completeness findings, not a failure:
- alsa: lib/alsa-lib: optional omission: group plugins: no usable plugin group (1 location(s) unavailable, 0 candidate(s) skipped); ./myapp/lib: absent (activated by libasound.so.2)The component keeps working through the runtime mappings the rule also declares, and the report says what was skipped.
- ⚠️ Activation reads sonames, not behavior. A plugin loaded under a name the binary computes at run time still needs
--trace-run(host scan) or a sysroot trace, like every otherdlopenby computed name.
Project-local rules
A recipe can extend the catalog with descriptor files of its own and switch built-in rules off. Rule paths resolve against the recipe's directory, like every other recipe path:
[package]
command = "bin/app"
[bundle]
rules = ["vendor-framework.toml"]
disable-rules = ["translations"]A local descriptor uses the same schema as the built-in ones:
schema = 1
id = "vendor-framework"
[[triggers]]
soname-prefix = "libvendor.so"
[[resources.plugins]]
id = "plugins"
kind = "directory"
destination = "lib/vendor-plugins"
requirement = "optional"
candidates = [{ base = "library-dir", path = "vendor-plugins" }]
[[runtime.paths]]
id = "plugins"
kind = "directory"
variables = ["VENDOR_PLUGIN_DIR"]
selection = "first"
inheritance = "replace"
candidates = [{ base = "library-root", path = "vendor-plugins" }]A plugin group collects every compatible member of its directory unless it lists members: paths relative to the found directory, such as "support/libspa-support.so". Then only those members are collected, and a listed member the source lacks is simply absent. The built-in PipeWire and SPA rules use this to carry the client side alone: the modules client.conf loads into an application's context, the SPA support plugins and the audio converter. The daemon's protocol servers, device plugins and Bluetooth codecs are left behind, along with the libraries they pull in. The PipeWire rule also carries share/pipewire/client.conf, without which a client context does not start, and points PIPEWIRE_CONFIG_DIR at it.
⚠️ This is a limitation of packaged PipeWire clients. With PIPEWIRE_CONFIG_DIR set, PipeWire reads its client configuration from that directory alone, so the user's drop-ins under ~/.config/pipewire/client.conf.d/ and ~/.config/pipewire/client.conf are not read by a packaged application. A user who needs their own client configuration sets PIPEWIRE_CONFIG_DIR before the launch, since a value the caller set wins.
[[resources.plugins]]
id = "plugins"
kind = "directory"
destination = "lib/vendor-plugins"
requirement = "optional"
candidates = [{ base = "library-dir", path = "vendor-plugins" }]
members = ["libvendor-core.so", "codecs/libvendor-pcm.so"]- ✅ The rules are parsed and checked with the built-ins before the AppDir is touched. A parse error, an unsupported schema, an unknown field or hook, a refused variable (any
LD_*name,GCONV_PATH,GLIBC_TUNABLESor anONELF_*name), a local identity that repeats another file's, and an unknown or repeateddisable-rulesentry all fail the build naming the file and the rule. - ❌ A local rule cannot take a built-in identity, not even one the recipe disables. Give it its own identity and disable the built-in. A variable may be mapped by one enabled rule only, so a local rule that maps a built-in's variable needs that built-in disabled.
- ✅ A disabled rule never activates: its groups are not collected and its runtime mappings are not carried.
- ✅ The package carries the enabled rules' runtime mappings in
.onelf/runtime-rules, so a launch needs neither the descriptor files nor a TOML parser. A recipe whose rules leave the runtime behavior the built-ins already give carries no record and packs exactly as before. - ✅
onelf run --bundleassembles with the same rules, and a development launch evaluates the record a build would carry. - ✅
[bundle] skipbuilds still validate the rules and carry their mappings, without claiming any dependency was audited.
Resources prepared from a set
When a declared set, not the AppDir's source, supplies a rule's helper or small configuration resource, the build reads it verified out of the pinned set and prepares it into .onelf-prepared/<set>/<pin>/ inside the application. The package's runtime record binds that subtree to the pin, so a launch uses it only when its entrypoint selects that pin. For each mapping the application's own resources come first, then the selected pins' prepared copies, then the raw set roots. A resource is prepared only where one of the rule's runtime mappings would find it, so a prepared copy is never left unmapped.
Extra library search paths
The default resolver walks ldconfig and the NixOS store. If the libraries you want live somewhere else (cross-compile output, custom prefix), add a search path:
onelf bundle-libs ./myapp --search-path /opt/custom/lib--search-path takes precedence over ldconfig and the store, so it's the best way to pin a specific library version.
Packing on NixOS
✅ Do nothing special. bundle-libs handles the NixOS stub loader (/lib64/ld-linux-x86-64.so.2, which exists but refuses to run foreign binaries, printing NixOS cannot run dynamically linked executables...) automatically:
- Any candidate loader whose canonical path contains
stub-ldis rejected at every resolution tier, so a real glibc from the Nix store wins. - A previously-bundled stub-ld accidentally copied into
lib/is detected (by path or by theNixOS cannot runsignature inside the file) and deleted on the nextbundle-libsrun. - The bundled glibc loader has its
/nix/store/...build-time paths scrubbed so it can't reach back to a store path that doesn't exist on another machine.
⚠️ If you see the stub-ld error anyway, your lib/ predates the fix: delete it and re-run bundle-libs with the current onelf.
Cross-libc hygiene
❌ Mixing libc families in one bundle. When the target binary is musl and the host is glibc (or vice versa), bundle-libs can end up copying libraries built against the wrong libc. Those fail at runtime with confusing "symbol not found" errors.
✅ --strict-libc refuses to bundle libraries whose DT_NEEDED points at the wrong libc family, and instead reports them as unresolved in the completeness findings:
onelf bundle-libs ./myapp --strict-libc✅ Combine with --search-path pointing at the right-libc versions to make the bundle clean.
Excluding and including
onelf bundle-libs ./myapp --exclude libpthread,libdl
onelf bundle-libs ./myapp --include libsomething.so.1--exclude skips libraries by prefix, collected plugin group members included, so excluding a plugin by name keeps it and its dependencies out. An exclude prefix also drops an inferred directory when a path component below its library dir or share begins with it, so --exclude libdecor leaves out the carried lib/libdecor/plugins-1 group as well as the library, while libx leaves libx32 alone. Excluding a library that a retained object needs is a conflict that stops onelf build, since nothing at launch supplies it from the host. --include forces a soname into the resolution queue.
☑️ Some prefixes are always excluded: libnss_ (apart from the name service modules a bundled glibc needs), the vendor GPU and compute runtimes libcuda.so, libnvidia, libamdhip64.so and libze_loader.so, and linux-vdso.so.
Stripping
onelf bundle-libs ./myapp --stripRuns strip --strip-unneeded on each copied library. Saves disk space (often 20-40 %) at the cost of debuggability.
Dry run
✅ Check a bundle plan before committing to it:
onelf bundle-libs ./myapp --dry-runShows what would be bundled without copying, fetching or running anything. For a recipe, onelf build --dry-run does the same for the whole build: it reports the import, the libraries and framework groups it would collect, the package it would emit, and the completeness findings, and it leaves the AppDir untouched.
GPU / graphics helpers
The granular framework flags:
| Flag | What it bundles |
|---|---|
--gl | The glvnd dispatch libraries (libGL, libGLX, libEGL, libGLESv1_CM, libGLESv2, libOpenGL, libGLdispatch), Mesa's libGLX_mesa, libEGL_mesa, libglapi, libgbm and libxatracker, GBM backends, EGL vendor files, and Mesa's drirc.d and libdrm data |
--dri | Mesa DRI drivers into lib/dri (filtered to your architecture) |
--vulkan | Vulkan ICD files into share/vulkan/icd.d and the drivers they name (filtered to your architecture) |
--wayland | libwayland-client, -server, -cursor and -egl, libdecor-0 with its plugins, and libxkbcommon |
--gtk | GSettings schemas, compiled into share/glib-2.0/schemas |
- ✅
--waylandand--gtkare enabled by detection; pass them to force-on when detection misses something. - ☑️
--gl,--driand--vulkanare opt-in, since the driver stack comes from the host unless you say otherwise. - Each has a
--no-*counterpart (--no-gl,--no-dri,--no-vulkan,--no-wayland,--no-gtk) that forces-off, overriding both detection and the matching--*flag. - ☑️ None of them apply to a sysroot build. On the command line they are refused with
--sysroot, and in a recipe with a[sysroot]they do nothing.