LnL7 / nix-darwin

nix modules for darwin
MIT License
3.13k stars 451 forks source link

Something with /var/empty as a home directory is messing up home manager #423

Closed devins2518 closed 2 years ago

devins2518 commented 2 years ago

I was having an issue with GPG where $GNUPGHOME was set to /var/empty/.gnupg and caused all signing to fail since it couldn't read or write there. I attempted to fix this by adding this to my config:

  programs.gpg = {
    enable = true;
    homedir = "${config.xdg.dataHome}/.gnupg";
  };

However, this didn't fix the issue. $GNUPGHOME was being set to /var/empty/.local/share/.gnupg now. My fix is now this:

  programs.gpg = {
    enable = true;
    homedir = "/Users/devin/.local/share/.gnupg";
  };

This is obviously not ideal and not portable.

I suspect that this is an issue with nix-darwin as it hasn't happened with my NixOS system which doesn't require this fix.

devins2518 commented 2 years ago

I found this issue https://github.com/nix-community/home-manager/issues/2004 which alluded to the fact that users.users.<username>.home is set to /var/empty by default, but doesn't seem to be set to the proper directory unless you define a user account. Is there any way to send out a warning or error message if there's no user accounts defined? I'll close the issue, but the examples or documentation should show that this issue will be caused if you don't set user accounts.

FlakM commented 2 years ago

@devins2518 I think I've bumped into the same issue. Could you please provide some information about the way you managed to solve this? For me defining the home results in error https://github.com/FlakM/nix_dots/blob/bf3878f0471cdb78f170ae7461dfc52a1d517292/.nixpkgs/home-manager/pro.nix#L11

❯ darwin-rebuild switch --flake .
building the system configuration...
error: The option `home-manager.users.mflak.home.homeDirectory' has conflicting definition values:
       - In `<unknown-file>': "/Users/mflak"
       - In `/nix/store/4ibd0n5jnaznp0cjg86r7g0ql0l8hcpi-source/nixos/common.nix': "/var/empty"
(use '--show-trace' to show detailed location information)
devins2518 commented 2 years ago

As explained above, this is how I set up my home directory in a Darwin specific configuration file.

https://github.com/devins2518/dotfiles/blob/c0bd22b155f2a8167f634b71a65a80d08684fef2/defaults-darwin.nix#L28-L37

  users = {
    users = {
      devin = {
        shell = pkgs.zsh;
        description = "Devin Singh";
        home = "/Users/devin";
      };
    };
  };
mattsawyer77 commented 2 years ago

@FlakM I ran into this as well. I think you need to add

users.users.mflak = {
  name = "mflak";
  home = "/Users/mflak";
};

I'm not sure why my configuration was working before without it, but essentially your home-manager user and users.user need to match, IIUC.