nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.56k stars 1.73k forks source link

bug: home manager unable to switch when .config/home-manager is a symlink #4307

Open golddranks opened 1 year ago

golddranks commented 1 year ago

Are you following the right branch?

Is there an existing issue for this?

Issue description

I have been using home manager with flakes for a week without problems, having home.nix, flake.nix and flake.lock under ~/.config/home-manager/. Now I decided to move my home manager config to a git repo where I keep my other systems' (and this systems' configuration.nix) config too. It is checked out at ~/nixos_configs. So, make ~/.config/home-manager a symlink pointing ~/nixos_configs/SYSNAME/home-manager. As I test home-manager switch, it fails with following:

error: getting status of '/nix/store/2igw8w883ri968qz76rv8nw2zi8vdpcg-source/mame/home-manager': No such file or directory
error: getting status of '/nix/store/2igw8w883ri968qz76rv8nw2zi8vdpcg-source/mame/home-manager': No such file or directory
error: getting status of '/nix/store/2igw8w883ri968qz76rv8nw2zi8vdpcg-source/mame/home-manager': No such file or directory

Examining /nix/store/2igw8w883ri968qz76rv8nw2zi8vdpcg-source reveals that it's an exact copy of ~/nixos_configs except that it doesn't contain the ~/nixos_configs/SYSNAME/home-manager dir!

Trying to clean things up, uninstalling also fails:

$ home-manager uninstall
This will remove Home Manager from your system.
Really uninstall Home Manager? [y/n] y
Switching to empty Home Manager configuration...
error: file 'home-manager/home-manager/home-manager.nix' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «none»:0: (source not available)

So clearly there's something weird happening; home manager seems to be doing something with the home-manager dir that makes symlinks behave differently from actual directories.

Everything returns to normal, if I move the directory back.

After this, I tried symlinking each of the files home.nix, flake.nix and flake.lock separately. This setup works.

Maintainer CC

@rycee

System information

nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.41, NixOS, 23.05 (Stoat), 23.05.2478.bd836ac5e5a7`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.13.3`
 - channels(kon): `""`
 - channels(root): `"nixos-23.05"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
sullyj3 commented 12 months ago

After this, I tried symlinking each of the files home.nix, flake.nix and flake.lock separately. This setup works.

Fwiw I only have flake.nix linked, and it works for me. I think it understands that any imports should be relative to the real location, rather than the link location.

stale[bot] commented 9 months ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.