Hi, NixOS community, newbie here!
I’m trying to build my project using nix flake
s and fail to expose custom .so
libraries to CMake.
The CMake error message: Could not find DAHUA_NET_SDK using the following names: dhnetsdk
. Where dhnetsdk corresponds to libdhnetsd.so
.
Obviously CMake’s find_library()
can’t simply locate this foreign .so
.
What I’ve done:
- Created a
flake.nix
in my project that looks like this (showing onlyoutputs
section):
outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in
{
packages.${system}.default = (pkgs.callPackage ./default.nix { inherit pkgs; });
devShells.${system}.default = { ... };
...
};
- Created a
default.nix
to host my project derivation:
{ pkgs ? import <nixpkgs> { } }:
pkgs.llvmPackages_latest.stdenv.mkDerivation rec {
pname = "lithium";
version = "0.2.9";
src = ./.;
nativeBuildInputs = with pkgs; [ cmake ];
buildInputs = with pkgs; [
cmake
clang
jsoncpp
zlib
libuuid
(pkgs.callPackage ./dahua-package.nix { }).dahua-avnetsdk
(pkgs.callPackage ./dahua-package.nix { }).dahua-dhnetsdk
(pkgs.callPackage ./dahua-package.nix { }).dahua-dhconfigsdk
];
cmakeFlags = [
"-DLITHIUM_USE_SUBDMODS=ON"
...
];
}
- And finally created
dahua-package.nix
to store a set of derivations with my custom.so
files:
{ pkgs ? import <nixpkgs> { } }:
let
basename = "dahua";
origin = "https://github.com/danny-mhlv/dahua-c-wrapper/releases/download/0.0.1";
in
with pkgs;
{
"${basename}-dhnetsdk" = pkgs.stdenv.mkDerivation rec {
pname = "libdhnetsdk";
version = "1.0.0";
dontUnpack = true;
src = fetchurl {
url = "${origin}/${pname}.so";
hash = "sha256-tzXLd2Mv/HoouN/eSfnJGPUPywxRrPZgPTx5QkmWpUA=";
};
phases = [ "unpackPhase" "installPhase" ];
installPhase = ''
mkdir -p $out
cp $src $out
'';
};
...
}
As you can see for my .so
dependencies - I simply fetch them from the web and copy to the $out
.
You can see from the configurations provided, I’m including my derivations via callPackage
in buildInputs
section of my project’s derivation.
I’ve tried to investigate it myself, but couldn’t find any examples where some 3rd party, God forbidden .so
files would be pulled into a C++ project.
So the question is: how can I use .so
files fetched from the web in my project build?