@@ -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.
@@ -48,7 +49,7 @@ let
4849 # A user is required by nix
4950 # https://github.com/NixOS/nix/blob/9348f9291e5d9e4ba3c4347ea1b235640f54fd79/src/libutil/util.cc#L478
5051 export USER=nobody
51− ${nix}/bin/nix-store --load-db < ${closureInfo {rootPaths = contentsList;}}/registration
52+ ${buildPackages.nix}/bin/nix-store --load-db < ${closureInfo {rootPaths = contentsList;}}/registration
5253
5354 mkdir -p nix/var/nix/gcroots/docker/
5455 for i in ${lib.concatStringsSep " " contentsList}; do
@@ -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
@@ -443,7 +454,7 @@ rec {
443454 runCommand "${name}.tar.gz" {
444455 inherit (stream) imageName;
445456 passthru = { inherit (stream) imageTag; };
446− buildInputs = [ pigz ];
457+ nativeBuildInputs = [ pigz ];
447458 } "${stream} | pigz -nT > $out";
448459
449460 # 1. extract the base image
@@ -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
@@ -762,7 +773,7 @@ rec {
762773 else
763774 lib.head (lib.strings.splitString "-" (baseNameOf conf.outPath));
764775 paths = referencesByPopularity overallClosure;
765− buildInputs = [ jq ];
776+ nativeBuildInputs = [ jq ];
766777 } ''
767778 ${if (tag == null) then ''
768779 outName="$(basename "$out")"
@@ -826,7 +837,7 @@ rec {
826837 # take images can know in advance how the image is supposed to be used.
827838 isExe = true;
828839 };
829− buildInputs = [ makeWrapper ];
840+ nativeBuildInputs = [ makeWrapper ];
830841 } ''
831842 makeWrapper ${streamScript} $out --add-flags ${conf}
832843 '';