JSON parsing errors when interacting with nix profile

I recently started seeing some issue with rebuilding my NixOS config. I traced it down to an issue with homemanager, but I’m unsure how to proceed. Whenever I try and list my nix profiles, I get a JSON parsing error.

Logging output from home-manager:

Sep 30 14:18:58 desktop systemd[1]: Starting Home Manager environment for stusmall...
Sep 30 14:19:00 desktop hm-activate-stusmall[457624]: thread 'main' panicked at zellij-client/src/os_input_output.rs:29:43:
Sep 30 14:19:00 desktop hm-activate-stusmall[457624]: could not get terminal attribute: ENOTTY
Sep 30 14:19:00 desktop hm-activate-stusmall[457624]: note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Sep 30 14:19:00 desktop hm-activate-stusmall[457624]: [64B blob data]
Sep 30 14:19:00 desktop hm-activate-stusmall[457612]: Starting Home Manager activation
Sep 30 14:19:00 desktop hm-activate-stusmall[457612]: Activating checkFilesChanged
Sep 30 14:19:00 desktop hm-activate-stusmall[457612]: Activating checkLinkTargets
Sep 30 14:19:00 desktop hm-activate-stusmall[457859]: Existing file '/home/stusmall/.config/alacritty/alacritty.toml' is in the way of '/nix/store/sf70djafmg53nyrx8gf2vk36d9l0c42h-home-manager-files/.config/alacritty/alacritty.toml', will be skipped since they are the same
Sep 30 14:19:00 desktop hm-activate-stusmall[457612]: Activating writeBoundary
Sep 30 14:19:00 desktop hm-activate-stusmall[457612]: Activating installPackages
Sep 30 14:19:00 desktop hm-activate-stusmall[457886]: error: [json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON
Sep 30 14:19:00 desktop hm-activate-stusmall[457892]: error: [json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON
Sep 30 14:19:00 desktop hm-activate-stusmall[457612]: Oops, Nix failed to install your new Home Manager profile!
Sep 30 14:19:00 desktop hm-activate-stusmall[457612]: Perhaps there is a conflict with a package that was installed using
Sep 30 14:19:00 desktop hm-activate-stusmall[457612]: "nix profile install"? Try running
Sep 30 14:19:00 desktop hm-activate-stusmall[457612]:     nix profile list
Sep 30 14:19:00 desktop hm-activate-stusmall[457612]: and if there is a conflicting package you can remove it with
Sep 30 14:19:00 desktop hm-activate-stusmall[457612]:     nix profile remove {number | store path}
Sep 30 14:19:00 desktop hm-activate-stusmall[457612]: Then try activating your Home Manager configuration again.
Sep 30 14:19:00 desktop systemd[1]: home-manager-stusmall.service: Main process exited, code=exited, status=1/FAILURE
Sep 30 14:19:00 desktop systemd[1]: home-manager-stusmall.service: Failed with result 'exit-code'.
Sep 30 14:19:00 desktop systemd[1]: Failed to start Home Manager environment for stusmall.
Sep 30 14:19:00 desktop systemd[1]: home-manager-stusmall.service: Consumed 1.393s CPU time, no IP traffic.

When I follow the suggestion in the logs and run nix profile list I get:

[stusmall@desktop:~]$  nix profile list
error: [json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON

Any suggestions on what I should try next to troubleshoot? Almost any nix profile interactions just gives me a JSON error. I tried verbose and debug logging, but couldn’t get anything more than this parsing error.

I managed to replicate your error by removing the main profile link and creating an empty file at ~/.local/state/nix/profile/manifest.json

Could you run

ls -l ~/.local/state/nix/*

You could try removing ~/.local/state/nix/profile and running nix profile list.
In my testing, this seemed to create a link there to a valid profile

This is a common case of disk corruption.
Try as advised above, as well as running sudo nix-store --repair --verify --check-contents to make sure you don’t have disk corruption in your store either.

In any case, unless you had a massive crash, forcible shutoff, or power outage recently, I would look into replacing whatever disk your home directory is on.