nix-community / home-manager

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

Error: HOME is set to "/Users/xxx" but we expect "/var/empty" #4026

Closed sxyazi closed 1 year ago

sxyazi commented 1 year ago

Are you following the right branch?

Is there an existing issue for this?

Issue description

I encountered the error when I rebuilt after updating.

It's supposed to be caused by https://github.com/nix-community/home-manager/commit/6a1922568337e7cf21175213d3aafd1ac79c9a2e. I'm on the Darwin system.

Maintainer CC

@rycee

System information

- system: `"aarch64-darwin"`
 - host os: `Darwin 22.5.0, macOS 13.4`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.13.3`
 - channels(root): `"nixpkgs"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
ncfavier commented 1 year ago

You should probably set your home directory to /Users/xxx in your nix-darwin configuration. I'm not sure how anything would work without it.

ncfavier commented 1 year ago

Hmm, it seems like Home Manager's homeDirectory defaults to $HOME if the stateVersion is < 20.09. @rycee maybe we should skip the check in this situation?

sxyazi commented 1 year ago

Wow, It works after setting users.users.xxx.home, thanks! Not sure if it's a breaking change, my stateVersion is 23.05.

rycee commented 1 year ago

Ouch. I'm not sure what the correct way to use nix-darwin is in this case. It seems you are expected to explicitly set the home directory? There doesn't seem to be an isNormalUser option like in NixOS.

@LnL7 The default home directory of a user in nix-darwin seems to be set to /var/empty, which I would guess is not the right choice except for some system users. I assume that regular users are expected have an explicitly set users.users.<name>.home option?

We recently introduced a check in the Home Manager activation script that verifies that the user that the script is built for matches the user running the activation. This check led to this issue since @sxyazi had missed to set the home directory in the nix-darwin configuration.

The home directory option was originally introduced in https://github.com/LnL7/nix-darwin/commit/b8713d540c3928a800ea676f38643012c89a97dc and as far as I can tell it is mostly unchanged since then.

Perhaps nix-darwin could have something similar to NixOS's isSystemUser and isNormalUser flags to help user's get the right home directory configuration?

sxyazi commented 1 year ago

Thanks for the clear elaboration, so far it looks like setting users.users.xxx.home is the best way. I will wait a while to close the issue and see if anyone else also having the issue.

If so I will file an issue for nix-darwin and ask them to add the isSystemUser and isNormalUser flags, but this may not happen soon as nix-darwin is currently in a lack of maintenance situation.

sukhmel commented 1 year ago

@sxyazi I had the same problem after updating flakes just now. For now I used the users.users.xxx.home setting and it worked 🤷‍♂️