Malformed json in an empty boot.json file when swithing to a new generation

i’m running this command:

sudo nixos-rebuild switch --show-trace --install-bootloader
which produces this output:

building the system configuration...
Copied "/nix/store/f8plklbbq3gwkq1wfq89i3f4wy8rabzn-systemd-258/lib/systemd/boot/efi/systemd-bootx64.efi" to "/boot/EFI/systemd/systemd-bootx64.efi".
Copied "/nix/store/f8plklbbq3gwkq1wfq89i3f4wy8rabzn-systemd-258/lib/systemd/boot/efi/systemd-bootx64.efi" to "/boot/EFI/BOOT/BOOTX64.EFI".
Random seed file /boot/loader/random-seed successfully refreshed (32 bytes).
Created EFI boot entry "Linux Boot Manager".
error: Malformed Json: Expecting value: line 1 column 1 (char 0), in /nix/store/szzrs32drnram02x7h5v5dbgk6244wdh-nixos-system-nixos-25.11pre889928.ae814fd3904b/boot.json
Failed to install bootloader
Command 'systemd-run -E LOCALE_ARCHIVE -E NIXOS_INSTALL_BOOTLOADER --collect --no-ask-password --pipe --quiet --service-type=exec --unit=nixos-rebuild-switch-to-configuration /nix/store/q7ni5zvi45jazqbq0mxw46lc1mlsa681-nixos-system-nixos-25.11.20251108.b6a8526/bin/switch-to-configuration switch' returned non-zero exit status 1.

this seems to work fine:
sudo nixos-rebuild build
nothing more is printed with --show-trace for some reason.

building the system configuration...
Done. The new configuration is /nix/store/q7ni5zvi45jazqbq0mxw46lc1mlsa681-nixos-system-nixos-25.11.20251108.b6a8526

just some basic info:
this started happening after i tried mounting a new drive.
i did it my actually just mounting it as i want and regenerating the config after.
the drive can be manually mounted in my latest working generation.
i’m using btrfs but didn’t make the new drive a subvolume, just mounted it as normal.
i did manually alter some mount options in hardware-configuration.nix to add “noatime” and “compress=zstd” but thats it.
the boot.json file it prints the path to is totall empty with a size of 0 bytes. this is indeed malformed json, but i’m really not sure why its empty. this is way beyond me as i literally started nixos yesterday. I have used nix for a while already though so i understand the basic concepts.

Thanks for any help or tips :slight_smile:

I don’t have a complete answer for you here, but note that this may not be related to your current generation, but rather a generation some distance back in your history. When nixos-rebuild is rebuilding the boot menu, it looks at all generations of the system profile and their boot.json. If something’s wrong with any of them, that’s going to cause an error like this. Check the actual store path in the error against your system generations. You may be able to just delete an old generation and get rid of the problem.

As for how this could have happened, I have difficulty imagining it unless you did something really cursed with some internal options. The most plausible option is actually filesystem corruption, I think. How sure are you that your hardware is reliable?

2 Likes

You could also try to check the path for corruption; truncation is the most common form of corruption, after all.

The nix-store or nix store commands have repair/check options/subcommands to do that (though I deleting the path is the only recourse in this case, which I think those commands will still do…?).

Edit: Ah, @tejing ninja-edited their reply so now this looks like I’m just repeating what they said :wink:

1 Like