nativeBuildInputs is for build inputs that need to run during compilation. Runtime dependencies, such as boost, openssl, zlib and friends should be in buildInputs.
In practice this will only cause issues if you’re not compiling locally, so you don’t see the problems if you get it wrong.
Things like gcc are automatically included by mkDerivation, so you can remove that dependency. This helps make it easier to build your package on other platforms.
I suspect you’re using buildPhase because using configurePhase broke that, and therefore the nixpkgs integration. Instead, you should be using the cmakeFlags variable, and not calling cmake by hand at all - buildPhase (and installPhase) should then be left empty, makeDerivation will call make correctly for you.
By defining your own phase you override a lot of nixpkgs defaults, which are important for cross-platform support, and sometimes even just for adhering to your NixOS config.
Even if you did want to override nixpkgs defaults, using $(nproc) is not a good idea for nix packages. You’re likely to build lots of software concurrently, adding that can make memory pressure cause build failures, or at least swamp the kernel with process management.
While you can define a package in a default.nix like this, it’s better to make a top-level default.nix that calls your package in a different file using callPackage and to list each dependency as a separate function input. This allows users to use .override to change specific input dependencies, and makes it easier to upstream your package into nixpkgs (or to extend your custom package set.
Though you’d need to change your nix-build command a bit, depending on how you build your attrset. You can also just do this for a simple one-package repo:
To add, the preferred way would be to use $NIX_BUILD_CORESonly if necessary which would use the cores nix setting.
But usually, most builders will take care of this for you, if you just set enableParallelBuilding = true; (which for some builders is even the default already).
Nice! I took a look and there are some small misunderstandings to still clean up:
callPackage is only useful for allowing overrides if you let it do its job, which is to automatically take the correct libraries out of pkgs and make them arguments. So instead of this, it should look something like this:
{
zlib,
boost,
openssl,
mpi,
hdf5,
curl,
libgit2,
libsndfile,
# ... rest cut because this is an example
}:
pkgs.stdenv.mkDerivation {
buildInputs = [
zlib
boost
openssl
mpi
hdf5
curl
libgit2
libsndfile
# ... again, cutting the rest
The point of this is that with this definition someone could use e.g. nelson.override { openssl = pkgs.openssl_1_1; } or something, and get a useable build out of that (assuming the APIs are compatible). With your current code, only the entirety of pkgs can be replaced, which is not very useful.
wrapQappsHookshould be in nativeBuildInputs and I’m fairly sure eigen should be in buildInputs. gnumake is part of the stdenv and should be omitted.
Ideally, you don’t have pkgs in your function args at all - callPackage will put anything you ask for in your args (including, e.g. lib or stdenv), so there’s no need for it.