about summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-11-07T17·19+0000
committerVincent Ambo <github@tazj.in>2019-11-09T15·35+0000
commit145b7f4289cd6c54bbbe5d1345c8d034e6f16be7 (patch)
treeb6d1a7ce793978a3a7c7f5857d44653286a71d4a /tools
parentd7ccf351494873b7e45ba450019c5462ef860aeb (diff)
fix(build-image): Allow "cross-builds" of images for different arch
Imports the package set twice in the builder expression: Once
configured for the target system, once configured for the native
system.

This makes it possible to fetch the actual image contents for the
required architecture, but use local tools to assemble the symlink
layer and metadata.
Diffstat (limited to 'tools')
-rw-r--r--tools/nixery/build-image/build-image.nix13
1 files changed, 9 insertions, 4 deletions
diff --git a/tools/nixery/build-image/build-image.nix b/tools/nixery/build-image/build-image.nix
index eb14d52424bc..4393f2b859a6 100644
--- a/tools/nixery/build-image/build-image.nix
+++ b/tools/nixery/build-image/build-image.nix
@@ -45,8 +45,13 @@ let
     toFile
     toJSON;
 
-  inherit (pkgs) lib runCommand writeText;
+  # Package set to use for sourcing utilities
+  nativePkgs = import loadPkgs { inherit srcType srcArgs importArgs; };
+  inherit (nativePkgs) coreutils jq openssl lib runCommand writeText symlinkJoin;
 
+  # Package set to use for packages to be included in the image. This
+  # package set is imported with the system set to the target
+  # architecture.
   pkgs = import loadPkgs {
     inherit srcType srcArgs;
     importArgs = importArgs // {
@@ -115,7 +120,7 @@ let
   runtimeGraph = runCommand "runtime-graph.json" {
     __structuredAttrs = true;
     exportReferencesGraph.graph = allContents.contents;
-    PATH = "${pkgs.coreutils}/bin";
+    PATH = "${coreutils}/bin";
     builder = toFile "builder" ''
       . .attrs.sh
       cp .attrs.json ''${outputs[out]}
@@ -124,7 +129,7 @@ let
 
   # Create a symlink forest into all top-level store paths of the
   # image contents.
-  contentsEnv = pkgs.symlinkJoin {
+  contentsEnv = symlinkJoin {
     name = "bulk-layers";
     paths = allContents.contents;
   };
@@ -141,7 +146,7 @@ let
   # Two different hashes are computed for different usages (inclusion
   # in manifest vs. content-checking in the layer cache).
   symlinkLayerMeta = fromJSON (readFile (runCommand "symlink-layer-meta.json" {
-    buildInputs = with pkgs; [ coreutils jq openssl ];
+    buildInputs = [ coreutils jq openssl ];
   }''
     tarHash=$(sha256sum ${symlinkLayer} | cut -d ' ' -f1)
     layerSize=$(stat --printf '%s' ${symlinkLayer})