git.iko.soy/typeable/nixpkgs
on master help sign in
dockerTools: Set correct architecture when cross compiling
commit8a3b33baed9458a0af56a710b535bedf6d6c2598 authoradisbladis <adisbladis@gmail.com> dateThu 19 Nov 2020, 15:03 (6 years ago) parent4313ac6
1 file changed+14−3
pkgs/build-support/docker/default.nix+14−3
pkgs/build-support/docker/default.nix+14−3
@@ -31,6 +31,7 @@
3131 writeScript,
3232 writeText,
3333 writePython3,
34+ system, # Note: This is the cross system we're compiling for
3435}:
3536
3637# WARNING: this API is unstable and may be subject to backwards-incompatible changes in the future.
@@ -56,6 +57,16 @@ let
5657 done;
5758 '';
5859
60+ # Map nixpkgs architecture to Docker notation
61+ # Reference: https://github.com/docker-library/official-images#architectures-other-than-amd64
62+ getArch = nixSystem: {
63+ aarch64-linux = "arm64v8";
64+ armv7l-linux = "arm32v7";
65+ x86_64-linux = "amd64";
66+ powerpc64le-linux = "ppc64le";
67+ i686-linux = "i386";
68+ }.${nixSystem} or "Can't map Nix system ${nixSystem} to Docker architecture notation. Please check that your input and your requested build are correct or update the mapping in Nixpkgs.";
69+
5970in
6071rec {
6172
@@ -72,7 +83,7 @@ rec {
7283 , imageDigest
7384 , sha256
7485 , os ? "linux"
75− , arch ? buildPackages.go.GOARCH
86+ , arch ? getArch system
7687
7788 # This is used to set name to the pulled image
7889 , finalImageName ? imageName
@@ -488,7 +499,7 @@ rec {
488499 baseJson = let
489500 pure = writeText "${baseName}-config.json" (builtins.toJSON {
490501 inherit created config;
491− architecture = buildPackages.go.GOARCH;
502+ architecture = getArch system;
492503 os = "linux";
493504 });
494505 impure = runCommand "${baseName}-config.json"
@@ -715,7 +726,7 @@ rec {
715726 streamScript = writePython3 "stream" {} ./stream_layered_image.py;
716727 baseJson = writeText "${name}-base.json" (builtins.toJSON {
717728 inherit config;
718− architecture = buildPackages.go.GOARCH;
729+ architecture = getArch system;
719730 os = "linux";
720731 });
721732