Python shell from `buildPythonPackage`

I’ve been working on a python package using nix-shell and a shell.nix, installing all dependencies with nix (no pip or virtualenv).

I now converted that shell.nix to a default.nix in the vein of the ones in nixpkgs (a function with dependencies as parameters, and a buildPythonPackage) because I’m thinking of using it for deployment.

But I’d like to be able to drop to a shell like before, with a python with all the dependencies set up.

How do I write a shell.nix that uses my default.nix to get to that point?

Something like this:

{ pkgs ? import ./pin.nix {} }:
with pkgs;
with pkgs.python.pkgs;
let thePackage = callPackage ./default.nix {};
in mkShell {
  propagateBuildInputs = [

builds the package OK and gives me the right python version, but with no dependencies importable.

(Oh, I’d need to have also the test dependencies, to run tests manually.)

This works, sort of:

{ pkgs ? import ./pin.nix {} }:
with pkgs;
with pkgs.python.pkgs;
let crawlers = callPackage ./default.nix {};
in (pkgs.python.buildEnv.override {
  extraLibs = crawlers.propagatedBuildInputs;

but no test dependencies.

You should be able to do nix-shell default.nix.

probably the easiest solution would be to import your default.nix from your shell.nix. nix-shell should do the right thing

Once I deleted the that worked, but I still don’t have the test dependencies.

nix-shell default.nix -A "" may also work

Is there any way to access the checkInputs of a Python derivation?

checkInputs aren’t included in the shellHook logic:

  buildInputs = mergeInputs "buildInputs";
  nativeBuildInputs = mergeInputs "nativeBuildInputs";
  propagatedBuildInputs = mergeInputs "propagatedBuildInputs";
  propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs";

  shellHook = lib.concatStringsSep "\n" (lib.catAttrs "shellHook"
    (lib.reverseList inputsFrom ++ [attrs]));

sounds like you want a python development environment. I would recommend looking at

But I don’t want to use pip…


  pkgs = import <nixpkgs> {};
in pkgs.mkShell (import ./default.nix).overrideAttrs(oldAttrs: {
  buildInputs = oldAttrs.buildInputs ++ oldAttrs.checkInputs;

Hmmm, no luck. It says checkInputs is not an attribute. I’ll try some more tomorrow, but for now, thanks :slight_smile:

This is a shell.nix that works for me:

{ pkgs ? import ./pinned.nix {} }:
with pkgs;
with pkgs.python.pkgs;
  crawlers = callPackage ./default.nix {};
  pydrv = (pkgs.python.buildEnv.override {
    extraLibs = crawlers.buildInputs ++ crawlers.nativeBuildInputs ++ [
      # Development stuff
      mypy pylama pylint black isort ipython
      # Deployment stuff
in mkShell {
    pydrv crawlers.buildInputs jre
    # Development stuff
    nodejs yarn

Only problem is that jre is in the checkInputs of default.nix, but needs to be mentioned again here. Can live with that