Accidentally removed ~/.local/state/nix/profiles/profile

23 days ago by OliMoli2137 to c/nix

On my raspberry pi (aka oliserver) I removed ~/.local but I forgot that nix profiles are stored there, and now I can't access my home manager packages (commands, terminfo etc.). Is there a way to restore the ~/.local/state/nix/profiles/profile symlink? I already tried switching the config again. I am using nixos module home manager with den.nix, dots are here

edit: solved by setting uninstall = true in home manager, switching, and rolling back

hallettj 3 points 23 days ago

I would've thought that running switch again would put things back. But I might be able to help you out by sharing the structure of symlinks I have on my machine.

First, a couple of ideas to try. You probably lost your Nix user profile state in addition to Home Manager state. According to my searching I think some Nix commands should recreate the profile links for you. Try running nix profile list and see if that puts anything back in ~/.local/state/nix/profiles/. If it does that might get you to a point where running switch will get you going again.

Another idea: Home Manager generations have store paths that look like this:

/nix/store/0k18msqsz0cdh751a9nv3grvfg8ajn2q-home-manager-generation

Each of those has an executable called activate. Running one of those might get you set up again - possibly in a pretty old generation. I think that's a procedure you can normally use to roll back to a previous generation. I'd find a store path ending in home-manager-generation, and give it a go.

I have ~/.nix-profile linked to /home/jesse/.local/state/nix/profiles/profile. I believe that's the Nix / NixOS user profile rather than Home Manager specifically, but I think that's an important piece.

You're probably aware, but you can recreate that and other links with commands like ln -s $HOME/.local/state/nix/profiles/profile $HOME/.nix-profile.

My Nix state in .local is in ~/.local/state/nix/profiles/ which has content like this:

home-manager -> home-manager-229-link
home-manager-227-link -> /nix/store/74awmvpikhvhi3rgn8c9iznvyc6fdi9j-home-manager-generation
home-manager-228-link -> /nix/store/w2bcxdvi5ak3rbqkpjzksgrk02xvkzsr-home-manager-generation
home-manager-229-link -> /nix/store/nfngszmd3yi9i0r5mkmy56yavjsxxv3a-home-manager-generation
profile -> profile-290-link
profile-288-link -> /nix/store/pcjlhf0m8iprnglvfv5mwi6rf41yqrfd-user-environment
profile-289-link -> /nix/store/zq3lh6hr8nbm3n15avqcdjv7rlzaqr25-user-environment
profile-290-link -> /nix/store/skfbszbmc7b7i55rj91zqi9r9vv2c59a-user-environment

So that's both Home Manager generations, and Nix user profile generations. All symlinks, or symlinks to symlinks. I don't know if the generation number is stored in state somewhere. You might be able to pick an arbitrary number, pick an arbitrary home-manager-generation store path, and create the corresponding chain of two symlinks.

path: 0 26036571, hotness: undefined, score: 3, children: 1
OliMoli2137 4 points 23 days ago

thx, but I forgot to edit the post, as I already solved it

I had to set the uninstall home manager option, then switch, and roll back, it worked

but thank you for support anyway

path: 0 26036571 26038578, hotness: undefined, score: 4, children: 0

go to feed...