Nix repl flake attribute has unexpected value

I’m trying to troubleshoot building of a python package and I’ve ran into an issue that I’d like to understand before I go back to the troubleshooting at hand.

I have a flake.nix that I use to rebuild my NixOS system. It’s organized something like:

{
  inputs = { ... };
  outputs = inputs: {
    nixosConfigurations = {
      hostXyz  = import ./hostXyz inputs;
    };
  };
}

Then in hostXyz/default.nix I have:

{ nixpkgs, ... }@inputs:
nixpkgs.lib.nixosSystem {
  ...
  modules = [
    ./python/default.nix
  ];
}

Then in python/default.nix I have

{ config, pkgs, ... }@inputs:
{
  environment.systemPackages = with pkgs; [
    python3.withPackages (python-packages: with python-packages; [
      ...
      (callPackage ./some-python-package {})
      ])
    ];
}

This seems to be working fine when I do nixos-rebuild switch --flake .#hostXyz - I’m able to import this package in python just fine and it has the expected version.

However, when I fire up a nix repl session in the same folder flake.nix is and load the flake with :lf ., the load succeeds fine, but outputs.nixosConfigurations.hostXyz.pkgs.python3Packages.some-python-package either does not exist (if it’s a new package not already in nixpkgs) or points to a previous version (the one that’s in nixpkgs that is - not the new one I’m trying to upgrade it to).

What am I missing?

environment.systemPackages only adds packages to your NixOS environment, but doesn’t mutate pkgs. If you want to access the package from nix repl, consider exposing it under something like passthru or changing pkgs using nixpkgs.overlays.

Thanks @figsoda.

Not necessarily, I was just using nix repl for debugging basically. So there’s no way (without modifying the config, which I’d like to avoid) to get package details from nix repl?

Or alternatively - how is nixos-rebuild swich figuring that out? I guess I was under impression you can do everything through nix repl as well - why is that not the case?

Since you already have it in a file, just callPackageing it like you did in python/default.nix works

nixos-rebuild switch is a script that wraps nix. nix evaluates your files, and the python package ends up somewhere in nixosConfigurations.hostXyz.config.environment.systemPackages, which ends up in nixosConfigurations.hostXyz.config.system.build.toplevel and becomes part of your system