Empty manifest.json in profiles
Describe the bug
I'm using home-manager modules from within my configuration.nix. When running nixos-rebuild switch, activating the home-manager environments fails for my two users. When investigating the issue, I found that /nix/var/nix/profiles/per-user/<user>/profile/manifest.json is an empty file for both users. Older profiles are ok.
I cannot use the nix profile command to remove the broken profile, because
nix profile remove 0
error: [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal
Steps To Reproduce
I don't know how to reproduce this. I have experienced system crashes recently, but given that the profiles are in the Nix store, my assumption is that they are built somewhat atomically and hope that system crashes don't lead to half-built derivations in the store.
nix-env --version output
nix-env (Nix) 2.18.1
Additional context
I have opened an issue in home-manager about this: https://github.com/nix-community/home-manager/issues/5348 - but I guess home-manager simply uses nix profile, so it's probably better located here.
It seems people encountered empty manifest.json before:
https://github.com/NixOS/nix/issues/4742 https://github.com/NixOS/nixpkgs/issues/18279 https://discourse.nixos.org/t/home-manager-stopped-working-on-my-non-nixos/6023
Priorities
Add :+1: to issues you find important.
Nix doesn't fsync changes to the Nix store by default (see the option sync-before-registering). So in case of a system crash, manifest.json can show up as a zero-byte file. You can check for this kind of corruption by doing nix store verify -v ~/.nix-profile.
Thanks! verify -v ~/.nix-profile actually confirmed a corrupt store path. Nice to learn about the sync-before-registering, I'll try this! As far as I understand it, with that option set to false, the possiblity of this kind of corruption is expected and not a bug, right?