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.

I’m really sorry about the slow reply. I haven’t been back at my desktop for a while. I ran the command and got:

[stusmall@desktop:~]$ ls -l ~/.local/state/nix/*
total 128
lrwxrwxrwx 1 stusmall users 15 Apr  1  2024 channels -> channels-1-link
lrwxrwxrwx 1 stusmall users 60 Apr  1  2024 channels-1-link -> /nix/store/57904rflsfh46y7fxi62rzc7sidc9vmq-user-environment
lrwxrwxrwx 1 stusmall users 21 Jun 24 11:56 home-manager -> home-manager-103-link
lrwxrwxrwx 1 stusmall users 67 Jun 21 10:04 home-manager-100-link -> /nix/store/gsa1agd42s34m3c6w6jcc18xahdiv332-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Jun 24 09:52 home-manager-101-link -> /nix/store/hx5xfllmwcvqwvp3x5kx2nk0jd3pj0wk-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Jun 24 11:12 home-manager-102-link -> /nix/store/gw2z3zzbizljx80ad0dz4z5bkrngdm8m-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Jun 24 11:56 home-manager-103-link -> /nix/store/2x3dywi6ibyy3cbkrlasjkjf7h4hk4z6-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Apr  1  2024 home-manager-73-link -> /nix/store/a4m2bwjbw9190a4s64c2l1mm4b7xk031-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Apr  5  2024 home-manager-74-link -> /nix/store/vibzl3mgliyavfgvh6z7w6kf3822jypg-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Apr  8  2024 home-manager-75-link -> /nix/store/08cr5vd9vrjynnnh55imy6sx2qwlwm8k-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Apr  9  2024 home-manager-76-link -> /nix/store/13rkn08y5d4qinsq9df5k5a30lwi8y1n-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Apr 11 10:18 home-manager-77-link -> /nix/store/axxk2j2x5j2s64a90bvrq4wwm50kb87i-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Apr 15 07:53 home-manager-78-link -> /nix/store/9msmxsxsajwi0icbcwwyw456zv0vrzif-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Apr 17 10:30 home-manager-79-link -> /nix/store/f1ks9yvlb22dhwki1s6wpg6rz7d43xsj-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Apr 20 10:23 home-manager-80-link -> /nix/store/950r4079rv0z7ds2m4vkgvw4lr03xqm1-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Apr 21 07:42 home-manager-81-link -> /nix/store/xjlpgk1azrbh3jl7za7lkji9g7rg0395-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Apr 24 15:57 home-manager-82-link -> /nix/store/mivc702k7kwprbzkyrnw9cikqdr13x1x-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 May  1 10:37 home-manager-83-link -> /nix/store/9cy0jx0ni59crllrd6lxd0k6i6p4znri-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 May  1 10:55 home-manager-84-link -> /nix/store/hl3zzc8fmkzggzvdzxldfyqamnf85y3k-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 May  3 09:29 home-manager-85-link -> /nix/store/gihb178ax04d26y58bpxa0grwdclxwkl-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 May  5 19:29 home-manager-86-link -> /nix/store/vjg0izqmbfkswbxn95zc8kr1dpzbl4y1-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 May  8 07:29 home-manager-87-link -> /nix/store/02626kcip4nxw0x2fgx3v18aix7lyj74-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 May 10 15:56 home-manager-88-link -> /nix/store/4cz71fwbkyp6p2c5xp13crjjydbjp4vz-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 May 13 11:29 home-manager-89-link -> /nix/store/g7900ygv067zl6q32h8bx7mpqy51a2ki-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 May 21 07:00 home-manager-90-link -> /nix/store/39i0jvb802gk0x5m5w0rvaii9cfvylkn-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 May 21 10:40 home-manager-91-link -> /nix/store/26wsvk75as6cv97hy4n7b62i8g0r4ha3-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 May 23 08:49 home-manager-92-link -> /nix/store/cjpcxq877impwqzs80845araryd30wbl-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Jun  3 11:30 home-manager-93-link -> /nix/store/05mxs581319xbn4fyb6z3g6n7a9lf9g2-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Jun  3 16:12 home-manager-94-link -> /nix/store/s4lfi3rpjz7n5022y3kbj3vhli0dyqsh-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Jun  3 16:19 home-manager-95-link -> /nix/store/05mxs581319xbn4fyb6z3g6n7a9lf9g2-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Jun  5 09:01 home-manager-96-link -> /nix/store/93n8svv62axixa3bffkmj096bbjzvypq-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Jun 10 10:09 home-manager-97-link -> /nix/store/klr17b8i53nkd9jhh4vb0czj89777n42-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Jun 13 09:41 home-manager-98-link -> /nix/store/a1ydsp7cxvyz9kkg55302a9hhh83f2d7-home-manager-generation
lrwxrwxrwx 1 stusmall users 67 Jun 20 09:15 home-manager-99-link -> /nix/store/7v2vnwrnlrza9m11zki3q0rjcq7v7hj1-home-manager-generation

i think it is interesting that I somehow I don’t have a manifest.json

I just ran it without --repair at first. And it gave a really interesting clue:

[stusmall@desktop:~]$ sudo nix-store --verify --check-contents
[sudo] password for stusmall:
Sorry, try again.
[sudo] password for stusmall:
reading the Nix store...
checking path existence...
checking link hashes...
checking store hashes...
path '/nix/store/3lbhf6bdyqkgm5x1m1s3dhaxk2qsc76j-profile' was modified! expected hash 'sha256:0rgan1j2qpx1zb7wp5yqm5z96qg508smhr79jr19y6vjl7qcgrxb', got 'sha256:1xwcr484mva7y4542dg23vp37kpp4hpbcd179vqhcxlp4bkkpdri'
warning: not all store errors were fixed

I will run again with repair now. I’m curious on how it repairs things, but I can dig into docs for that.

EDIT:
Well, running it with --repair answered on how it will repair it, it can’t :laughing:. Honestly that makes sense.
error: cannot repair path '/nix/store/3lbhf6bdyqkgm5x1m1s3dhaxk2qsc76j-profile'

So I accepted that I was probably going to have to reformat the computer and got slowly more aggressive with deleting things and poking state. I didn’t get any luck.

Eventually I decided to:

  • Start a root shell
  • mv my home directory to a backup folder
  • restart the computer and login again
  • Since the home directory is missing, it would completely recreate it including all the nix profile state
  • copy files from my back up home directory to the newly created home directory
  • delete the back up

Things are still copying over, but it looks like it fixed it :face_with_diagonal_mouth:. Not the most graceful solution, but got me there.