Failed to rebuild system

I have a modularized setup on my computer. The file structure is as follows:

/etc/nixos
├── configuration.nix
├── flake.lock
├── flake.nix
├── hardware-configuration.nix
├── home
│ ├── home.nix
│ └── modules
├── modules
│ ├── boot
│ ├── desktop
│ ├── lang
│ ├── misc
│ ├── network
│ ├── security
│ ├── services
│ └── system
└── README.md

When running:

sudo nixos-rebuild switch --flake /etc/nixos#hostname

I get this error output:

warning: Git tree '/etc/nixos' is dirty
error:
       … while calling the 'seq' builtin
         at /nix/store/syvnmj3hhckkbncm94kfkbl76qsdqqj3-source/lib/modules.nix:359:18:
          358|         options = checked options;
          359|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          360|         _module = checked (config._module);

       … while evaluating a branch condition
         at /nix/store/syvnmj3hhckkbncm94kfkbl76qsdqqj3-source/lib/modules.nix:295:9:
          294|       checkUnmatched =
          295|         if config._module.check && config._module.freeformType == null && merged.unmatchedDefns != [ ] then
             |         ^
          296|           let

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: path '/nix/store/9l1scb05j5ag0fs36r9fggfd0kr0clkl-source/hardware-configuration.nix' does not exist

Something that may be important is that this configuration is centralized in the /etc/nixos directory and it contains the global system configuration and also the Home-Manager.

My flake.nix:

{
  description = "Flake NixOS + Home Manager + Plasma Manager + NUR";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    zen-browser.url = "github:0xc000022070/zen-browser-flake";

    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    plasma-manager = {
      url = "github:nix-community/plasma-manager";
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.home-manager.follows = "home-manager";
    };

    nur = {
      url = "github:nix-community/NUR";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, home-manager, plasma-manager, nur, zen-browser, ... }:
    let
      system = "x86_64-linux";
    in {
      nixosConfigurations = {
        hostname = nixpkgs.lib.nixosSystem {
          inherit system;

          modules = [
            ./configuration.nix
            nur.modules.nixos.default
            nur.legacyPackages."${system}".repos.iopq.modules.xraya

            home-manager.nixosModules.home-manager

            {
              home-manager.useGlobalPkgs = true;
              home-manager.useUserPackages = true;

              home-manager.users.guilherme = import ./home/home.nix;

              home-manager.sharedModules = [
                plasma-manager.homeManagerModules.plasma-manager
              ];
            }
          ];

          specialArgs = {
            inherit system zen-browser plasma-manager nur;
          };
        };
      };
    };
}

My configuration.nix:

{ config, pkgs, ... }:

{
  # Sistema
  system.stateVersion = "25.05";
  
  # Importações
  imports = [
    ./hardware-configuration.nix
    ./modules/security
    ./modules/services
    ./modules/network
    ./modules/desktop
    ./modules/system
    ./modules/boot
    ./modules/misc
    ./modules/lang
  ];

  # Linux
  boot.initrd.kernelModules = [ "amdgpu" ];
  boot.kernelPackages = pkgs.linuxPackages_zen;
}

Is there any way to fix this problem?
If you need, I can post the other files from my configuration here.

Quick guess: As your posted logs show that the git tree is dirty I assume that the Hardware-configuration.nix is not on the git tree.

Flakes utilize git when it’s a git repo to check for changes, thus it’s not copying files to /nix/store/ that are not on the git tree resulting in that behavior.

Sorry to ask, so I had put hardware-configuration.nix in .gitignore. Should I remove it from there? If I do that will the problem be solved?

Yes, has to be in the git repo.