LnL7 / nix-darwin

nix modules for darwin
MIT License
3.26k stars 462 forks source link

switch to a flake on a apple silicon m2 MacBookPro , complains about itself is a "x86_64" machine #843

Closed hitsmaxft closed 11 months ago

hitsmaxft commented 11 months ago

run switch commmand on my flake.nix

nix run nix-darwin -- switch --flake .  -vvv

it's show error logs and exits

error: a 'aarch64-darwin' with features {} is required to build '/nix/store/x566x7pwkgs57dn7yq8h9q98ykycmf6n-darwin-version.json.drv', but I am a 'x86_64-darwin' with features {benchmark, big-parallel, nixos-test}

here is my configuration

{
  description = "Example Darwin system flake";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nix-darwin.url = "github:LnL7/nix-darwin/master";
    nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
    home-manager.url = "github:nix-community/home-manager/master";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = inputs@{ self, nix-darwin, nixpkgs, home-manager,... }:
  let

    brewPrefix = "/opt/homebrew";

    configuration = { pkgs, arch, modulesPath, ... }: {

      system.stateVersion = 4;
      system.configurationRevision = self.rev or self.dirtyRev or null;

      imports = [
        (modulesPath + "/programs/zsh")
        (modulesPath + "/nix/nix-darwin.nix")
      ];

      nix = {
        useDaemon = true; 

        registry.nixpkgs.to = { type = "path"; path = "${pkgs.path}"; };
        settings.experimental-features = "nix-command flakes";
        package = pkgs.nix;
        envVars = {
          HTTP_PROXY = "http://127.0.0.1:7890";
          HTTPS_PROXY = "http://127.0.0.1:7890";
          ALL_PROXY = "socks5://127.0.0.1:7890";
        };
      };
      # Necessary for using flakes on this system.

      environment = {
        profiles = ["${brewPrefix}"];

        shells = with pkgs; [ zsh ];

        extraInit = ''
        # environment.extraInit
          if [[ "$(uname)" == "Darwin" ]] ; then
          export JAVA_HOME=$(/usr/libexec/java_home)
          fi
        ''; # see /etc/static/bashrc

        systemPackages = with pkgs; [
          niv
          home-manager
          yadm
          vim
          git
          nix-tree
          htop
          parallel
          binutils
          nixfmt
        ];
        variables = {
          HOMEBREW_PREFIX = brewPrefix;
          HOMEBREW_CELLAR = "${brewPrefix}/Cellar";
          HOMEBREW_REPOSITORY = brewPrefix;
          INFOPATH = "${brewPrefix}/share/info:\${INFOPATH:-}";
          MANPATH = "${brewPrefix}/share/man\${MANPATH+:$MANPATH}:";
        };
      };

      # The platform the configuration will be used on.
      nixpkgs.hostPlatform = arch ;
    };
  in
  {
    # Build darwin flake using:
    darwinConfigurations."xxx" = nix-darwin.lib.darwinSystem {
      modules = [ 
        configuration
      ];
      specialArgs = { arch = "aarch64-darwin"; };

    };

    # Expose the package set, including overlays, for convenience.
    darwinPackages = self.darwinConfigurations.xxx.pkgs;
  };
}

is there any mistakes in host configuration

Enzime commented 11 months ago

This means you've installed the x86_64 Nix, the easiest fix is probably to uninstall Nix:

https://github.com/DeterminateSystems/nix-installer#uninstalling

Otherwise, if /nix/nix-installer doesn't exist:

https://nixos.org/manual/nix/unstable/installation/uninstall.html#macos

Then reinstall it with:

https://github.com/DeterminateSystems/nix-installer#usage

I would download the aarch64-darwin binary manually instead of running the command to ensure the correct Nix gets installed

hitsmaxft commented 11 months ago

This means you've installed the x86_64 Nix, the easiest fix is probably to uninstall Nix:

https://github.com/DeterminateSystems/nix-installer#uninstalling

Otherwise, if /nix/nix-installer doesn't exist:

https://nixos.org/manual/nix/unstable/installation/uninstall.html#macos

Then reinstall it with:

https://github.com/DeterminateSystems/nix-installer#usage

I would download the aarch64-darwin binary manually instead of running the command to ensure the correct Nix gets installed

thank you , i found that while previous installing, install script run uname -m , but it outputs x86 and download the wrong installer leads to this problem.

hitsmaxft commented 11 months ago

@Enzime need help for home manager switch

it complain about system args

[nix-shell:~/.config/home-manager]$ home-manager switch
error:
       … while evaluating the attribute 'activationPackage'

         at /nix/store/kyxjq9677b5l77a46lixkwv43jrzr9w2-home-manager-source/modules/default.nix:54:3:

           53|
           54|   activationPackage = module.config.home.activationPackage;
             |   ^
           55|

       … while evaluating a branch condition

         at /nix/store/3bi1ssj310l4jj3i6abqgiafyc7fx0nd-nixpkgs/nixpkgs/lib/lists.nix:57:9:

           56|       fold' = n:
           57|         if n == len
             |         ^
           58|         then nul

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'currentSystem' missing

       at /nix/store/3bi1ssj310l4jj3i6abqgiafyc7fx0nd-nixpkgs/nixpkgs/lib/modules.nix:508:28:

          507|         builtins.addErrorContext (context name)
          508|           (args.${name} or config._module.args.${name})
             |                            ^
          509|       ) (lib.functionArgs f);
Enzime commented 11 months ago

I suggest using home-manager as a nix-darwin module, that way when you do a darwin-rebuild switch it'll also apply your home-manager config

https://nix-community.github.io/home-manager/index.xhtml#sec-flakes-nix-darwin-module

hitsmaxft commented 11 months ago

I suggest using home-manager as a nix-darwin module, that way when you do a darwin-rebuild switch it'll also apply your home-manager config

https://nix-community.github.io/home-manager/index.xhtml#sec-flakes-nix-darwin-module

I've rollbacked to classic nix-darwin installation for saving time. thank you for your advice, i wll try it on other macbooks.