I have been attempting to build my own derivation as nixpkgs doesn’t always have the library I need. I’ve found some guides such as Hacking Your First Package — nix-tutorial documentation and Jacek's C++ Blog · Managing libraries with Nix but I’ve had no success - I get different CMake errors with each library.
For example, this is what my nix file and output looks like for the osqp-eigen library https://github.com/robotology/osqp-eigen
{
pkgs ? import <nixpkgs> {},
stdenv ? pkgs.stdenv,
}:
stdenv.mkDerivation rec {
name = "osqp-eigen";
version = "master";
src = builtins.fetchGit {
url = "https://github.com/robotology/osqp-eigen.git";
ref = "master";
};
nativeBuildInputs = with pkgs; [ cmake gcc ];
buildInputs = with pkgs; [
osqp
eigen
catch2
];
configurePhase = ''
mkdir build && cd build
cmake ../
'';
buildPhase = ''
make
'';
installPhase = ''
make install
'';
meta = {
description = "osqp-cpp";
};
}
The corresponding error output is:
these derivations will be built:
/nix/store/c3m0nxidw2inl4rxdm35rxyncyrkd869-osqp-eigen.drv
building '/nix/store/c3m0nxidw2inl4rxdm35rxyncyrkd869-osqp-eigen.drv'...
unpacking sources
unpacking source archive /nix/store/vx8pxcfw6d5kxiid1gqrrvllfbi7ga58-source
source root is source
patching sources
configuring
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /nix/store/8pbwywcj6vbswz7xmy2dh716x8blgh8w-gcc-wrapper-9.3.0/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /nix/store/8pbwywcj6vbswz7xmy2dh716x8blgh8w-gcc-wrapper-9.3.0/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Setting build type to 'Release' as none was specified.
-- Configuring done
CMake Error in CMakeLists.txt:
Imported target "osqp::osqp" includes non-existent path
"/nix/store/myrvaladws1l5dggxa2akylw3miyvi9f-osqp-0.6.0//nix/store/myrvaladws1l5dggxa2akylw3miyvi9f-osqp-0.6.0/include/osqp"
in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
* The path was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and references files it does not
provide.
CMake Error in CMakeLists.txt:
Imported target "osqp::osqp" includes non-existent path
"/nix/store/myrvaladws1l5dggxa2akylw3miyvi9f-osqp-0.6.0//nix/store/myrvaladws1l5dggxa2akylw3miyvi9f-osqp-0.6.0/include/osqp"
in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
* The path was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and references files it does not
provide.
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
builder for '/nix/store/c3m0nxidw2inl4rxdm35rxyncyrkd869-osqp-eigen.drv' failed with exit code 1
error: build of '/nix/store/c3m0nxidw2inl4rxdm35rxyncyrkd869-osqp-eigen.drv' failed
I’m unsure of how to write an idiomatic derivation for C++ libraries. I’ve come across different examples of how to include build steps inside a derivation, but often, their reasoning for the selected choices aren’t included.