nix2container
nix2container copied to clipboard
Example defaults to amd64 architecture
Running the example in the README:
> nix run github:nlewo/nix2container#examples.bash.copyToDockerDaemon
> docker run -it bash:2bq5nc0g665z2ixfv1lzypxki5cqjf42
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
standard_init_linux.go:228: exec user process caused: exec format error
This is running on a Macbook M1 Pro. I've tried parsing through some of the logic and I'm not familiar enough with the backend to understand why it's defaulting to this architecture. Any ideas?
Currently, nix2container.buildImage doesn't expose an attribute to specify the architecture.
To support this feature, we would need to do two things:
- expose an attribute in nix2container functions. The architecture would be then written in the produced image JSON file. This should be quite easy to implemented
- use this attribute in the Nix Skopeo transport: i don't know (yet) how to specify it but this should not be a big deal.
Regarding the default architecture value, i think it's Skopeo that decides it (but i don't know how).
I think it would be nice to support different architectures but i only have a x86-linux machine, so i won't be able to test this feature (expecting via the CI but that's time consuming...).
This issue shouldn't be closed. I'm still getting the wrong architecture being generated on the M1 platform.
❯ docker run -it bash:2bq5nc0g665z2ixfv1lzypxki5cqjf42
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
standard_init_linux.go:228: exec user process caused: exec format error
I apologize for my oversight, the issue is fixed, I just didn't account for the fact that the image being built was targeting darwin.
@jmgilman No problem. I always like to see an issue being closed ;)
I'm building a docker image from an and Linux machine and a M1 user is having the error that @jmgilman posted. Is there an option to build to both architectures? does this need to be build on a M1 CI?
If Nix is running on an M1, it's going to attempt to build the binaries for the native M1 architecture/OS. If you then copy this to the Docker daemon running on an M1, you'll run into a host of exec errors because it's expecting a completely different format (ELF, to be exact). You need to run Nix in an ARM Linux machine to get the correct results.
You need to run Nix in an ARM Linux machine to get the correct results.
I'm recognizing some GH handles here and presuming some more context I have, I can also suggest to try std|paisano --for x86_64-linux ... It was precisely made to build a x86_64-linux image more ergonomically on another machine. Due to lack of an M1 in my hands, it hasn't been thoroughly tested, but it was designed to locally (e.g. on a M1) use native toolchain to execute all actions (such as copyToDockerDaemon) while at the same time still building an x86_64-linux image.