Mkderivation magic

So I’m working on getting cadquery to work on NixOS. cadquery has a dependency on pythonocc which isn’t in nixpkgs so I tried writing my own nix expression to build it.
t has some dependencies on packages that are in nixpkgs however they have differing version so I have rewritten the existing nix expressions to use the required version. This seems to work fine and compilation of all packages succeeds without issues.

However once compilation is finished pythonocc is not available from within python when I launch a nix-shell. pythonocc uses cmake to build and there are flags which can be set to control where certain libraries are and where to install. These are set by nix using cmakeFlags. During compilationd I can see they are passed to cmake since the following is written to the terminal:

cmake flags: -DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_SKIP_BUILD_RPATH=ON -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/3qv70m5a7sbzamxj1m886qwbdmf25chv-pythonocc-core/include -DCMAKE_INSTALL_LIBDIR=/nix/store/3qv70m5a7sbzamxj1m886qwbdmf25chv-pythonocc-core/lib -DCMAKE_INSTALL_NAME_DIR=/nix/store/3qv70m5a7sbzamxj1m886qwbdmf25chv-pythonocc-core/lib -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_OSX_DEPLOYMENT_TARGET= -DCMAKE_OSX_SYSROOT= -DCMAKE_FIND_FRAMEWORK=last -DCMAKE_STRIP=/nix/store/0y7jmqnj48ikjh37n3dl9kqw9hnn68nq-binutils-2.31.1/bin/strip -DCMAKE_RANLIB=/nix/store/0y7jmqnj48ikjh37n3dl9kqw9hnn68nq-binutils-2.31.1/bin/ranlib -DCMAKE_AR=/nix/store/0y7jmqnj48ikjh37n3dl9kqw9hnn68nq-binutils-2.31.1/bin/ar -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=/nix/store/3qv70m5a7sbzamxj1m886qwbdmf25chv-pythonocc-core -Wno-desv -DPYTHONOCC_INSTALL_DIRECTORY=/nix/store/3qv70m5a7sbzamxj1m886qwbdmf25chv-pythonocc-core/lib/python3.7/site-packages/OCC -DSMESH_INCLUDE_PATH=/nix/store/qiryxmxn3naaig8n03vm59s73wrscil9-smesh/include/smesh -DSMESH_LIB_PATH=/nix/store/qiryxmxn3naaig8n03vm59s73wrscil9-smesh/lib -DPYTHONOCC_WRAP_SMESH=TRUE

however a cmake warning is emitted stating some flags are unused:

CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_EXPORT_NO_PACKAGE_REGISTRY
    PYTHONOCC_INSTALL_DIRECTORY
    PYTHONOCC_WRAP_SMESH
    SMESH_INCLUDE_PATH
    SMESH_LIB_PATH

I found this weird so started a nix-shell which has all dependencies in scope and started manually compiling pythonocc and this warning does occur but with a different set of variables:

CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_EXPORT_NO_PACKAGE_REGISTRY
    CMAKE_INSTALL_INCLUDEDIR
    CMAKE_INSTALL_LIBDIR

When I run the make install subsequentially it fails like expected since it tries to write to /nix/store however it tries to install the more then what is installed when I use the nix-expression. I really don’t know why the build is so different when I’m mkderivation. Another thing to note is that the build using nix doesn’t build doesn’t build the same targets. I really hope someone can assist me with this!

I’m using nixos 19.03

github repo with the nix expressions, the test.nix can be used to launch a shell: https://github.com/rowanG077/cadquery-nix
gist of manual compile of pythonocc in nix-shell with all dependencies: https://gist.github.com/rowanG077/57577dd27b1b0ddf4423f8ad19a86d7f#file-manual-build
gist of compiling pythonocc via nix expression: https://gist.github.com/rowanG077/57577dd27b1b0ddf4423f8ad19a86d7f#file-nix-build

open a PR for pythonocc and ping me, might be easier to give some some feedback.

t has some dependencies on packages that are in nixpkgs however they have differing version

older/more recent ?
Do you really have to set

    "-DPYTHONOCC_INSTALL_DIRECTORY=${placeholder "out"}/${python.sitePackages}/OCC"
    "-DSMESH_INCLUDE_PATH=${cq-smesh}/include/smesh"
"-DSMESH_LIB_PATH=${cq-smesh}/lib"

?

Use pname instead of name in name = "pythonocc-core";

I got it to work with some other tries. The pythonocc version is a custom form for cadquery so I can’t use the normal one.

thanks.
I want use pythonocc in python.

Similar package pivy.

but…
pythonocc 's

cmakeFlags = ‘’…
“-DPYTHONOCC_INSTALL_DIRECTORY={placeholder "out"}/{python.sitePackages}/OCC”
…’’

and
stdenv.mkDerivation to buildPythonPackage
but failed.
.
so.
After I changed to mkDerivation again.
and

              # postInstall = ''
              #   ln -sf ${placeholder "out"}/${python.sitePackages}/OCC ${self.python37.sitePackages}/
              # '';

hmm…
etc… I tried toPythonModule
but failed~ all g,.g

I wanna using buildPythonPackage for PythonOCC.
but error setup.py blah blah.
so. I tried tried…~