summary refs log tree commit diff
path: root/pkgs/build-support/docker
diff options
context:
space:
mode:
authoradisbladis <adisbladis@gmail.com>2020-11-19 15:03:44 +0100
committeradisbladis <adisbladis@gmail.com>2020-11-19 18:13:21 +0100
commit8a3b33baed9458a0af56a710b535bedf6d6c2598 (patch)
tree311d07a54e4146501daf96d45498308874f85380 /pkgs/build-support/docker
parent4313ac6b292708158cb413420c8848f7b8012305 (diff)
downloadnixpkgs-8a3b33baed9458a0af56a710b535bedf6d6c2598.tar
nixpkgs-8a3b33baed9458a0af56a710b535bedf6d6c2598.tar.gz
nixpkgs-8a3b33baed9458a0af56a710b535bedf6d6c2598.tar.bz2
nixpkgs-8a3b33baed9458a0af56a710b535bedf6d6c2598.tar.lz
nixpkgs-8a3b33baed9458a0af56a710b535bedf6d6c2598.tar.xz
nixpkgs-8a3b33baed9458a0af56a710b535bedf6d6c2598.tar.zst
nixpkgs-8a3b33baed9458a0af56a710b535bedf6d6c2598.zip
dockerTools: Set correct architecture when cross compiling
Diffstat (limited to 'pkgs/build-support/docker')
-rw-r--r--pkgs/build-support/docker/default.nix17
1 files changed, 14 insertions, 3 deletions
diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix
index b072c291f77..e4e8f794bc4 100644
--- a/pkgs/build-support/docker/default.nix
+++ b/pkgs/build-support/docker/default.nix
@@ -31,6 +31,7 @@
   writeScript,
   writeText,
   writePython3,
+  system,  # Note: This is the cross system we're compiling for
 }:
 
 # WARNING: this API is unstable and may be subject to backwards-incompatible changes in the future.
@@ -56,6 +57,16 @@ let
     done;
   '';
 
+  # Map nixpkgs architecture to Docker notation
+  # Reference: https://github.com/docker-library/official-images#architectures-other-than-amd64
+  getArch = nixSystem: {
+    aarch64-linux = "arm64v8";
+    armv7l-linux = "arm32v7";
+    x86_64-linux = "amd64";
+    powerpc64le-linux = "ppc64le";
+    i686-linux = "i386";
+  }.${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.";
+
 in
 rec {
 
@@ -72,7 +83,7 @@ rec {
     , imageDigest
     , sha256
     , os ? "linux"
-    , arch ? buildPackages.go.GOARCH
+    , arch ? getArch system
 
       # This is used to set name to the pulled image
     , finalImageName ? imageName
@@ -488,7 +499,7 @@ rec {
       baseJson = let
           pure = writeText "${baseName}-config.json" (builtins.toJSON {
             inherit created config;
-            architecture = buildPackages.go.GOARCH;
+            architecture = getArch system;
             os = "linux";
           });
           impure = runCommand "${baseName}-config.json"
@@ -715,7 +726,7 @@ rec {
       streamScript = writePython3 "stream" {} ./stream_layered_image.py;
       baseJson = writeText "${name}-base.json" (builtins.toJSON {
          inherit config;
-         architecture = buildPackages.go.GOARCH;
+         architecture = getArch system;
          os = "linux";
       });