I figured that out today. If you build locally, you “use packages.aarch64-darwin.containerImage = … because I’m you are building on a mac M1” with import <nixpkgs> { localSystem = "aarch64-darwin", crossSystem = "x86_64-linux"; };.
Here an example (without fanciness), ./docker.nix would contain the dockerTools.buildLayeredImage derivation:
{
outputs = { self, nixpkgs }: {
# Regular build
# packages.${localsystem}.${name} = drv { import pkgs = nixpkgs.legacypackages.${localsystem}; }
packages.aarch64-darwin.containerImage = import ./docker.nix { pkgs = nixpkgs.legacyPackages.aarch64-darwin; };
# Cross build
# packages.${localSystem}."${name}-${crossSystem}" = drv { import nixpkgs { localSystem = localSystem; crossSystem = crossSystem;}
packages.aarch64-darwin.containerImage-x86_64-linux = import ./docker.nix { pkgs = import nixpkgs { localSystem = "aarch64-darwin"; crossSystem = "x86_64-linux"; }; };
};
}
For fancy generation, there is this post: How do I cross-compile a flake? - #22 by reckenrode and GitHub - numtide/flake-utils: Pure Nix flake utility functions [maintainer=@zimbatm]
Those are the conventions I have observed. For example: https://github.com/NixOS/nix/blob/435a16b5556f4171b4204a3f65c9dedf215f168c/flake.nix#L422-L423