Using nixos-rebuild on aarch64 to deploy to x86_64 system

I have an aarch64 laptop and I want to run nixos-rebuild on that host and build for and deploy to a x86_64-linux machine. So I have spent some time researching and reading up on how to do this.

However I must be missing something because I get an error complaining that “i686 Linux package set can only be used with the x86 family”

I have added the below config to my host system config

boot.binfmt.emulatedSystems = [ "x86_64-linux" ];
nix.settings.extra-platforms = config.boot.binfmt.emulatedSystems;

The flake for my remote x86_64 machine is

{
  description = "NixOS configuration";
  inputs = {
    nixpkgs = {
      url = "github:NixOS/nixpkgs/nixos-24.05";
    };
    sops-nix = {
      url = "github:Mic92/sops-nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };

  };
  outputs = { nixpkgs, sops-nix, ... }: {
    nixosConfigurations = {
      # Native build on the machine
      Test = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          sops-nix.nixosModules.sops

          # import config
          ./configuration.nix
        ];
      };
      # Build on aarch64 for x86_64
      Test-from-aarch64 = nixpkgs.lib.nixosSystem {
        modules = [
          sops-nix.nixosModules.sops

          # import config
          ./configuration.nix
          {
            # this is the achitecture we build from
            nixpkgs.buildPlatform = "aarch64-linux";
            # this is the architecture of the target system
            nixpkgs.hostPlatform = "x86_64-linux";

          }
        ];
      };
    };
  };
}

When I run the nixos-rebuild command

nixos-rebuild switch --fast --flake .#Test-from-aarch64 --build-host localhost --target-host target-machine --option eval-cache false

I get

error:
       … while calling the 'head' builtin

         at /nix/store/2lvj8bm21ymxra61dqrc4xpzr8njgywj-source/lib/attrsets.nix:1575:11:

         1574|         || pred here (elemAt values 1) (head values) then
         1575|           head values
             |           ^
         1576|         else

       … while evaluating the attribute 'value'

         at /nix/store/2lvj8bm21ymxra61dqrc4xpzr8njgywj-source/lib/modules.nix:809:9:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

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

       error: i686 Linux package set can only be used with the x86 family.

What do you think I am missing here?

1 Like