# Where is \`callPackage\` defined exactly? (part 2)

**URL:** https://discourse.nixos.org/t/where-is-callpackage-defined-exactly-part-2/12524
**Category:** Help
**Created:** [April 17, 2021, 7:59pm UTC](https://discourse.nixos.org/t/where-is-callpackage-defined-exactly-part-2/12524 "2021-04-17T19:59:19Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![toraritte](https://discourse.nixos.org/user_avatar/discourse.nixos.org/toraritte/32/6777_2.png) [@toraritte](https://discourse.nixos.org/u/toraritte)
#### Post date: [April 18, 2021, 3:59am UTC](https://discourse.nixos.org/t/where-is-callpackage-defined-exactly-part-2/12524/6 "2021-04-18T03:59:03Z")

</div>

> [@Radvendii](#):
>
> Whew, the internals of nixpkgs make my head spin.

[You can say that again](https://www.youtube.com/watch?v=yrY9Vdi1zPA)… How long did it take for you to figure this out? The couple of lines in your answer are pretty dense with info, especially now that I’ve looked at `pkgs/top-level/splice.nix`. I’m still stuck at

```nix
in

{
  inherit splicePackages;

  # We use `callPackage' to be able to omit function arguments that can be
  # obtained `pkgs` or `buildPackages` and their `xorg` package sets. Use
  # `newScope' for sets of packages in `pkgs' (see e.g. `gnome' below).
  callPackage = pkgs.newScope {};

  callPackages = lib.callPackagesWith splicedPackagesWithXorg;

  newScope = extra: lib.callPackageWith (splicedPackagesWithXorg // extra);

  # Haskell package sets need this because they reimplement their own
  # `newScope`.
  __splicedPackages = splicedPackages // { recurseForDerivations = false; };
}

```

because it seems as if the `callPackage` definition calls the `newScope` one below. (And couldn’t even figure out where `stage.nix` comes into the picture.)

Fun times ahead:)

---

_[View the full topic](https://discourse.nixos.org/t/where-is-callpackage-defined-exactly-part-2/12524)._
