When calling `callPackage`, does `callPackageWith` get evaluated using the initial imported Nixpkgs set?

For example, in this snippet,

nix-repl> pkgs = import <nixpkgs> {}
nix-rep> pkgs.callPackage ( x: x ) {}

the last call will roughly become

pkgs.lib.callPackageWith <Nixpkgs_subset> ( x: x ) {}

My intuition tells me that the <Nixpkgs_subset> that callPackageWith will be called with is based on the same Nixpkgs set imported at the top (i.e., pkgs). Is this correct?


I will eventually sit down with pen and paper to write out what happens exactly during the 2 calls (i.e., the import and the callPackage one), because I have all the pieces right now, but the endless recursive function calls and Nix laziness keeps throwing me off.

callPackageWith comes from lib, not pkgs.

1 Like

Iā€™m not 100% sure what you were asking originally btw, but you may find this helpful:
https://nix.dev/tutorials/callpackage