Help with making a Python package as a flake

I’m just trying to create a flake for a personal project that uses Jupyter Book. Since Jupyter Book isn’t in nixpkgs, I have to package that myself. nix build and nix shell both succeed fine, but then the command jupyter-book isn’t available. What am I doing wrong?

Here’s the flake,, and here’s the jupyter-book.nix module I’m importing.

The purpose of python.withPackages is creating a derivation with python binary that has access to the specified Python modules – it will not expose any other files. So if you want to have e.g. program from some package in the environment, you will need to add it to the shell explicitly.

With flakes, that is what the devShell output is for (use with pkgs.mkShell and nix develop command).

Also, I would recommend using let bindings for the custom definitions:

$ nix flake check
warning: unknown flake output 'jupyterBook'
warning: unknown flake output 'myPython'
1 Like

How can I explicitly add a package to the environment?

So I’m getting closer but now I’m getting the error:

error: builder for '/nix/store/pp9074i7bmmvfmff4lkdmnj2wkj8vdaj-python3.8-attrs-20.3.0.drv' failed with exit code 1;
       last 10 log lines:
       > Executing pipInstallPhase
       > /build/attrs-20.3.0/dist /build/attrs-20.3.0
       > Processing ./attrs-20.3.0-py2.py3-none-any.whl
       > Installing collected packages: attrs
       >   Attempting uninstall: attrs
       >     Found existing installation: attrs 21.2.0
       >     Uninstalling attrs-21.2.0:
       > ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '_cmp.pyi'
       > Consider using the `--user` option or check the permissions.
       > 
       For full logs, run 'nix log /nix/store/pp9074i7bmmvfmff4lkdmnj2wkj8vdaj-python3.8-attrs-20.3.0.drv'.
error: 1 dependencies of derivation '/nix/store/85pch33lksbp8g0d7jhyawlpmyiwl7n8-python3-3.8.9-env.drv' failed to build

Does anyone know how to fix this kind of error?