Support request: conflicting definition of homeDirectory while integrating nix-darwin and home-manager

I’m a Nix noob, incrementally managing my macOS setup with Nix. Having successfully started using nix-darwin and home-manager separately (with darwin-rebuild switch and home-manager switch), I’m now trying to combine them, using the nix-darwin module home-manager provides. When I do, darwin-rebuild fails due to conflicting definitions. Could someone please cast an eye over my configuration and point out what I’m sure is the stupid mistake I’ve made? If you notice other idiocy in passing, please feel free to point it out (e.g. I’ve currently got a massive vimrc inlined into a configuration file, and I should definitely pull that into a separate file; but there are doubtless many other things I’m doing wrongly).

My configuration is specified in the following two files:

When I darwin-rebuild switch, I get the following error:

➜  darwin-rebuild switch
building the system configuration...
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error: The option `home-manager.users.Patrick.home.homeDirectory' has conflicting definition values:
- In `/Users/Patrick/.nix-defexpr/channels/home-manager/nix-darwin': "/var/empty"
- In `/Users/Patrick/.nixpkgs/darwin-configuration.nix': "/Users/Patrick"
(use '--show-trace' to show detailed location information)        

The detailed location information can be found below the fold.

I understand what this is saying: the default home-manager-provided module for nix-darwin specifies a home directory of /var/empty, but my own darwin-configuration.nix specifies /Users/Patrick. I have a mental model in which it makes sense for home-manager's module to have a default home directory that’s completely separate from anything it might blat when installing into an existing setup; is that indeed why it specifies this home directory?

I have the general impression that it’s possible to set the priority of one definition over the other, e.g. from Conflicting definitions for programs.ssh.askPassword in plasma5 and seahorse · Issue #75867 · NixOS/nixpkgs · GitHub. Is that the right thing to do here?

Thanks in advance,
Patrick


Detailed location information:

➜  darwin-rebuild switch --show-trace
building the system configuration...
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error: while evaluating the attribute 'config.system.build.toplevel' at undefined position:
while evaluating 'g' at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/attrsets.nix:298:19, called from undefined position:
while evaluating anonymous function at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/modules.nix:140:72, called from /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pr
e299952.7918dc5148d/nixpkgs/lib/attrsets.nix:301:20:
while evaluating the attribute 'value' at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/modules.nix:525:9:
while evaluating the option `system.build':
while evaluating the attribute 'mergedValue' at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/modules.nix:557:5:
while evaluating 'merge' at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/types.nix:386:20, called from /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918d
c5148d/nixpkgs/lib/modules.nix:559:59:
while evaluating 'filterAttrs' at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/attrsets.nix:124:23, called from /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299
952.7918dc5148d/nixpkgs/lib/types.nix:387:35:
while evaluating anonymous function at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/attrsets.nix:125:29, called from /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11p
re299952.7918dc5148d/nixpkgs/lib/attrsets.nix:125:18:
while evaluating anonymous function at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/types.nix:387:51, called from /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre2
99952.7918dc5148d/nixpkgs/lib/attrsets.nix:125:62:
while evaluating the attribute 'toplevel' at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/attrsets.nix:366:7:
while evaluating anonymous function at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/types.nix:387:86, called from /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/attrsets.nix:366:15:
while evaluating the attribute 'optionalValue' at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/modules.nix:569:5:
while evaluating the attribute 'values' at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/modules.nix:551:9:
while evaluating the attribute 'values' at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/modules.nix:650:7:
while evaluating anonymous function at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/modules.nix:537:28, called from /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/modules.nix:537:17:
while evaluating definitions from `/nix/store/syidmwxgh41rmxqrmh6vm1h6wwihw5xd-darwin/darwin/modules/system':
while evaluating 'dischargeProperties' at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/modules.nix:609:25, called from /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/modules.nix:538:137:
while evaluating the attribute 'value' at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/types.nix:391:60:
while evaluating 'throwAssertions' at /nix/store/syidmwxgh41rmxqrmh6vm1h6wwihw5xd-darwin/darwin/modules/system/default.nix:13:21, called from /nix/store/syidmwxgh41rmxqrmh6vm1h6wwihw5xd-darwin/darwin/modules/system/default.nix:73:29:
while evaluating anonymous function at /nix/store/syidmwxgh41rmxqrmh6vm1h6wwihw5xd-darwin/darwin/modules/system/default.nix:11:50, called from undefined position:
while evaluating the attribute 'assertion' at /Users/Patrick/.nix-defexpr/channels/home-manager/nix-darwin/default.nix:110:32:
while evaluating the attribute 'assertion' at /Users/Patrick/.nix-defexpr/channels/home-manager/modules/home-environment.nix:417:9:
while evaluating the attribute 'home.homeDirectory' at undefined position:
while evaluating 'g' at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/attrsets.nix:298:19, called from undefined position:
while evaluating anonymous function at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/modules.nix:140:72, called from /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/attrsets.nix:301:20:
while evaluating the attribute 'value' at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/modules.nix:525:9:
while evaluating the option `home-manager.users.Patrick.home.homeDirectory':
while evaluating the attribute 'mergedValue' at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/modules.nix:557:5:
while evaluating 'mergeEqualOption' at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/options.nix:137:27, called from /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/modules.nix:559:59:
while evaluating anonymous function at /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/options.nix:143:26, called from /nix/store/0zgv90z5sii3hphzr1zlvdvchrlcwwy6-nixpkgs-21.11pre299952.7918dc5148d/nixpkgs/lib/options.nix:143:11:
The option `home-manager.users.Patrick.home.homeDirectory' has conflicting definition values:
- In `/Users/Patrick/.nix-defexpr/channels/home-manager/nix-darwin': "/var/empty"
- In `/Users/Patrick/.nixpkgs/darwin-configuration.nix': "/Users/Patrick" 

The answer turned out to be very simple, though it took me days to find: delete my own /Users/Patrick specification from the home-manager config file home.nix. I don’t really know why, but my guess is that this is a custom override option that only works for specifying a user from scratch, whereas I was trying to overlay a Nix setup on top of an existing user.

1 Like

Thanks for sharing!

Just ran in to the same “issue”, except I had to add the home folder configuration to my nix-darwin setup.

The issue has a bit annoying to debug because:

  • The errors were not pointing to specific files. They came from two <anonymous function> sites (perhaps because I’m using flakes?).
  • I was able to “successfully misconfigure” it. I only noticed something was broken when I couldn’t read my GPG keys. GPG was trying to source its config from /var/empty/.gnupg.

I got started with nix by just implementing home-manager. Now I’m trying to implement nix-darwin (with flakes) with my existing home.nix and I’m hitting this error.

@aisamu Can you clarify where you added the home folder config?

I figured out to put in in the configuration.nix file that was called by the flake.nix

{ pkgs, lib, ... }:
{
  # Nix configuration ------------------------------------------------------------------------------

  nix.settings.substituters = [
    "https://cache.nixos.org/"
  ];
  nix.settings.trusted-public-keys = [
    "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
  ];
  nix.settings.trusted-users = [
    "@admin"
  ];
  nix.configureBuildUsers = true;

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

  # Enable experimental nix command and flakes
  # nix.package = pkgs.nixUnstable;
  nix.extraOptions = ''
    auto-optimise-store = true
    experimental-features = nix-command flakes
  '' + lib.optionalString (pkgs.system == "x86_64-darwin") ''
    extra-platforms = x86_64-darwin aarch64-darwin
  '';

  # Create /etc/bashrc that loads the nix-darwin environment.
  programs.zsh.enable = true;

  # Auto upgrade nix package and the daemon service.
  services.nix-daemon.enable = true;

 
  

  

 
}

I added it to the top-level flake, but I think you’re right and it should probably live on the darwin-configuration.nix module:

{
  ...
  outputs = { self, darwin, home-manager, ... }@inputs: {
    darwinConfigurations."zzzzz" =
      ...
      darwin.lib.darwinSystem {
        ...
        modules = [
          ...
          ./darwin-configuration.nix
          {
            users.users.aisamu.home = "/Users/aisamu";
          }
          home-manager.darwinModule
          {
            home-manager = {
              ...
              users.aisamu = import ../.config/nixpkgs/home.nix;
            };
          }
        ];
      };
  };
}