I’ve used regular old non-flake Nix in the past to “cross-compile” docker images. My local machine is macOS M1, and I can either override system (ie. import <nixpkgs> { system = "x86_64-linux"; }; or set architecture when building the docker image.
But with flakes, how would I define a flake that builds a docker image that runs on linux?
Do I use packages.x86_64-linux.containerImage = dockerTools.buildLayeredImage … because I want it to run on linux, or do I use packages.aarch64-darwin.containerImage = … because I’m building on a mac M1?
I have a remote builder available for linux x86_64…
I figured that out today. If you build locally, you “use packages.aarch64-darwin.containerImage = … because I’myou 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: