New Apple Silicon MacBook, Nix installation questions

Hello, I have a new M2 MacBook and just installed Nix with Determinate’s graphical Nix Darwin installer. That part worked fine, as does creating the first flake.nix with nix flake init -t nix-darwin. But when I the run nix run nix-darwin -- switch --flake . I get these errors:

byrongibson@MacBook-Pro-2 config % nix run nix-darwin -- switch --flake .
error: cannot connect to socket at '/nix/var/nix/daemon-socket/socket': Connection refused
byrongibson@MacBook-Pro-2 config % sudo nix run nix-darwin -- switch --flake .
warning: $HOME ('/Users/byrongibson') is not owned by you, falling back to the one defined in the 'passwd' file ('/var/root')
warning: $HOME ('/Users/byrongibson') is not owned by you, falling back to the one defined in the 'passwd' file ('/var/root')
warning: creating lock file '/Users/byrongibson/nix/darwin/config/flake.lock':
• Added input 'nix-darwin':
    'github:LnL7/nix-darwin/3ac7acd32db4f7111015e8d5349ff6067df01bf6' (2024-01-21)
• Added input 'nix-darwin/nixpkgs':
    follows 'nixpkgs'
• Added input 'nixpkgs':
    'github:NixOS/nixpkgs/e5d1c87f5813afde2dda384ac807c57a105721cc' (2024-01-19)
building the system configuration...
warning: $HOME ('/Users/byrongibson') is not owned by you, falling back to the one defined in the 'passwd' file ('/var/root')
error: flake 'path:/Users/byrongibson/nix/darwin/config?lastModified=1705811073&narHash=sha256-SKstJL21bfvtgqveKIGwpXeIZethgabPbVvp0McnTUU%3D' does not provide attribute 'packages.aarch64-darwin.darwinConfigurations.MacBook-Pro-2.system', 'legacyPackages.aarch64-darwin.darwinConfigurations.MacBook-Pro-2.system' or 'darwinConfigurations.MacBook-Pro-2.system'

byrongibson is the system’s main Admin user. The only changes I made to the default flake are:

      ....
      # The platform the configuration will be used on.
      #nixpkgs.hostPlatform = "x86_64-darwin";
      nixpkgs.hostPlatform = "aarch64-darwin";
    };
  in
  {
    # Build darwin flake using:
    # $ darwin-rebuild build --flake .#simple
    #darwinConfigurations."simple" = nix-darwin.lib.darwinSystem {
    darwinConfigurations."MacBook-Pro-2.attlocal.net" = nix-darwin.lib.darwinSystem {
      modules = [ configuration ];
    };

    # Expose the package set, including overlays, for convenience.
    #darwinPackages = self.darwinConfigurations."simple".pkgs;
    darwinPackages = self.darwinConfigurations."MacBook-Pro-2.attlocal.net".pkgs;
  };

Anyone see what I’m doing wrong here?

it’s looking for a configuration matching your hostname by default which looks to be “MacBook-Pro-2”, but your darwinConfiguration entry is set to “MacBook-Pro-2.attlocal.net”. I’m guessing that’s why?

If you want to use “MacBook-Pro-2.attlocal.net” then when you build the flake you’d have to explicitly add .#MacBook-Pro-2.attlocal.net and then end of your command I believe.

Thanks, modified the flake.nix to:

{
    # Build darwin flake using:
    # $ darwin-rebuild build --flake .#simple
    #darwinConfigurations."simple" = nix-darwin.lib.darwinSystem {
    darwinConfigurations."MacBook-Pro-2" = nix-darwin.lib.darwinSystem {
      modules = [ configuration ];
    };

    # Expose the package set, including overlays, for convenience.
    #darwinPackages = self.darwinConfigurations."simple".pkgs;
    darwinPackages = self.darwinConfigurations."MacBook-Pro-2".pkgs;
  };

But still getting connection refused error:

byrongibson@MacBook-Pro-2 config % nix run nix-darwin -- switch --flake .
error: cannot connect to socket at '/nix/var/nix/daemon-socket/socket': Connection refused
byrongibson@MacBook-Pro-2 config % nix run nix-darwin -- switch --flake .MacBook-Pro-2
error: cannot connect to socket at '/nix/var/nix/daemon-socket/socket': Connection refused
byrongibson@MacBook-Pro-2 config % nix run nix-darwin -- switch --flake .#MacBook-Pro-2
error: cannot connect to socket at '/nix/var/nix/daemon-socket/socket': Connection refused

That part I’m not sure about. Seems like others have and just reinstalled to fix it: [New install] error: cannot connect to socket at '/nix/var/nix/daemon-socket/socket': Connection refused · Issue #610 · LnL7/nix-darwin · GitHub

1 Like

Thanks, uninstalling and reinstalling fixed it!

1 Like