It's possible (and I think advisable) to set your flake nixos config to set the system flake registry to point to the same nixpkgs revision that your flake uses. The nixos-starter-configs standard template has two lines that do this:
# Opinionated: make flake registry and nix path match flake inputs
registry = lib.mapAttrs (_: flake: {inherit flake;}) flakeInputs;
nixPath = lib.mapAttrsToList (n: _: "${n}=flake:${n}") flakeInputs;
That actually adds all of your flake inputs to the system flake registry. So for example if in addition to your nixpkgs
input you also have an input you named nixpkgs-unstable
then can also reference that with stuff like nix shell
. For example:
nix shell nixpkgs#hello nixpkgs-unstable#cowsay