Um? That's trivial with flakes (and I think it was doable without flakes, but I don't really remember/care). For one-offs (I'd probably do this for your firefox example but YMMV), just tell it the version to run:
$ nix run nixpkgs#firefox -- --version
Mozilla Firefox 138.0.1
$ nix run github:nixos/nixpkgs/nixos-unstable#firefox -- --version
Mozilla Firefox 139.0.1
$ nix run github:nixos/nixpkgs/b98a4e1746acceb92c509bc496ef3d0e5ad8d4aa#firefox -- --version
Mozilla Firefox 122.0.1
Or, if you want to actually incorporate it into your system, tell the system flake to pull whatever versions you want:
and then when you pull packages say which one you want:
packages = with pkgs; [
dillo # from stable nixpkgs
nixpkgs-unstable.firefox # from unstable
nixpkgs-b98a.whatever # from some exact commit of nixpkgs
]
I assume you could do the same thing for project-level flakes, but TBH I don't usually do that so I don't have the code to hand. (In contrast with grabbing system packages from whatever version of nixpkgs I want, which I know works because I pulled the example code from the config on the machine I'm typing this comment on.)