Home-manager flake not respecting --build-host during nixos-rebuild

I’m new to NixOS and have been experimenting with flakes recently. I use nixos-rebuild switch --target-host root@arm64 --build-host root@arm64 --flake '.#arm64' on x86_64-darwin to remotely rebuild an aarch64-linux host with the following flake.nix:

{
  outputs = { self, nixpkgs  }: {
    nixosConfigurations.arm64 = nixpkgs.lib.nixosSystem {
      system = "aarch64-linux";
      modules = [
        ./hosts/arm64/configuration.nix
      ];
    };
  };
}

This works well. I tried adding home-manager to the flake as follows:

{
  inputs = {
    home-manager.url = "github:nix-community/home-manager";
  };

  outputs = { self, nixpkgs, home-manager }: {
    nixosConfigurations.arm64 = nixpkgs.lib.nixosSystem {
      system = "aarch64-linux";
      modules = [
        ./hosts/arm64/configuration.nix
        home-manager.nixosModules.home-manager
        {
          home-manager.useGlobalPkgs = true;
          home-manager.useUserPackages = true;
          home-manager.users.alex = import ./home;
        }
      ];
    };
  };
}

However, nixos-rebuild fails with the following error once I add programs to my home-manager configuration:

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

Is there something wrong with my flake configuration?

2 Likes

Did you ever solve this problem? I’m having the exact same issue, but I didn’t realize home-manager was the culprit.