Once you have a nix file that yields a nixos configuration, like in this example, you can also use nixos-rebuild build-image. e.g.
nixos-rebuild build-image --image-variant sd-card -f nixos.nix in this case. The sd-image module import is implied here. So a minimal nixos.nix here could be just
{ pkgs, ...}:
pkgs.nixosSystem {
# whatever nixos options you need
}
Everything else is handled by defaults, including the target system and nixpkgs commit. The latter defaults to your nix path - so you can just prepend NIX_PATH="nixpkgs=$path-to-nixpkgs" to pin it, if desired (there’s also various other ways, build-image supports the --flake, --file and --attr flags of nixos-rebuild)