Can't update system: Filesystem error

Hello there! I’m completely new to NixOS, currently Dual-booting it with ArchLinux.
nixpkgs-version is 24.11, nix --version is 2.24.10.
I can’t say when, what change in the config caused it, but suddenly, when trying to rebuild with sudo nixos-rebuild --flake .#, I got this error message:

warning: Git tree '/home/sfn/garnix' is dirty
building the system configuration...
warning: Git tree '/home/sfn/garnix' is dirty
evaluation warning: sfn profile: You have enabled hyprland.systemd.enable or listed plugins in hyprland.plugins but do not have any configuration in hyprland.settings or hyprland.extraConfig. This is almost certainly a mistake.
error: filesystem error: read_symlink: Invalid argument [/nix/var/nix/profiles/system-profiles/nix]
Traceback (most recent call last):
  File "/nix/store/awfzzpdk2jk5wy61l0l3p3wfn92yzrzf-systemd-boot/bin/systemd-boot", line 435, in <module>
    main()
  File "/nix/store/awfzzpdk2jk5wy61l0l3p3wfn92yzrzf-systemd-boot/bin/systemd-boot", line 418, in main
    install_bootloader(args)
  File "/nix/store/awfzzpdk2jk5wy61l0l3p3wfn92yzrzf-systemd-boot/bin/systemd-boot", line 363, in install_bootloader
    gens += get_generations(profile)
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/awfzzpdk2jk5wy61l0l3p3wfn92yzrzf-systemd-boot/bin/systemd-boot", line 213, in get_generations
    gen_list = run(
               ^^^^
  File "/nix/store/awfzzpdk2jk5wy61l0l3p3wfn92yzrzf-systemd-boot/bin/systemd-boot", line 58, in run
    return subprocess.run(cmd, check=True, text=True, stdout=stdout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/zv1kaq7f1q20x62kbjv6pfjygw5jmwl6-python3-3.12.7/lib/python3.12/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/nix/store/w4l4xvw461ywc4ia3accj5i3hh50n4r8-nix-2.24.10/bin/nix-env', '--list-generations', '-p', '/nix/var/nix/profiles/system-profiles/nix']' returned non-zero exit status 1.
Failed to install bootloader
warning: error(s) occurred while switching to the new configuration

What does this actually mean, and how do I fix it.
Thank you for your help!

The NixOS bootloader scripts have had such longstanding bugs. If you’re willing to delete previous generations, do that and rebuild. If not, report this on github since there’s currently no open issues about it.

Thank you for your answer! To delete previous generations, do I just run sudo nixos-garbage -d and then rebuild my configuration?