[nix-shell] Calling a package with another package as argument

Hi there,

I am packaging two new python packages: One (A) depends on the other (B).

B is declared as input argument in package A like:

{ lib
, buildPythonPackage
, packageB
, pytest
}:

Now I’d like to test it, but when I call it via nix-shell and callPackage, it’s failing with this error:

error: anonymous function at /my-local-nix-tree/pkgs/development/python-modules/packageA/default.nix:1:1 called without required argument 'packageB'

Which is understandable. (If there is a way to supply this, please show :grimacing:

And this won’t work for a reason I don’t get:

nix-shell -I /my-local-nix-tree/ -p packageA
(or nix-shell -I /my-local-nix-tree/ -p python3Packages.packageA )

both are declared in the correct locations in the local clone, maybe I didn’t understand the -I parameter correctly.

Can I really use my local tree with -I parameter and/or handle this without creating a shell.nix file?

Thanks for any help.

1 Like

I think you use pkgs.callPackage, but should use pkgs.python3.pkgs.callPackage, which includes other python packages into scope.

And this won’t work for a reason I don’t get:

export NIX_PATH=nixpkgs=/my-local-nix-tree 
nix-shell -p python3.pkgs.packageA

I think -I isn’t implemented for nix-shell -p.

Can I really use my local tree with -I parameter and/or handle this without creating a shell.nix file?

yes

For single commands:

$  nix run -f . python3Packages.requests --command python -c 'print("hello")'
hello

“proper nix-shell”

$ nix-shell -I nixpkgs=./. -p python3Packages.requests

“hacky nix-shell” (nix-shell can also just evaluate an arbitrary expression)

$ nix-shell -p "with import ./. {}; with python3Packages; [ requests lxml ]"

[nix-shell:/home/jon/projects/nixpkgs]$
2 Likes

Oh my… Apparently using ~ while declaring nixpkgs was not OK with my zsh configuration. Worked with -I nixpkgs=./. and proper full path from root :man_facepalming: Thanks!