Inscrutable errors like these are generally nix bugs/regressions, which there seem to be a lot of lately…
Use nix 2.18 or lix. In your config, add a line like the following:
nix.package = pkgs.nixVersions.nix_2_18; # or pkgs.lix
Though, I fear, you’ll need that same version of nix on PATH
to rebuild your current config:
nix shell github:NixOS/nixpkgs/nixos-24.11#nixVersions.nix_2_18
nixos-rebuild boot <rest of your commmand here>