ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '_cmp.pyi

I’m trying to install jupyter-book, and I’ve got as far as installing one of its dependencies, attrs. But when the builder runs it gives this error:

warning: Git tree '/home/jon/Code/book-computational-literary-analysis' is dirty
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/z9hkqa5qfvpqjjikv6m6fahfia37k07q-python3-3.8.9-env.drv' failed to build

What’s going on here, and how do I fix it? It looks like it’s attempting to uninstall another version of the package, which wouldn’t be possible with Nix. So how can I tell buildPythonPackage not to look for existing installs?

This is what I have so far.

Any chance the attrs wheel just produces a write-only file that nix tries to patch for nix reasons? Maybe a postUnpackPhase with chmod +w some/file would do the trick.

How would one do that? I have no idea where to find the files that are produced mid-build. Or how to find a list of phases that the python builder is running. Or where to find documentation on that builder, and how it works.

The docs are here: NixOS - Nixpkgs 21.05 manual

A list of phases and detailed docs on the nixpkgs build process is here: NixOS - Nixpkgs 21.05 manual

Looks like you’re using flakes? The simplest way to debug during the build is just to plop down an ls -l in one of the phases and look at the output of nix build -L :slight_smile:

For more proper debugging nix shell nix develop can enter the build env during specific phases.

1 Like

Looks like you’re using flakes? The simplest way to debug during the build is just to plop down an ls -l in one of the phases and look at the output of nix build -L :slight_smile:

Where exactly is “in one of the phases”?

I know where the nixpkgs manual is, but there isn’t any documentation there about the phases of the python builder. Nowhere do I see anything about pipInstallPhase, for instance, which is where this is failing.

1 Like

The docs do mention how this is implemented, and point to the python build hooks that live in this directory, and are included in mk-python-derivation here.

pipInstallPhase in particular lives here.

I’d assumed you were looking for general documentation as you said you have “no idea”. I would suggest using text search on the nixpkgs repo occasionally when looking for implementation details of particular languages/frameworks, since those don’t always manage to bubble up to the public docs.

That said, I don’t think full knowledge of that is per-se necessary if you have nix develop and general knowledge of the build phases as defined in the stdenv.

Ok so I ran nix develop but I’m getting this error:

✦ ❯ nix develop
warning: Git tree '/home/jon/Code/book-computational-literary-analysis' is dirty
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/3j9b3518z3ggfpq09k3552wr3hq9qpjl-python3-3.8.9-env-env.drv' failed to build

It appears to be the same error.