Modify chromium command / provide path to dynamic library

Hello,

in order to have vulkan enabled in chromium I need to provide the path to the vulkan loader via the LD_LIBRARY_PATH variable. Therefore I call chromium like this:

LD_LIBRARY_PATH=$(nix eval --raw nixpkgs#vulkan-loader)/lib:$LD_LIBRARY_PATH chromium

How can I make this persistent such that when I start chromium it can find the vulkan loader? I don’t want to have chromium start like this from the command line.
Is there a way to define an overlay/override to modify the chromium command? Or should I export the LD_LIBRARY_PATH env. variable?

This is the relevant issue: Vulkan disabled in chromium: Couldn't open libvulkan.so.1 · Issue #150398 · NixOS/nixpkgs · GitHub

Apparently this commit might help, but I have no idea about chromium builds: chromium: Install libvulkan.so.1 · a-m-joseph/nixpkgs@b7fe2da · GitHub. You could do the same in an overlay like this:

final: prev: {
     chromium = prev.chromium.overrideAttrs(old: {
        postInstall = ''
            cp -v "$buildPath/libvulkan.so.1" "$libExecPath/"
        '';
    });
}

Though it looks like that’s already being done upstream in 22.05, so upgrade if you haven’t yet: nixpkgs/browser.nix at 21321a6381fd8d3660fe1cdc0485fbb5978112ce · NixOS/nixpkgs · GitHub

To apply your hack permanently to the chromium package, I think you would use an overlay like this:

final: prev: {
     chromium = prev.chromium.overrideAttrs(old: {
        postInstall = ''
            wrapProgram $out/bin/chromium \
                --prefix LD_LIBRARY_PATH : "${prev.makeLibraryPath [prev.vulkan-loader]}"
        '';
    });
}

This will mean you need to rebuild the chromium package though :slight_smile: Might be better to create a separate derivation that just depends on the chromium one, and is just a little shell script that sets the library path. Perhaps:

final: prev: {
     chromium = prev.writeShellScriptBin "chromium" ''
        LD_LIBRARY_PATH="${prev.makeLibraryPath [prev.vulkan-loader]}:$LD_LIBRARY_PATH" ${prev.chromium}/bin/chromium $@
    '';
}

Edit: Shout if any of these work, would probably be nice to add them to the upstream ticket.

1 Like

Hey @TLATER
thank you for that great answer! I learned a lot from it. Your last solution works for me if I replace prev.makeLibraryPath with lib.makeLibraryPath. Because of that wrapper script though in KDE chromium doesn’t appear as an application anymore but as a script. Also somehow chromium isn’t the default browser anymore. But that is okay.
I also tried the other two of your solutions but they didn’t have any effect. I build my system with flakes and nixpkgs-input: nixos-unstable. So I should have already had chromium including that commit that you referenced with the libvulkan.so.1 in the libExecPath. This does not work for me. I see in chromium still the log message that the library couldn’t be found.
Anyway thanks to you answer I made progress!

My bad! prev.lib makeLibraryPath is probably correcter (keeps you from accidentally mixing nixpkgs versions), but in practice doesn’t matter at all.

It is a hack, I’d definitely encourage you to try and root cause this properly and fix it upstream if you have some bandwidth :slight_smile:

1 Like
Hosted by Flying Circus.