Nixos, default flake returns error when using nixos-rebuild switch

All flakes I have tried to put into my /etc/nixos directory (this is including the default flake generated by sudo nix flake init) cause nixos-rebuild switch or nixos-rebuild switch --flake /etc/nixos (it does not matter which one I use) to return this error:

error: flake 'path:/etc/nixos' does not provide attribute 'packages.x86_64-linux.nixosConfigurations."nixos".config.system.build.nixos-rebuild', 'legacyPackages.x86_64-linux.nixosConfigurations."nixos".config.system.build.nixos-rebuild' or 'nixosConfigurations."nixos".config.system.build.nixos-rebuild'

I am saying “all” flakes because the default flake causes the same issue as any others I tried. I am saying they cause this issue because when I delete the flake, nixos-rebuild switch works just fine. My issue began with others I was using trying to follow this tutorial, but then I tested with the default one and discovered it must be a deeper problem. I have no idea how to navigate this, or what kind of information I should include. The same error seems to have appeared for other people, but it always seemed to be a problem with code that my unedited flake.nix did not even have. I am at a loss. Is this the result of a classic stupid mistake? Is there information I can give that might help suss out the problem? Please let me know.

The nix flake template doesn’t set up a NixOS project. nix flakes target many different use cases, flake.nix is an entrypoint into all of them. The template flake contains just a package definition:

# flake.nix
{
  description = "A very basic flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
  };

  outputs = { self, nixpkgs }: {

    packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;

    packages.x86_64-linux.default = self.packages.x86_64-linux.hello;

  };
}

… this is useless for nixos-rebuild, it can’t do anything with that flake. For nixos-rebuild to work, you need some kind of nixosConfiguration:

# flake.nix
{
  inputs = {
    nixpkgs.url = "https://channels.nixos.org/nixos-25.05/nixexprs.tar.xz";
  };

  outputs = 
    { nixpkgs, ... }@inputs: 
    {
      nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux"; # Or whatever architecture your system is
        modules = [
          ./configuration.nix
        ];
        specialArgs.flake-inputs = inputs;
      };
    };
  };
}

I will also add that for pure NixOS configurations, flakes are almost only additional boilerplate and introduce performance penalties. npins give you the same level of input control, with better performance and less boilerplate.

That worked. Thank you very much!