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

Hi im having an issue where trying to run sudo nixos-rebuild switch results in “failed to canonicalize /nix/store/***/kernel-modules/bzImage: No such file or directory” error.

I was trying to use flakes, and that’s around when this issue started, but even after switching back to previous setups without flakes, this problem persists. What can I do to fix this?

configuration.nix: Mozilla Community Pastebin/3kk8JHkF (JavaScript)
hardware-configuration: Mozilla Community Pastebin/vdWH3NOw (JavaScript)

full error: Mozilla Community Pastebin/z991RSzG (JavaScript)

solved by running sudo nix-collect-garbage -d

I’m having the same issue, but this problem persists even after running sudo nix-collect-garbage -d

I added --show-trace -L -v

$ sudo cat /proc/sys/kernel/hostname
$ nix --extra-experimental-features nix-command flakes build --out-link /tmp/nixos-rebuild.3Cck3R/nixos-rebuild /home/user/nixconf#nixosConfigurations."hostname".config.system.build.nixos-rebuild --show-trace -L -v
$ exec /nix/store/0ml5vq2c2gvia1zxrx8bb6izn9h0gj7j-nixos-rebuild/bin/nixos-rebuild switch --flake /home/user/nixconf --show-trace -L -v
$ sudo cat /proc/sys/kernel/hostname
building the system configuration...
Building in flake mode.
$ nix --extra-experimental-features nix-command flakes build /home/user/nixconf#nixosConfigurations."hostname".config.system.build.toplevel --show-trace -L -v --out-link /tmp/nixos-rebuild.HHHrfh/result
$ sudo nix-env -p /nix/var/nix/profiles/system --set /nix/store/4ibzwxjy21sa611q6i0zpj64ihv12p5n-nixos-system-hostname-24.11.20240624.2893f56
$ sudo systemd-run -E LOCALE_ARCHIVE -E NIXOS_INSTALL_BOOTLOADER= --collect --no-ask-password --pipe --quiet --same-dir --service-type=exec --unit=nixos-rebuild-switch-to-configuration --wait true
Using systemd-run to switch configuration.
$ sudo systemd-run -E LOCALE_ARCHIVE -E NIXOS_INSTALL_BOOTLOADER= --collect --no-ask-password --pipe --quiet --same-dir --service-type=exec --unit=nixos-rebuild-switch-to-configuration --wait /nix/store/4ibzwxjy21sa611q6i0zpj64ihv12p5n-nixos-system-mondal-24.11.20240624.2893f56/bin/switch-to-configuration switch
failed to synthesize: failed to canonicalize /nix/store/4ibzwxjy21sa611q6i0zpj64ihv12p5n-nixos-system-mondal-24.11.20240624.2893f56/kernel-modules/bzImage: No such file or directory (os error 2)
Traceback (most recent call last):
File "/nix/store/nn325cwkvi34w0104wrfbzcgc0g0zsz3-7qyzcvjy31xpad0l75wnxylzm1pxbc4l-systemd-boot", line 393, in <module>
main()
File "/nix/store/nn325cwkvi34w0104wrfbzcgc0g0zsz3-7qyzcvjy31xpad0l75wnxylzm1pxbc4l-systemd-boot", line 376, in main
install_bootloader(args)
File "/nix/store/nn325cwkvi34w0104wrfbzcgc0g0zsz3-7qyzcvjy31xpad0l75wnxylzm1pxbc4l-systemd-boot", line 323, in install_bootloader
remove_old_entries(gens)
File "/nix/store/nn325cwkvi34w0104wrfbzcgc0g0zsz3-7qyzcvjy31xpad0l75wnxylzm1pxbc4l-systemd-boot", line 221, in remove_old_entries
bootspec = get_bootspec(gen.profile, gen.generation)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/nn325cwkvi34w0104wrfbzcgc0g0zsz3-7qyzcvjy31xpad0l75wnxylzm1pxbc4l-systemd-boot", line 115, in get_bootspec
boot_json_str = subprocess.check_output([
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/6b1fqdwb3g56j5pazv8zkx9qd0mv3wiz-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/6b1fqdwb3g56j5pazv8zkx9qd0mv3wiz-python3-3.11.9/lib/python3.11/subprocess.py", line 571, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/nix/store/75q6v7rhdsj38bkg16v6m06p0flc7rvn-bootspec-1.0.0/bin/synthesize', '--version', '1', '/nix/var/nix/profiles/system-23-link', '/dev/stdout']' returned non-zero exit status 1.
warning: error(s) occurred while switching to the new configuration

My config:
github repo: my nix (flake) config