HunterThueson / dots

Dotfiles for my NixOS configuration
GNU Lesser General Public License v2.1
0 stars 0 forks source link

`home-manager` not correctly activating upon login #55

Closed HunterThueson closed 1 year ago

HunterThueson commented 1 year ago

Upon logging into user hunter for the first time after a system boot/reboot, opening a shell shows the following message at the top (followed by the starship prompt:

bash: /home/hunter/.nix-profile/etc/profile.d/hm-session-vars.sh: No such file or directory

Running cd .nix-profile; ls (since .nix-profile is technically a symbolic link) returns the following:

.
├── activate
├── bin
│  └── home-manager-generation -> /nix/store/rws5z25d9h2irphxb6hglk2077dd14cy-home-manager-generation/activate
├── hm-version
├── home-files -> /nix/store/n7ma21yfph7a4srd62zix7p9f8wrnim2-home-manager-files
├── home-path -> /nix/store/blq8brfzjg7ywxyipq8shyg0jyw89y81-home-manager-path
└── lib
   └── nmd -> /nix/store/4f1grv7fxazjl2yzmdpd3hcz4kibcpj6-source

However, after running home-manager-generation, the error message goes away, and after running cd .nix-profile; ls once more we see the following instead:

.
├── bin -> /nix/store/blq8brfzjg7ywxyipq8shyg0jyw89y81-home-manager-path/bin
├── etc -> /nix/store/blq8brfzjg7ywxyipq8shyg0jyw89y81-home-manager-path/etc
├── lib -> /nix/store/blq8brfzjg7ywxyipq8shyg0jyw89y81-home-manager-path/lib
├── libexec -> /nix/store/blq8brfzjg7ywxyipq8shyg0jyw89y81-home-manager-path/libexec
├── manifest.nix -> /nix/store/axzwvk71fsgppdvvyyrhxchfvlz6d0fj-env-manifest.nix
├── sbin -> /nix/store/blq8brfzjg7ywxyipq8shyg0jyw89y81-home-manager-path/sbin
└── share -> /nix/store/blq8brfzjg7ywxyipq8shyg0jyw89y81-home-manager-path/share

Prior to commit a76ec98367f64d75924a4cc89297956561f84216 (Date: Wed Dec 7 20:57:55 2022 -0700), any user-specific packages specified in users/hunter.nix were also not available on the system. This (plus the presence of an activate script in ~/.nix-profile/) leads me to believe that home-manager itself is simply not activating upon login.

Strangely, this issue only applies to the user hunter; user ash works just fine.

I'm pretty sure this issue is happening because I (at the behest of some well-meaning soul on the NixOS discord) recursively deleted the entire directory at /nix/var/nix/profiles/system-profiles/. This accomplished my goal at the time, which was to remove old/deprecated GRUB menu entries that had been generated using nixos-rebuild -p test, putting them in a test folder that was (to our knowledge) untouchable by nix-collect-garbage, nixos-rebuild, etc. Those generations were successfully removed from the GRUB menu (and were presumably deleted after running nix-collect-garbage one more time), but that was when all this trouble with home-manager-generation started happening.

There is one final point of interest I should mention before submitting this issue.

Here is the output from running ls --no-icons --color=never -T /nix/var/nix/profiles/per-user/ash:

/nix/var/nix/profiles/per-user/ash
├── home-manager -> home-manager-15-link
├── home-manager-1-link -> /nix/store/ypp5lgvvylsfxanw32zdbzmvhpayrzjb-home-manager-generation
├── home-manager-2-link -> /nix/store/zfb9hwly7w3n5cadj609jwpj5xlk6bi7-home-manager-generation
├── home-manager-3-link -> /nix/store/pg199285wmzmldaywqy2rfmds52scaax-home-manager-generation
├── home-manager-4-link -> /nix/store/mv1py04i370iq6k20vvj2apsna395sas-home-manager-generation
├── home-manager-5-link -> /nix/store/1p837fd22wyl1z9nsn8ix22fapjgrwxy-home-manager-generation
├── home-manager-6-link -> /nix/store/izxx2ww3vc7bx2ifqwkwmw83wp9k53dx-home-manager-generation
├── home-manager-7-link -> /nix/store/5hmp3znnqvdb5m0243g4jc9yrsd58p6v-home-manager-generation
├── home-manager-8-link -> /nix/store/f6g7pqlbs16n1v7lb5qwv2rvdh3apsma-home-manager-generation
├── home-manager-9-link -> /nix/store/7cm54fl29hhfnz1k0iih11hkbhqdwwdb-home-manager-generation
├── home-manager-10-link -> /nix/store/1wq5wfsl15b2v2abdjx7w4fg1iq2nj38-home-manager-generation
├── home-manager-11-link -> /nix/store/zmqsr7cfsmziw56r8c8g0h71kxddcsww-home-manager-generation
├── home-manager-12-link -> /nix/store/mdw35q35v7saky54sv8ji7bifc4ahz8k-home-manager-generation
├── home-manager-13-link -> /nix/store/irpmvzr6c6ydc8ra7r4kd4k2yig4m80j-home-manager-generation
├── home-manager-14-link -> /nix/store/cb8qbvjid53ch9xlq6ys67cj0czh1whk-home-manager-generation
├── home-manager-15-link -> /nix/store/vipfmgd6q23zvdn4lrwqrb0gajypd5ri-home-manager-generation
├── profile -> profile-27-link
├── profile-8-link -> /nix/store/chvz5iwfv7fa156zr6z1qsd4qvrc329i-user-environment
├── profile-9-link -> /nix/store/lp5756nnzm3gs3ax57irzi85bh6kps4v-user-environment
├── profile-10-link -> /nix/store/529ns531k184bl5nrvjfdy7bn1ywic19-user-environment
├── profile-11-link -> /nix/store/4rgf2kqpdkrinbckcd2a7fll15adpd4l-user-environment
├── profile-12-link -> /nix/store/ln90llafqvkvki84k87wrbzp6ia72kci-user-environment
├── profile-13-link -> /nix/store/f7qrg6nj717qk7c6js0rq3sd1xarp1sl-user-environment
├── profile-14-link -> /nix/store/57904rflsfh46y7fxi62rzc7sidc9vmq-user-environment
├── profile-15-link -> /nix/store/qmkj96008b3277gs754vi4zcmrdhf8jx-user-environment
├── profile-16-link -> /nix/store/3787dl2ncriakspzkppvfvn8aiv47mpy-user-environment
├── profile-17-link -> /nix/store/jyp3x5idvc0zqiixgnbq5zm9p21dhy35-user-environment
├── profile-18-link -> /nix/store/d5n7kn5w1skx7k3kanpn710pz7lklkij-user-environment
├── profile-19-link -> /nix/store/h6nl722qcbbi0qc6szffszbwyhfvhmy2-user-environment
├── profile-20-link -> /nix/store/iqaffym74pjymrg97vgzdh7cniznnz82-user-environment
├── profile-21-link -> /nix/store/j508x94nyfjfr8irds4mwkhgr21qr9fa-user-environment
├── profile-22-link -> /nix/store/vpv3c0cxprwwzkm3cxa78bd6pkiqmrmw-user-environment
├── profile-23-link -> /nix/store/y7qxqwfr1pls4nihwb6h70lrw4w8pc7y-user-environment
├── profile-24-link -> /nix/store/20xq9rbx8kz6gs4v67788k7jkfnjhnnx-user-environment
├── profile-25-link -> /nix/store/hdk8f7dby1gxc4rcc7nf66wxnf4rrsh5-user-environment
├── profile-26-link -> /nix/store/kkh06gniav7p8qqd8snrj8alrz6h97d8-user-environment
└── profile-27-link -> /nix/store/ffv320f0hcc13dqp7r7r7mx1s7axym7c-user-environment

and here is the output from running ls --no-icons --color=never -T /nix/var/nix/profiles/per-user/hunter:

/nix/var/nix/profiles/per-user/hunter
├── channels -> channels-2-link
├── channels-2-link -> /nix/store/4db6k8yq2j5rjq98kc67r57dpqr158cl-user-environment
├── home-manager -> home-manager-135-link
├── home-manager-18-link -> /nix/store/nx9560p18pwf1n5k6lkz9bpiqpj3r134-user-environment
├── home-manager-19-link -> /nix/store/fyf4vcj136maah1jc66frz3cds23gb7a-home-manager-generation
    # ...
    # lots of generations here, you get the picture
    # ...
├── home-manager-134-link -> /nix/store/rws5z25d9h2irphxb6hglk2077dd14cy-home-manager-generation
├── home-manager-135-link -> /nix/store/g77pfjnrpkj6q4flcrlxrd04fszldm17-user-environment
├── profile -> profile-17-link
└── profile-17-link -> /nix/store/nx9560p18pwf1n5k6lkz9bpiqpj3r134-user-environment

See the differences? There are far more profile-[number]-link files in .../ash/ than in .../hunter/. The only one listed for hunter is profile-17..., which was probably generated after I ran home-manager-generation just now. Also, hunter lists two files called channels* that are not present for ash.Do I understand what that means, or whether or not it is significant? Not at this time, no. But it may be relevant, so I'm including it in my report on the off chance I find it useful later.

Anyways, that's all I know so far about this issue. I will report back later as I learn more.

HunterThueson commented 1 year ago

Not exactly sure how this issue was resolved; I think I fixed it by running nixos-rebuild boot --upgrade-all in a TTY as root rather than using sudo in a regular alacritty window, which is how I have usually done up 'till now. It's also possible that there was some sort of fix from upstream, though, and I don't want to take credit for the fix if it wasn't actually my doing. I don't know. Whatever the cause, the point is that the issue was fixed and it can now be closed. I just hope it doesn't somehow unfix itself (again), because then I really won't know what to do.

HunterThueson commented 1 year ago

aaaaannnnddd my worst fear has been realized: the issue has un-fixed itself.

Seriously, what in the world is going wrong? I haven't even run nixos-rebuild since I closed the issue. I did edit configuration.nix and its imported .nix files a bit -- and the edits I made would definitely not run successfully if I tried to nixos-rebuild right this second, but that's just because I haven't finished yet -- but since I haven't run nixos-rebuild yet, those changes shouldn't affect home-manager, right?

I am so confused. And annoyed. But I mean, hey -- it will be really satisfying when I finally do figure it out, right? At least I have something to look forward to, I guess.

Reopened issue #55.

HunterThueson commented 1 year ago

Now it's working again! I ran nixos-rebuild just now and rebooted, and even though the changes I made to configuration.nix had nothing to do with home-manager, it's somehow working again. What the hell?! I should be glad, but it's definitely frustrating to not know how or why this is happening.

Maybe it has something to do with home-manager being out of date? I did use the --upgrade-all flag while rebuilding, so maybe it just doesn't activate properly if there are changes upstream?

I have no idea. I won't close this for now in case the problem pops up again, but it's working correctly for the time being, it seems.

HunterThueson commented 1 year ago

I was a bit suspicious of this most recent fix of the issue, so I performed a full shutdown instead of simply rebooting. Sure enough, the issue is back. I'm hypothesizing that if I run nixos-rebuild, it will fix the issue for an unlimited number of reboots, but the moment I shut all the way down, it will no longer activate home-manager properly until the next nixos-rebuild. I will have to run some more scientific tests to be sure, but that's a problem for another day.