Trouble packaging python "ocrmypdf" and it's depency "pikepdf"

Hey y’all i’ve struggling with this one for a while. I am not a python programmer, but have been trying to get my hands on some OCR software to make some scanned reading for class searchable.
I have been trying to keep everything in my /etc/nixos/configuration.nix layer, rather than a pkgs clone.
I packaged one dependency setuptools_scm_git_archive without too much trouble; but now I need pikepdf, which is failing for trying to access the homeless shelter.
I feel like I’m really close here, but just need a push in the right direction.
Here are all of the files:, but I will post the pikepdf derivation here.

{ lib
, fetchFromGitHub
, python37Packages
, img2pdf
, qpdf
, setuptools_scm_git_archive
with python37Packages;
buildPythonApplication rec {

  pname   = "pikepdf";
  version = "1.0.5";

  src = fetchFromGitHub {
    sha256      = "0gpdrsaf0hga5yizkiw5v1qmdn2n6gx7hsccpzz2gj0503661hd7";
    owner       = "pikepdf";
    repo        = "pikepdf";
    rev         = "v${version}";

  buildInputs = [
  checkInputs           = [ pytest pytestrunner ];
  runtimeDeps           = [ qpdf ];

  doCheck = false;

  meta = {
    description = ''
      pikepdf is a Python library for reading and writing PDF files.
    homepage =;
    license  = lib.licenses.gpl3;

And the tail of the error (the full on is at the link)

running build_ext
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/nix/store/b75brsgimlrw33l9ykhacz5fni3vq0jn-python3-3.7.2/include/python3.7m -c /build/tmpo4h638l_.cpp -o build/tmpo4h638l_.o -std=c++14
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/nix/store/b75brsgimlrw33l9ykhacz5fni3vq0jn-python3-3.7.2/include/python3.7m -c /build/tmpxijm306d.cpp -o build/tmpxijm306d.o -fvisibility=hidden
building 'pikepdf._qpdf' extension
/nix/store/sa5zlglizy5v9l9j4gchbdw6v6d71r25-python3.7-setuptools_scm-3.1.0/lib/python3.7/site-packages/setuptools_scm/ UserWarning: meta invoked without explicit configuration, will use defaults where required.
  "meta invoked without explicit configuration,"
error: [Errno 13] Permission denied: '/homeless-shelter'
builder for '/nix/store/bc94gkmwl6hv9kks4lzd5fpi0llqyprg-pikepdf-1.0.5.drv' failed with exit code 1
error: build of '/nix/store/bc94gkmwl6hv9kks4lzd5fpi0llqyprg-pikepdf-1.0.5.drv' failed

I am sure there are other little things that should be fixed, like properly integrating with the versioning of nix.pythonPackagesXX; but for now I would be satisfied just to get this bit working.

Thanks y’all!

You can try setting HOME=$TEMPDIR in preBuild or somewhere.

Sadly that didnt do the trick. After digging more i believe it is attempting to install a specific version of a dependency with pip or git and doesnt know how to install it through nix. But maybe the buildPythonApplication handles that? Im not familiar enough with pythons build tools, let alone nix’s python tools to know for sure though.

If you set NIX_DEBUG = 1 in your derivation, it will print out each command it’s running. This should help you track down what it’s trying to do.