How to resolve 'nixpkgs' was not found error without channels?

I’m running Nix 2.22.1 on macOS using home-manager and flakes, so no nix-channels.

I wrote a minimal shell.nix

let
  nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-24.05";
  pkgs = import nixpkgs { config = { }; overlays = [ ]; };
in

pkgs.mkShellNoCC { }

which fails to build when running nix-shell:

$ nix-shell
error:
       … while calling the 'import' builtin
         at «string»:1:2:
            1| (import <nixpkgs> {}).bashInteractive
             |  ^

       … while realising the context of a path

       … while calling the 'findFile' builtin
         at «string»:1:9:
            1| (import <nixpkgs> {}).bashInteractive
             |         ^

       error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)
will use bash from your environment
Detected Bash version that isn't supported by Nixpkgs (3.2.57(1)-release)
Please install Bash 4 or greater to continue.

I suppose that mkShell runs findFile which depends on <nixpkgs>. I didn’t have this problem with a mkDerivation. How can I resolve it?

Put this line to your configuration.nix.

nix.settings.nix-path = "nixpkgs=flake:nixpkgs";

Is this meant for nix-darwin? I’m not running nix-darwin. Just a Nix installation.

Oh you are using macOS, I don’t know if macOS have Configuration.nix. So I don’t know.

Since they are using home manager, nix.nixPath is the option name.

I’m looking for a deterministic way of declaring the nix shell. With a local <nixpkgs> it’ll depend on where the nix shell is run.