Can't use nix develop on x86_64-darwin

Here’s a repo with the minimal code that still causes the issue for me: GitHub - ashwinmathi/broken-nix-flake

I’m currently running nix 2.8.1 on an intel macOS with nix-darwin set up to use the nix-command and flakes.

I’m expecting to be able to use commands like ‘nix develop’ ‘nix shell’ ‘nix build’ but I keep getting errors that seem to suggest the flake isn’t setting certain attributes when to me it seems like one of them is definitely explicitly set in the flake output.

shell> nix develop                        
error: flake 'git+file:///Users/$USER/Documents/Workspace/hello' does not provide attribute 'devShells.x86-64-darwin.default', 'devShell.x86-64-darwin', 'packages.x86-64-darwin.default' or 'defaultPackage.x86-64-darwin'
       Did you mean x86_64-darwin?

To use the develop command like that you need to create a devShell output. What errors do the other commands give?

nix shell produces this output

error: flake 'git+file:///Users/ashwinmathi/Documents/Workspace/broken-nix-flake' does not provide attribute 'packages.x86-64-darwin.default' or 'defaultPackage.x86-64-darwin'

       Did you mean x86_64-darwin?

nix build produces this output

error: flake 'git+file:///Users/ashwinmathi/Documents/Workspace/broken-nix-flake' does not provide attribute 'packages.x86-64-darwin.default' or 'defaultPackage.x86-64-darwin'
       Did you mean x86_64-darwin?

Edit:

I’m definitely just mad confused cuz especially in those last few commands from my perspective I’ve defined both of those things, and in the case of nix develop the manual seems to imply that any one of the items in that error message’s list would be acceptable.

I am a bit confused because it seems to suggest that you’re typoing: x86-64-darwin vs x86_64-darwin, see the first dash/underscore. But afaik _ is correct.

Could you try nix shell .#packages.x86_64-darwin.default to confirm? Maybe this is a very new nix version doing things I’ve not yet become aware of.

nix shell .#packages.x86_64-darwin.default runs with no error but doesn’t launch a new environment or anything, just puts me back to the normal shell. I’m not sure what the expected behavior of nix shell should be but I’m guessing it’s at least a little similar to what nix-shell would have looked like?

edit: disregard and see comment below please

Here’s my flake file for easier reference

{
  description = "A very basic flake";

  outputs = { self, nixpkgs }: {

    packages.x86_64-darwin.hello = nixpkgs.legacyPackages.x86_64-darwin.hello;

    packages.x86_64-darwin.default = self.packages.x86_64-darwin.hello;
    
    defaultPackage.x86_64-darwin = self.packages.x86_64-darwin.hello;
  };
}

When I do nix develop .#packages.x86_64-darwin.default I get a new error

error (ignored): error: flake 'github:NixOS/nixpkgs/d8f2c4d846a2e65ad3f5a5e842b672f0b81588a2' does not provide attribute 'legacyPackages.x86-64-darwin.bashInteractive' or 'bashInteractive'
       Did you mean x86_64-darwin?

but it does actually end up putting me into a new environment titled ‘bash-5.1’

I appear to have been mistaken on what nix shell is supposed to do, I guess it isn’t as much of a ‘separate shell environment’ as I’m used to because upon running ‘hello’ and ‘where hello’ it points me to the local nix store and appears to work well!

Nix develop still errors out, I’ve tried it on both this minimal repository and a meatier one (GitHub - srid/haskell-template: Haskell project template using Nix + Flakes + VSCode (HLS)) which has been confirmed to work on M1 macs (diff. architecture but still darwin) so I’m not 100% sure the lack of devShells output is the issue here.

Thank you so much for your help I appreciate you so much!!

I don’t use Darwin, so my suggestion might be incorrect, but maybe try:

$ nix repl
nix-repl> builtins.currentSystem
"x86_64-darwin"

The correct output should x86_64-darwin. If you get x86-64-darwin, it is likely there is some sort of error in your configuration or something somewhere?

Possibly check in /etc/nix/nix.conf. If you can’t figure it out, I’d suggest completely uninstalling Nix (including ever configuration file you can find), and reinstalling.

3 Likes

Thank you so much for your time and help I can finally go to sleep in peace :sweat_smile:

The issue was caused by exactly what you said - there was a line loaded by my darwin configuration where I mistakenly set nix.extraOptions.system to x86-64-darwin rather than x86_64-darwin.

Again, I really can’t express my gratitude enough and am excited to pay it forward as soon as I gain some experience with this beast of a tool!

3 Likes