I have a pre-compiled library (libsomelib.so) and header file that references libusb-1.0.so, and which is a required library for a program I’m developing. As I’m new with nix, I thought I would create a flake to wrap the precompiled library:
flake.nix
{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};
outputs = { self, nixpkgs }:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
in {
packages.x86_64-linux.somelib = pkgs.stdenv.mkDerivation {
pname = "somelib";
version = "2.0.0";
src = ./.;
buildPhase = ''
echo "...nothing to build...";
'';
installPhase = ''
echo "...installing to $out...";
mkdir -p $out/lib
mkdir -p $out/include
cp -r somelibapi/*.h $out/include/
cp -r somelibapi/*.so* $out/lib/
'';
buildInputs = [
pkgs.libusb1
];
nativeBuildInputs = [
pkgs.libusb1
];
};
devShells.x86_64-linux = pkgs.mkShell {
packages = [
pkgs.libusb1
pkgs.pkg-config
];
buildInputs = [
pkgs.libusb1
pkgs.pkg-config
];
nativeBuildInputs = [
pkgs.pkg-config
];
};
packages.x86_64-linux.default = self.packages.x86_64-linux.somelib;
};
}
The library seems to “build” correctly into a package and is installed in my nix store. However, when I link it with the larger project (using a separate flake), the linker gives me an warning the libusb-1.0.so.0 is not found.
For the hell of it, I ran ldd on the libsomelib.so file:
ldd: warning: you do not have execution permission for `./libsomelib.so'
linux-vdso.so.1 (0x00007ffedc764000)
libusb-1.0.so.0 => not found
libc.so.6 => /nix/store/p9ysh5rk109gyjj3cn6jr54znvvlahfl-glibc-2.38-66/lib/libc.so.6 (0x00007f7a3cc17000)
/nix/store/p9ysh5rk109gyjj3cn6jr54znvvlahfl-glibc-2.38-66/lib64/ld-linux-x86-64.so.2 (0x00007f7a3d180000)
Why is libusb-1.0.so.0 not found? It is found in my nix store:
Any help would be appreciated!