Packaging a program through a flake.nix

Been playing around with using the nix ecosystem to package one of my projects and I have some doubts about how to proceed.

The current flake.nix looks like this:

The program builds fine via nix build but does not run with nix run because it fails with

legion-kb-rgb: error while loading shared libraries: cannot open shared object file: No such file or directory

meaning it does not appear to see the buildInputs at runtime.

As I understood it, nativeBuildInputs are only used at compile-time while buildInputs are those that the program also needs when running. I am not sure if I am misunderstanding something about nix packaging or if it is something specific to using a flake/crane. (Comparing it to how packages are written for nixpkgs).

I’m also curious about what would a proper way to install a program be once this has all been set up correctly. (Ie, does this work? I guess I could do without the overlay.)

Which build inputs are available at runtime is determined by whether a reference to them still exists in the resultant store object. The difference between nativeBuildInputs and buildInputs is primarily which arch they’re compiled for when cross-compiling. (I think also certain hooks might only be run for nativeBuildInputs, but I’m not certain.)

Most likely the way you’re compiling this doesn’t properly document the shared library’s location in the ELF header, however I don’t know enough about the ecosystems in use here to tell you what exactly is wrong.

Also, yes, that looks like it should work to install it, when you get there.

Searched around and found Adding extra build information to executables. · Discussion #35 · ipetkov/crane · GitHub, adapting it to my specific flake seems to do the trick:

Not too sure if I can avoid the wrapping step, but hey it works.

1 Like