[SOLVED] bzImage causes an error when running `sudo nixos-rebuild switch` 24.05

[user@hostname:/etc/nixos]$ sudo nixos-rebuild switch 
building Nix...
building the system configuration...
failed to synthesize: failed to canonicalize /nix/store/ai3icdfc8x94bzx7rabnzcknxschq8r7-nixos-system-nixos-24.11.20240716.b9b9e4f/kernel-modules/bzImage: No such file or directory (os error 2)
Traceback (most recent call last):
  File "/nix/store/9nnalghn6ffv5j42pnkk6qjkp48z38nl-jr4rls1hlf9caafl7sy9csl2iwzd8rxm-systemd-boot", line 394, in <module>
    main()
  File "/nix/store/9nnalghn6ffv5j42pnkk6qjkp48z38nl-jr4rls1hlf9caafl7sy9csl2iwzd8rxm-systemd-boot", line 377, in main
    install_bootloader(args)
  File "/nix/store/9nnalghn6ffv5j42pnkk6qjkp48z38nl-jr4rls1hlf9caafl7sy9csl2iwzd8rxm-systemd-boot", line 324, in install_bootloader
    remove_old_entries(gens)
  File "/nix/store/9nnalghn6ffv5j42pnkk6qjkp48z38nl-jr4rls1hlf9caafl7sy9csl2iwzd8rxm-systemd-boot", line 222, in remove_old_entries
    bootspec = get_bootspec(gen.profile, gen.generation)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/9nnalghn6ffv5j42pnkk6qjkp48z38nl-jr4rls1hlf9caafl7sy9csl2iwzd8rxm-systemd-boot", line 115, in get_bootspec
    boot_json_str = subprocess.check_output([
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/4rf5qybw37b4lh1g0xczlv14sqdbmnpm-python3-3.11.9/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/4rf5qybw37b4lh1g0xczlv14sqdbmnpm-python3-3.11.9/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/nix/store/b39s3sd9qshb46aq2kbvcrjfpcwqjigv-bootspec-1.0.0/bin/synthesize', '--version', '1', '/nix/var/nix/profiles/system-43-link', '/dev/stdout']' returned non-zero exit status 1.
warning: error(s) occurred while switching to the new configuration
# /etc/nixos/configuration.nix

{ config, pkgs, ... }:

#let
 # Import flakes
#  nixpkgs = import <nixpkgs> { overlays = [ (import <nixpkgs>/overlays/flake.nix) ]; };
#in
{
  imports =
    [ # Include the results of the hardware scan.
    <nixos-hardware/lenovo/ideapad/16ach6>
      ./hardware-configuration.nix
    ];
  environment.systemPackages = with pkgs; [
  qbittorrent
  zoxide
  git
  dmidecode
  python3
  glxinfo
  neovim
  wget
  neofetch
  mpv-unwrapped
  ffsend
  brave
  (pkgs.wrapFirefox (pkgs.firefox-devedition-unwrapped.override {pipewireSupport = true;}) {})
  grim # screenshot functionality
  slurp # screenshot functionality
  wl-clipboard # wl-copy and wl-paste for copy/paste from stdin / stdout
  mako # notification system developed by swaywm maintainer
  gnome3.adwaita-icon-theme
  home-manager
  gnomeExtensions.settingscenter
  ];

# Enable OpenGL
  hardware.opengl = {
    enable = true;
  };

  # Load nvidia driver for Xorg and Wayland
  services.xserver.videoDrivers = ["nvidia"];

  hardware.nvidia = {

    # Modesetting is required.
    modesetting.enable = true;

    powerManagement.enable = false;

    powerManagement.finegrained = false;

    open = false;

    nvidiaSettings = true;

    package = config.boot.kernelPackages.nvidiaPackages.stable;
  };

  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  boot.initrd.luks.devices."luks-ed93a8e1-032f-4dd1-a7d5-a1bb9037aa24".device = "/dev/disk/by-uuid/ed93a8e1-032f-4dd1-a7d5-a1bb9037aa24";
  networking.hostName = "hostname"; # Define your hostname.
  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.

  # networking.proxy.default = "http://user:password@proxy:port/";
  # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";

  networking.networkmanager.enable = true;

  time.timeZone = "Europe/Warsaw";

  # Select internationalisation properties.
  i18n.defaultLocale = "en_US.UTF-8";

  i18n.extraLocaleSettings = {
    LC_ADDRESS = "en_GB.UTF-8";
    LC_IDENTIFICATION = "en_GB.UTF-8";
    LC_MEASUREMENT = "en_GB.UTF-8";
    LC_MONETARY = "en_GB.UTF-8";
    LC_NAME = "en_GB.UTF-8";
    LC_NUMERIC = "en_GB.UTF-8";
    LC_PAPER = "en_GB.UTF-8";
    LC_TELEPHONE = "en_GB.UTF-8";
    LC_TIME = "en_GB.UTF-8";
  };

  programs.sway = {
    enable = true;
    wrapperFeatures.gtk = true;
  };
  programs.light.enable = true;

  security.polkit.enable = true;

  programs.waybar.enable = true;

  services.xserver = {
    enable = true;  
    exportConfiguration = true;
    displayManager.gdm = {
      enable = true;  
      wayland = true; 
    };
    desktopManager.gnome.enable = true; 
  };

    systemd.packages = with pkgs.gnome3; [ gnome-session gnome-shell];

  services.libinput.touchpad.naturalScrolling = false	;

  environment.gnome.excludePackages = (with pkgs; [
  gnome-photos
  gnome-tour
]) ++ (with pkgs.gnome; [
  cheese # webcam tool
  gnome-music
  gnome-terminal
  epiphany # web browser
  geary # email reader
  evince # document viewer
  gnome-characters
  totem # video player
  tali # poker game
  iagno # go game
  hitori # sudoku game
  atomix # puzzle game
]);

  # Configure keymap in X11
  services.xserver.xkb = {
    layout = "us,pl";
    variant = "";
    options = "grp:win_space_toggle";
  };


  services.printing.enable = true;

  hardware.pulseaudio.enable = false;
  security.rtkit.enable = true;
  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
    # If you want to use JACK applications, uncomment this
    #jack.enable = true;

    # use the example session manager (no others are packaged yet so this is enabled by default,
    # no need to redefine it in your config for now)
    #media-session.enable = true;
  };

  # Enable touchpad support (enabled default in most desktopManager).
  # services.xserver.libinput.enable = true;

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.user = {
    isNormalUser = true;
    description = "user";
    extraGroups = [ "networkmanager" "wheel" "light" "video" ];
    packages = with pkgs; [
    #  thunderbird
    ];
  };
programs.firefox = {
    enable = true;
  };
  # programs.firefox.package = pkgs.latest.firefox-devedition-unwrapped;# Allow unfree packages
  nixpkgs.config.allowUnfree = true;
  nix.settings.experimental-features = [ "nix-command" "flakes" ]; # Enable flakes

  # Enable the gnome-keyring secrets vault. 
  # Will be exposed through DBus to programs willing to store secrets.
  services.gnome.gnome-keyring.enable = true;
  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  # programs.mtr.enable = true;
  # programs.gnupg.agent = {
  #   enable = true;
  #   enableSSHSupport = true;
  # };

  services.openssh.enable = true;

  # Open ports in the firewall.
  # networking.firewall.allowedTCPPorts = [ ... ];
  # networking.firewall.allowedUDPPorts = [ ... ];
  # Or disable the firewall altogether.
  # networking.firewall.enable = false;

  system.stateVersion = "24.05"; 
}

Keep in mind I am only using NixOS for about a week now, so the issue may be incredibly trivial.

fixed with: [solved] "sudo nixos-rebuild switch" results in "failed to canonicalize /nix/store/***/kernel-modules/bzImage: No such file or directory"
sudo nix-collect-garbage -d